diff --git a/.eslintignore b/.eslintignore
deleted file mode 100644
index 35e915e52..000000000
--- a/.eslintignore
+++ /dev/null
@@ -1,3 +0,0 @@
-**/node_modules/*
-**/out/*
-**/.next/*
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 000000000..80e3f6d0b
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,15 @@
+module.exports = {
+ root: true,
+ parser: '@typescript-eslint/parser',
+ plugins: ['@typescript-eslint'],
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
+ overrides: [
+ {
+ // enable the rule specifically for TypeScript files
+ files: ['*.ts', '*.tsx'],
+ rules: {
+ '@typescript-eslint/explicit-module-boundary-types': [0],
+ },
+ },
+ ],
+}
diff --git a/.eslintrc.json b/.eslintrc.json
deleted file mode 100644
index 2b7fe86e0..000000000
--- a/.eslintrc.json
+++ /dev/null
@@ -1,49 +0,0 @@
-{
- "parser": "@typescript-eslint/parser",
- "plugins": ["@typescript-eslint"],
- "extends": [
- "eslint:recommended",
- "plugin:react/recommended",
- "plugin:@typescript-eslint/recommended"
- // Uncomment the following lines to enable eslint-config-prettier
- // Is not enabled right now to avoid issues with the Next.js repo
- // "prettier",
- ],
- "env": {
- "es6": true,
- "browser": true,
- "jest": true,
- "node": true
- },
- "settings": {
- "react": {
- "version": "detect"
- }
- },
- "ignorePatterns": "**/*.js",
- "rules": {
- "react/react-in-jsx-scope": 0,
- "react/display-name": 0,
- "react/prop-types": 0,
- "@typescript-eslint/no-extra-semi": 0,
- "@typescript-eslint/explicit-function-return-type": 0,
- "@typescript-eslint/explicit-member-accessibility": 0,
- "@typescript-eslint/indent": 0,
- "@typescript-eslint/member-delimiter-style": 0,
- "@typescript-eslint/no-explicit-any": 0,
- "@typescript-eslint/no-var-requires": 0,
- "@typescript-eslint/no-use-before-define": 0,
- "@typescript-eslint/no-unused-vars": [
- 2,
- {
- "argsIgnorePattern": "^_"
- }
- ],
- "no-console": [
- 2,
- {
- "allow": ["warn", "error"]
- }
- ]
- }
-}
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index dfe077042..000000000
--- a/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2af738278..e6a409954 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -5,9 +5,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
+ # install modules
- name: Install modules
run: yarn
- # unit tests
+ # build
+ - name: Build
+ run: yarn build:packages
+ # run unit tests
- name: Jest Annotations & Coverage
uses: mattallty/jest-github-action@v1.0.3
env:
diff --git a/.gitignore b/.gitignore
index f39130ca3..6b81fa8e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,37 +1,10 @@
-# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+node_modules/
+build/
+lib/
+dist/
+docs/
+.idea/*
-# dependencies
-/dist
-/node_modules
-/.pnp
-.pnp.js
-
-# testing
-/coverage
-
-# next.js
-/.next/
-/out/
-
-# production
-/build
-
-# misc
.DS_Store
-*.pem
-
-# debug
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-
-# local env files
-.env.local
-.env.development.local
-.env.test.local
-.env.production.local
-
-# vercel
-.vercel
-
-cypress/integration/examples
+coverage
+*.log
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 000000000..2da193068
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,17 @@
+/.github/
+/.vscode/
+/node_modules/
+/build/
+/tmp/
+.idea/*
+/docs/
+
+coverage
+*.log
+.gitlab-ci.yml
+
+package-lock.json
+/*.tgz
+/tmp*
+/mnt/
+/package/
diff --git a/.prettierrc b/.prettierrc
deleted file mode 100644
index e1076edfa..000000000
--- a/.prettierrc
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "semi": false,
- "singleQuote": true,
- "tabWidth": 2,
- "useTabs": false
-}
diff --git a/.vscode/snippets.code-snippets b/.vscode/snippets.code-snippets
index 047864012..1effdca66 100644
--- a/.vscode/snippets.code-snippets
+++ b/.vscode/snippets.code-snippets
@@ -1,7 +1,7 @@
{
"createComment": {
"scope": "typescript,typescriptreact",
- "prefix": "/**",
+ "prefix": "ccc",
"body": [
"/**",
" * ${1:description}",
@@ -10,8 +10,7 @@
" *",
" *```ts",
" * ${2:example}",
- " *```",
- " */"
+ " *```"
],
"description": "comment"
}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 000000000..d92be8b96
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,18 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "tsc",
+ "type": "shell",
+ "command": "./node_modules/.bin/tsc",
+ "args": ["--noEmit"],
+ "presentation": {
+ "reveal": "never",
+ "echo": false,
+ "focus": false,
+ "panel": "dedicated"
+ },
+ "problemMatcher": "$tsc-watch"
+ }
+ ]
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..57d6b4ac9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2021 Chris Hager
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 72023fe76..e44d26593 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,19 @@ To support this project (and gain access to the project while it is in developme
## Documentation
-...
+In progress! Check the README files in [packages/core](packages/core/README.md) and [packages/tldraw](packages/tldraw/README.md).
+
+## Examples
+
+- [@tldraw/core example](https://codesandbox.io/s/tldraw-core-example-88c74)
+- [@tldraw/tldraw example](https://codesandbox.io/s/tldraw-example-n539u)
## Local Development
+### The tldraw packages
+
+To work on the packages (@tldraw/core or @tldraw/tldraw), you'll want to run the (extremely fast) dev server.
+
1. Download or clone the repository.
```bash
@@ -34,357 +43,19 @@ To support this project (and gain access to the project while it is in developme
3. Start the development server.
```bash
- yarn dev
+ yarn start
```
-4. Open the local site at `https://localhost:3000`.
+4. Open the local site at `https://localhost:5000`.
-This project is a [Next.js](https://nextjs.org/) project. If you've worked with Next.js before, the tldraw code-base and setup instructions should all be very familiar.
+### The tldraw app
-## How it works
+To work on the app itself (that embeds @tldraw/tldraw), run the Next.js app. This won't directly respond to changes to packages, so for concurrent package dev work be sure to use the package dev server instead. (This is being worked on.)
-The app's state is a very large state machine located in `state/state.ts`. The machine is organized as a tree of state notes, such as `selecting` and `pinching`.
+1. Start the development server.
-```
-root
-├── loading
-└── ready
- ├── selecting
- │ ├── notPointing
- │ ├── pointingBounds
- │ ├── translatingSelection
- │ └── ...
- ├── usingTool
- ├── pinching
- └── ...
-```
+ ```bash
+ yarn start:www
+ ```
-### State Nodes
-
-Nodes may be active or inactive. The root node is always active. Depending on what's happened in the app, different branches of the state tree may be active, while other branches may be inactive.
-
-```ts
-pinching: {
- onExit: { secretlyDo: 'updateZoomCSS' },
- initial: 'selectPinching',
- states: {
- selectPinching: {
- on: {
- STOPPED_PINCHING: { to: 'selecting' },
- },
- },
- toolPinching: {
- on: {
- STOPPED_PINCHING: { to: 'usingTool.previous' },
- },
- },
- },
-},
-```
-
-State nodes are both a way to describe the state (e.g., "the pinching state is active") and a way of organizing events. Each node has a set of events (`on`). When the state receives an event, it will execute the event handlers on each of the machine's _active_ states where the event is present.
-
-### Event Handlers
-
-Event handlers contain references to event handler functions: `actions`, `conditions`, `results`, and `async`s. These are defined at the bottom of the state machine's configuration.
-
-An event handler may be a single action:
-
-```ts
-on: {
- MOVED_POINTER: 'updateRotateSession',
-}
-```
-
-Or it may be an array of actions:
-
-```ts
-on: {
- MOVED_TO_PAGE: ['moveSelectionToPage', 'zoomCameraToSelectionActual'],
-}
-```
-
-Or it may be an object with conditions under `if` or `unless` and actions under `do`:
-
-```ts
-on: {
- SAVED_CODE: {
- unless: 'isReadOnly',
- do: 'saveCode',
- }
-}
-```
-
-An event handler may also contain transitions under `to`:
-
-```ts
-on: {
- STOPPED_PINCHING: { to: 'selecting' },
-},
-```
-
-As well as nested event handlers under control flow, `then` and `else`.
-
-```ts
-on: {
- STOPPED_POINTING: {
- if: 'isPressingShiftKey',
- then: {
- if: 'isPointedShapeSelected',
- do: 'pullPointedIdFromSelectedIds',
- },
- else: {
- if: 'isPointingShape',
- do: [
- 'clearSelectedIds',
- 'setPointedId',
- 'pushPointedIdToSelectedIds',
- ],
- },
- },
-}
-```
-
-And finally, an event handler may have arrays of event handler objects.
-
-```ts
-on: {
- STOPPED_POINTING: [
- 'completeSession',
- {
- if: 'isToolLocked',
- to: 'dot.creating',
- else: {
- to: 'selecting'
- },
- },
- ],
-}
-```
-
-### Event Handler Functions
-
-The configuration's event handlers work by calling event handler functions. While each event handler function does a different job, all event handler functions receive the _same_ three parameters:
-
-1. The machine's current `data` draft
-2. The payload sent by the event that has caused the function to run
-3. The most recent result returned by a `result` function
-
-> Note: The `payload` and `result` parameters must be typed manually inline.
-
-```ts
-eventHandlerFn(data, payload: { id: string }, result: Shape) {}
-```
-
-Results may return any value.
-
-```ts
-pageById(data, payload: { id: string }) {
- return data.document.pages[payload.id]
-}
-```
-
-Conditions must return `true` or `false`.
-
-```ts
-pageIsCurrentPage(data, payload, result: Page) {
- return data.currentPageId === result.id
-}
-```
-
-Actions may mutate the `data` draft.
-
-```ts
-setCurrentPageId(data, payload, result: Page) {
- data.currentPageId = result.id
-}
-```
-
-In a state's event handlers, event handler functions are referred to by name.
-
-```ts
-on: {
- SOME_EVENT: {
- get: "pageById"
- unless: "pageIsCurrentPage",
- do: "setCurrentPageId"
- }
-}
-```
-
-Asyncs are asynchronous functions. They work like results, but resolve data instead.
-
-```ts
-async getCurrentUser(data) {
- return fetch(`https://tldraw/api/users/${data.currentUserId}`)
-}
-```
-
-These are used in asynchronous event handlers:
-
-```ts
-loadingUser: {
- async: {
- await: "getCurrentUser",
- onResolve: { to: "user" },
- onReject: { to: "error" },
- }
-}
-```
-
-### State Updates
-
-The state will update each time it:
-
-1. receives an event...
-2. that causes it to run an event handler...
-3. that passes its conditions...
-4. and that contains either an action or a transition
-
-Such updates are batched: while a single event may cause several event handlers to run, the state will update only once provided that at least one of the event handlers caused an action or transition to occur.
-
-When a state updates, it will cause any subscribed components to update via hooks.
-
-### Subscribing to State
-
-To use the state's data reactively, we use the `useSelector` hook.
-
-```tsx
-import state, { useSelector } from 'state'
-
-function SomeComponent() {
- const pointingId = useSelector((s) => s.data.pointingId)
-
- return
The pointing id is {pointingId}
-}
-```
-
-Each time the state updates, the hook will check whether the data returned by the selector function matches its previous data. If the answer is false (ie if the data is new) the hook will update and the new data will become its previous data.
-
-The hook may also accept a second parameter, a comparison function. If the selector function returns anything other than a primitive, we will often use a comparison function to correctly find changes.
-
-```tsx
-import state, { useSelector } from 'state'
-import { deepCompareArrays } from 'utils'
-
-function SomeComponent() {
- const selectedIds = useSelector(
- (s) => tld.getSelectedShapes(s.data).map((shape) => shape.id),
- deepCompareArrays
- )
-
- return The selected ids are {selectedIds.toString()}
-}
-```
-
-### Events
-
-Events are sent from the user interface to the state.
-
-```ts
-import state from 'state'
-
-state.send('SELECTED_DRAW_TOOL')
-```
-
-Events may also include payloads of data.
-
-```ts
-state.send('ALIGNED', { type: AlignType.Right })
-```
-
-The payload will become the second parameter of any event handler function that runs as a result of the event.
-
-Note that with very few exceptions, we send events to the state regardless of whether the state can handle the event. Whether the event should have an effect—and what that effect should be—these questions are left entirely to the state machine.
-
-> Note: You can send an event to the state from anywhere in the app: even from components that are not subscribed to the state. See the components/style-panel files for examples.
-
-### Commands and History
-
-The app uses a command pattern to keep track of what has happened in the app, and to support an undo and redo stack. Each command includes a `do` method and an `undo` method. When the command is created, it will run its `do` method. If it is "undone", it will run its `undo` method. If the command is "redone", it will run its `do` method again.
-
-```ts
-export default function nudgeCommand(data: Data, delta: number[]): void {
- const initialShapes = tld.getSelectedShapeSnapshot(data, () => null)
-
- history.execute(
- data,
- new Command({
- name: 'nudge_shapes',
- category: 'canvas',
- do(data) {
- tld.mutateShapes(
- data,
- initialShapes.map((shape) => shape.id),
- (shape, utils) => {
- utils.setProperty(shape, 'point', vec.add(shape.point, delta))
- }
- )
- },
- undo(data) {
- tld.mutateShapes(
- data,
- initialShapes.map((shape) => shape.id),
- (shape, utils) => {
- utils.setProperty(shape, 'point', vec.sub(shape.point, delta))
- }
- )
- },
- })
- )
-}
-```
-
-Undos are not done programatically. It's the responsibility of a command to ensure that any mutations made in its `do` method are correctly reversed in its `undo` method.
-
-> Note: All mutations to a shape must be done through a shape's utils (the structure returned by `getShapeUtils`). Currently, many commands do this directly: however we're currently working on a more robust API for this, with built-in support for side effects, such as shown with `mutateShapes` above.
-
-### Sessions
-
-Not every change to the app's state needs to be put into the undo / redo stack. Sessions are a way of managing the data associated with certain states that lie _between_ commands, such as when a user is dragging a shape to a new position.
-
-Sessions are managed by the SessionManager (`state/session`). It guarantees that only one session is active at a time and allows other parts of the app's state to access information about the current session.
-
-A session's life cycle is accessed via four methods, `begin`, `update`, `cancel` and `complete`. Different sessions will implement these methods in different ways.
-
-A session begins when constructed.
-
-```ts
-session.begin(
- new Sessions.TranslateSession(
- data,
- tld.screenToWorld(inputs.pointer.origin, data)
- )
-)
-```
-
-Next, the session receives updates. Note that we're passing in the `data` draft from an action. The session will make any necessary changes to the draft.
-
-```ts
-session.update(
- data,
- tld.screenToWorld(payload.point, data),
- payload.shiftKey,
- payload.altKey
-)
-```
-
-> Note: To get proper typing in `session.update`, you must provide the generic type of the session you're updating.
-
-When a session completes, the session calls a method. This way, a user is able to travel back through the undo stack, visit only discrete commands (like deleting a shape) and those commands that marked the end of a session.
-
-```ts
-session.complete(data)
-```
-
-A session may also be cancelled.
-
-```ts
-session.cancel(data)
-```
-
-When cancelled, it is the responsibility of the session to restore the state to exactly how it was when the session began, reversing any changes that were made to the state during the session.
-
-For this reason, many sessions begin by taking a snapshot of the current draft.
-
-> Because the draft is a JavaScript Proxy, you must deep clone any parts of the draft that you want to include in a snapshot. (Direct references will fail as the underlying Proxy will have expired.) While the memory size of a snapshot is not usually a concern, this deep-cloning process is thread-blocking, so try to snapshot only the parts of the `data` draft that you need.
+2. Open the local site at `https://localhost:3000`.
diff --git a/__tests__/README.md b/__tests__/README.md
deleted file mode 100644
index ca00db08d..000000000
--- a/__tests__/README.md
+++ /dev/null
@@ -1,239 +0,0 @@
-# Testing Guide
-
-Writing tests for tldraw? Thank you! This guide will get you started.
-
-- [Getting Started](#getting-started)
-- [How to Test](#how-to-test)
-- [What to Test](#what-to-test)
-- [I Found a Bug!](#i-found-a-bug)
-- [TestUtils](#test-utils)
-- [Conclusion and Tips](#conclusion-and-tips)
-
-## Getting Started
-
-This project uses Jest for its unit tests.
-
-- To run the test suite, run `yarn test` in your terminal.
-- To start the test watcher, run `yarn test:watch`.
-- To update the test snapshots, run `yarn test:update`.
-
-Tests live inside of the `__tests__` folder.
-
-To create a new test, create a file named `myTest.test.ts` inside of the `__tests__` folder.
-
-## How to Test
-
-In tldraw, we write our tests against application's _state_.
-
-Remember that in tldraw, user interactions send _events_ to the app's _state_, where they produce a change (or not) depending on the state's configuration and current status. To test a feature, we "manually" send those same events to the state machine and then check whether the events produced the change we expected.
-
-To test a feature, we'll need to:
-
-- learn how the features works in tldraw
-- identify the events involved
-- identify the outcome of the events
-- reproduce the events in our test
-- test the outcome
-
-### Example
-
-Let's say we want to test the "create a page" feature of the app.
-
-We'd start by creating a new file named `create-page.test.ts`. Here's some boilerplace to get us started.
-
-```ts
-// __tests__/create-page.test.ts
-
-import TestState from '../test-utils'
-const tt = new TestState()
-
-it('creates a new page', () => {})
-```
-
-In the code above, we import our `TestState` class, create a new instance for this test file, then have a unit test that will assert something about our app's behavior.
-
-In the app's UI, we can find a button labelled "create page".
-
-```tsx
-// page-panel.tsx
-
- state.send('CREATED_PAGE')} />
-```
-
-Because we're only testing the state machine, we don't have to worry about how the `DropdownMenuButton` component works, or whether `onSelect` is implemented correctly. Instead, our only concern is the call to `state.send`, where we "send" the `CREATED_PAGE` event to the app's central state machine.
-
-Back in our test, we can send that the `CREATED_PAGE` event ourselves and check whether it's produced the correct outcome.
-
-```ts
-// __tests__/create-page.test.ts
-
-import TestState from '../test-utils'
-const tt = new TestState()
-
-it('creates a new page', () => {
- const pageCountBefore = Object.keys(tt.state.data.document.pages).length
-
- tt.state.send('CREATED_PAGE')
-
- const pageCountAfter = Object.keys(tt.state.data.document.pages).length
-
- expect(pageCountAfter).toEqual(pageCountBefore + 1)
-})
-```
-
-If we run our tests (with `yarn test`) or if we're already in watch mode (`yarn test:watch`) then our tests should update. If it worked, hooray! Now try to make it fail and see what that looks like, too.
-
-## What to Test
-
-While a test like "create a page" is pretty self-explanatory, most features are at least a little complex.
-
-To _fully_ test a feature, we would need to:
-
-- test the entire outcome
-- testing every circumstance under which the outcome could be different
-
-Let's take another look at the `CREATED_PAGE` event.
-
-If we search for the event in the state machine itself, we can find where and how event is being handled.
-
-```ts
-// state/state.ts
-
-ready: {
- on: {
- // ...
- CREATED_PAGE: {
- unless: ['isReadOnly', 'isInSession'],
- do: 'createPage',
- }
- }
-}
-```
-
-Here's where we can see what exactly we need to test. The event can tell us a few things:
-
-- It should only run when the "ready" state is active
-- It never run when the app is in read only mode
-- It should never run when the app is in a session (like drawing or rotating)
-
-These are all things that we could test. For example:
-
-```ts
-// __tests__/create-page.test.ts
-
-import TestState from '../test-utils'
-const tt = new TestState()
-
-it('does not create a new page in read only mode', () => {
- tt.state.send('TOGGLED_READ_ONLY')
-
- expect(tt.state.data.isReadOnly).toBe(true)
-
- const pageCountBefore = Object.keys(tt.state.data.document.pages).length
-
- tt.state.send('CREATED_PAGE')
-
- const pageCountAfter = Object.keys(tt.state.data.document.pages).length
-
- expect(pageCountAfter).toEqual(pageCountBefore)
-})
-```
-
-> Note that we're using a different event, `TOGGLED_READ_ONLY`, in order to get the state into the correct condition to make our test. When using events like this, it's a good idea to assert that the state is how you expect it to be before you make your "real" test. Here that means testing that the state's `data.isReadOnly` boolean is `true` before we test the `CREATED_PAGE` event.
-
-We can also look at the `createPage` action.
-
-```ts
-// state/state.ts
-
-createPage(data) {
- commands.createPage(data, true)
-},
-```
-
-If we follow this call, we'll find the `createPage` command (`state/commands/create-page.ts`). This command is more complex, but it gives us more to test:
-
-- did we correctly iterate the numbers in the new page's name?
-- did we get the correct child index for the new page?
-- did we save the current page to local storage?
-- did we save the new page to local storage?
-- did we add the new page to the document?
-- did we add the new page state to the document?
-- did we go to the new page?
-- when we undo the command, will we remove the new page / page state?
-- when we redo the command, will we put the new page / page state back?
-
-To _fully_ test a feature, we'll need to write tests that cover all of these.
-
-### Todo Tests
-
-...but while full test coverage is a goal, it's not always within reach. If you're not able to test everything about a feature, it's a good idea to write "placeholders" for the tests that need to be written.
-
-```ts
-describe('when creating a new page...', () => {
- it('sets the correct child index for the new page', () => {
- // TODO
- })
-
- it('sets the correct name for the new page', () => {
- // TODO
- })
-
- it('saves the document to local storage', () => {
- // TODO
- })
-})
-```
-
-### Snapshots
-
-An even better way to improve coverage when dealing with complex tests is to write "snapshot" tests.
-
-```ts
-describe('when creating a new page...', () => {
- it('updates the document', () => {
- tt.state.send('CREATED_PAGE')
- expect(tt.state.data).toMatchSnapshot()
- })
-})
-```
-
-While snapshot tests don't assert specific things about a feature's implementation, they will at least help flag changes in other parts of the app that might break the feature. For example, if we accidentally made the app start in read only mode, then the snapshot outcome of `CREATED_PAGE` would be different—and the test would fail.
-
-## I Found a Bug!
-
-As you write your tests, chances are you'll find some part of the application that just doesn't work the way it should. If it's your own code, then go ahead and make your fix. If the bug is in code that someone else has written, and if the fix seems complicated, then consider reaching out to the author on [Discord](https://discord.gg/a3H98DGSXS) or on the Github issue for help.
-
-## TestUtils
-
-While you can test every feature in tldraw by sending events to the state, the `TestUtils` class is designed to make certain things easier. By convention, I'll refer to an instance of the `TestUtils` class as `tt`.
-
-```ts
-import TestState from '../test-utils'
-const tt = new TestState()
-```
-
-The `TestUtils` instance wraps an instance of the app's state machine (`tt.state`). It also exposes the state's data as `tt.data`, as well as the state's helper methods (`tt.send`, `tt.isIn`, etc.)
-
-- `tt.resetDocumentState` will clear the document and reset the app state.
-- `tt.createShape` will create a new shape on the page.
-- `tt.clickShape` will click a the indicated shape
-
-Check the `test-utils.ts` file for the rest of the API. Feel free to add your own methods if you have a reason for doing so.
-
-## Conclusion and Tips
-
-To wrap up, thanks again for writing tests for tldraw. Quality in creative software is extremely important: nothing's worse than losing work to a bug, but even lesser terrors—getting kicked out of creative flow by unexpected behavior, or having to accomodate an accidental quirk—can make an app unusable.
-
-To sum up what we've covered:
-
-- Do a bit of digging into a feature's events and their outcome(s)
-- Test the app's state machine (view `TestUtils`), not the React view
-- Use the `TestUtils` class for complex events like clicking and dragging
-- Write "todo" tests for the things you can't get to
-- Ask original authors if you find a complex bug
-- Ask for help on [Discord](https://discord.gg/a3H98DGSXS)
-
-Thanks!
-
--Steve (@steveruizok)
diff --git a/__tests__/__mocks__/data.json b/__tests__/__mocks__/data.json
deleted file mode 100644
index decf560c6..000000000
--- a/__tests__/__mocks__/data.json
+++ /dev/null
@@ -1,326 +0,0 @@
-{
- "isReadOnly": false,
- "settings": {
- "fontSize": 13,
- "isDarkMode": false,
- "isCodeOpen": false,
- "isDebugMode": false,
- "isDebugOpen": false,
- "isStyleOpen": false,
- "isToolLocked": false,
- "isPenLocked": false,
- "nudgeDistanceLarge": 10,
- "nudgeDistanceSmall": 1
- },
- "currentStyle": {
- "size": "Medium",
- "color": "Black",
- "dash": "Draw",
- "isFilled": false
- },
- "activeTool": "select",
- "editingId": null,
- "boundsRotation": 0,
- "currentPageId": "page1",
- "currentParentId": "page1",
- "currentCodeFileId": "file0",
- "codeControls": {},
- "document": {
- "id": "TESTING",
- "name": "My Document",
- "pages": {
- "page1": {
- "id": "page1",
- "type": "page",
- "name": "Page 1",
- "childIndex": 0,
- "shapes": {
- "e43559cb-6f41-4ae4-9c49-158ed1ad2f72": {
- "id": "e43559cb-6f41-4ae4-9c49-158ed1ad2f72",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 3,
- "point": [171.47, 288.63],
- "size": [176.22, 192.26],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "13448777-d8f5-46cd-8a70-a4259211902e": {
- "id": "13448777-d8f5-46cd-8a70-a4259211902e",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 4,
- "point": [511.7, 404.19],
- "size": [181.08999999999992, 150.40999999999997],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "75010635-8dfb-48ea-9250-719e50e58f02": {
- "id": "75010635-8dfb-48ea-9250-719e50e58f02",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 5,
- "point": [384.09, 378.45],
- "size": [95.20999999999992, 91.1799999999999],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "c892d665-3311-4e25-a0bf-c4632d777f7e": {
- "id": "c892d665-3311-4e25-a0bf-c4632d777f7e",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 6,
- "point": [162.45, 679.23],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "51641de1-9787-41b8-afcc-2c85fd1b24c7": {
- "id": "51641de1-9787-41b8-afcc-2c85fd1b24c7",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 7,
- "point": [517.18, 783.54],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "e08c415e-3db3-4d3b-878e-28ce693ec1b0": {
- "id": "e08c415e-3db3-4d3b-878e-28ce693ec1b0",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 8,
- "point": [398.99, 810.79],
- "radiusX": 45.484999999999985,
- "radiusY": 45.48499999999996,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "fee77127-e779-4576-882b-b1bf7c7e132f": {
- "id": "fee77127-e779-4576-882b-b1bf7c7e132f",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 9,
- "point": [252.85, 1057.5],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [0.09000000000000341, 208]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [0.045000000000001705, 104]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "2d842ace-ebc5-4e83-acdf-de29352e5e62": {
- "id": "2d842ace-ebc5-4e83-acdf-de29352e5e62",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 10,
- "point": [616.9, 1124.3],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [2.4500000000000455, 185.20000000000005]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [1.2250000000000227, 92.60000000000002]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f": {
- "id": "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 11,
- "point": [425.18, 1143.2],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [1.8500000000000227, 95.70000000000005]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [0.9250000000000114, 47.85000000000002]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "38e9e750-16c2-4476-93ab-21aeb5f8858f": {
- "id": "38e9e750-16c2-4476-93ab-21aeb5f8858f",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 12,
- "point": [207.16, 1422.4],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- },
- "5ba998df-c036-447a-9b88-d96c71394f52": {
- "id": "5ba998df-c036-447a-9b88-d96c71394f52",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 13,
- "point": [389.57, 1496.5],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- },
- "3c688979-b190-4270-915b-7d8dd22a2bb7": {
- "id": "3c688979-b190-4270-915b-7d8dd22a2bb7",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 14,
- "point": [564.06, 1558.1],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- }
- }
- }
- },
- "code": {
- "file0": {
- "id": "file0",
- "name": "index.ts",
- "code": "\nconst draw = new Draw({\n points: [\n ...Utils.getPointsBetween([0, 0], [20, 50]),\n ...Utils.getPointsBetween([20, 50], [100, 20], 3),\n ...Utils.getPointsBetween([100, 20], [100, 100], 10),\n [100, 100],\n ],\n})\n\nconst rectangle = new Rectangle({\n point: [200, 0],\n style: {\n color: ColorStyle.Blue,\n },\n})\n\nconst ellipse = new Ellipse({\n point: [400, 0],\n})\n\nconst arrow = new Arrow({\n start: [600, 0],\n end: [700, 100],\n})\n\nconst radius = 1000\nconst count = 100\nconst center = [350, 50]\n\nfor (let i = 0; i < count; i++) {\n const point = Vec.rotWith(\n Vec.add(center, [radius, 0]),\n center,\n (Math.PI * 2 * i) / count\n )\n\n const dot = new Dot({\n point,\n })\n}\n "
- }
- }
- },
- "pageStates": {
- "page1": {
- "id": "page1",
- "camera": {
- "point": [0, -145],
- "zoom": 1
- },
- "selectedIds": {}
- }
- }
-}
diff --git a/__tests__/__mocks__/document.json b/__tests__/__mocks__/document.json
deleted file mode 100644
index 2c8a7b213..000000000
--- a/__tests__/__mocks__/document.json
+++ /dev/null
@@ -1,298 +0,0 @@
-{
- "document": {
- "id": "TESTING",
- "name": "My Document",
- "pages": {
- "page1": {
- "id": "page1",
- "type": "page",
- "name": "Page 1",
- "childIndex": 0,
- "shapes": {
- "e43559cb-6f41-4ae4-9c49-158ed1ad2f72": {
- "id": "e43559cb-6f41-4ae4-9c49-158ed1ad2f72",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 3,
- "point": [100, 100],
- "size": [100, 100],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "13448777-d8f5-46cd-8a70-a4259211902e": {
- "id": "13448777-d8f5-46cd-8a70-a4259211902e",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 4,
- "point": [500, 400],
- "size": [200, 200],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "75010635-8dfb-48ea-9250-719e50e58f02": {
- "id": "75010635-8dfb-48ea-9250-719e50e58f02",
- "type": "rectangle",
- "name": "Rectangle",
- "parentId": "page1",
- "childIndex": 5,
- "point": [384.09, 378.45],
- "size": [95.20999999999992, 91.1799999999999],
- "radius": 2,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "c892d665-3311-4e25-a0bf-c4632d777f7e": {
- "id": "c892d665-3311-4e25-a0bf-c4632d777f7e",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 6,
- "point": [162.45, 679.23],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "51641de1-9787-41b8-afcc-2c85fd1b24c7": {
- "id": "51641de1-9787-41b8-afcc-2c85fd1b24c7",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 7,
- "point": [517.18, 783.54],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "e08c415e-3db3-4d3b-878e-28ce693ec1b0": {
- "id": "e08c415e-3db3-4d3b-878e-28ce693ec1b0",
- "type": "ellipse",
- "name": "Ellipse",
- "parentId": "page1",
- "childIndex": 8,
- "point": [398.99, 810.79],
- "radiusX": 45.484999999999985,
- "radiusY": 45.48499999999996,
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "fee77127-e779-4576-882b-b1bf7c7e132f": {
- "id": "fee77127-e779-4576-882b-b1bf7c7e132f",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 9,
- "point": [252.85, 1057.5],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [0.09000000000000341, 208]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [0.045000000000001705, 104]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "2d842ace-ebc5-4e83-acdf-de29352e5e62": {
- "id": "2d842ace-ebc5-4e83-acdf-de29352e5e62",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 10,
- "point": [616.9, 1124.3],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [2.4500000000000455, 185.20000000000005]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [1.2250000000000227, 92.60000000000002]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f": {
- "id": "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f",
- "type": "arrow",
- "name": "Arrow",
- "parentId": "page1",
- "childIndex": 11,
- "point": [425.18, 1143.2],
- "rotation": 0,
- "bend": 0,
- "handles": {
- "start": {
- "id": "start",
- "index": 0,
- "point": [0, 0]
- },
- "end": {
- "id": "end",
- "index": 1,
- "point": [1.8500000000000227, 95.70000000000005]
- },
- "bend": {
- "id": "bend",
- "index": 2,
- "point": [0.9250000000000114, 47.85000000000002]
- }
- },
- "decorations": {
- "start": null,
- "middle": null,
- "end": "Arrow"
- },
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- }
- },
- "38e9e750-16c2-4476-93ab-21aeb5f8858f": {
- "id": "38e9e750-16c2-4476-93ab-21aeb5f8858f",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 12,
- "point": [207.16, 1422.4],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- },
- "5ba998df-c036-447a-9b88-d96c71394f52": {
- "id": "5ba998df-c036-447a-9b88-d96c71394f52",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 13,
- "point": [389.57, 1496.5],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- },
- "3c688979-b190-4270-915b-7d8dd22a2bb7": {
- "id": "3c688979-b190-4270-915b-7d8dd22a2bb7",
- "type": "text",
- "name": "Text",
- "parentId": "page1",
- "childIndex": 14,
- "point": [564.06, 1558.1],
- "rotation": 0,
- "style": {
- "color": "Black",
- "size": "Medium",
- "isFilled": false,
- "dash": "Draw"
- },
- "text": "Hello",
- "scale": 1
- }
- }
- }
- },
- "code": {
- "file0": {
- "id": "file0",
- "name": "index.ts",
- "code": "\nconst draw = new Draw({\n points: [\n ...Utils.getPointsBetween([0, 0], [20, 50]),\n ...Utils.getPointsBetween([20, 50], [100, 20], 3),\n ...Utils.getPointsBetween([100, 20], [100, 100], 10),\n [100, 100],\n ],\n})\n\nconst rectangle = new Rectangle({\n point: [200, 0],\n style: {\n color: ColorStyle.Blue,\n },\n})\n\nconst ellipse = new Ellipse({\n point: [400, 0],\n})\n\nconst arrow = new Arrow({\n start: [600, 0],\n end: [700, 100],\n})\n\nconst radius = 1000\nconst count = 100\nconst center = [350, 50]\n\nfor (let i = 0; i < count; i++) {\n const point = Vec.rotWith(\n Vec.add(center, [radius, 0]),\n center,\n (Math.PI * 2 * i) / count\n )\n\n const dot = new Dot({\n point,\n })\n}\n "
- }
- }
- },
- "pageState": {
- "id": "page1",
- "camera": {
- "point": [0, -145],
- "zoom": 1
- },
- "selectedIds": {}
- }
-}
diff --git a/__tests__/__snapshots__/code.test.ts.snap b/__tests__/__snapshots__/code.test.ts.snap
deleted file mode 100644
index 0f851d5c8..000000000
--- a/__tests__/__snapshots__/code.test.ts.snap
+++ /dev/null
@@ -1,280 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`selection creates a code control: generated code controls from code 1`] = `
-Object {
- "test-number-control": Object {
- "id": "test-number-control",
- "label": "x",
- "step": 1,
- "type": "number",
- "value": 0,
- },
-}
-`;
-
-exports[`selection generates a draw shape: generated draw from code 1`] = `
-Array [
- Object {
- "childIndex": 1,
- "id": "test-draw",
- "isGenerated": true,
- "name": "Test draw",
- "parentId": "page1",
- "point": Array [
- 0,
- 0,
- ],
- "points": Array [
- Array [
- 100,
- 100,
- ],
- Array [
- 200,
- 200,
- ],
- Array [
- 300,
- 300,
- ],
- ],
- "rotation": 0,
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "draw",
- },
-]
-`;
-
-exports[`selection generates a rectangle shape: generated rectangle from code 1`] = `
-Array [
- Object {
- "childIndex": 1,
- "id": "test-rectangle",
- "isGenerated": true,
- "name": "Test Rectangle",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 200,
- 200,
- ],
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
-]
-`;
-
-exports[`selection generates a text shape: generated draw from code 1`] = `
-Array [
- Object {
- "childIndex": 1,
- "id": "test-text",
- "isGenerated": true,
- "name": "Test text",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Large",
- },
- "text": "Hello world!",
- "type": "text",
- },
-]
-`;
-
-exports[`selection generates an arrow shape: generated draw from code 1`] = `
-Array [
- Object {
- "bend": 0,
- "childIndex": 1,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 50,
- 50,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 100,
- 100,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "test-draw",
- "isGenerated": true,
- "name": "Test draw",
- "parentId": "page1",
- "point": Array [
- 0,
- 0,
- ],
- "points": Array [
- Array [
- 100,
- 100,
- ],
- Array [
- 200,
- 200,
- ],
- Array [
- 300,
- 300,
- ],
- ],
- "rotation": 0,
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
-]
-`;
-
-exports[`selection generates an ellipse shape: generated ellipse from code 1`] = `
-Array [
- Object {
- "childIndex": 1,
- "id": "test-ellipse",
- "isGenerated": true,
- "name": "Test ellipse",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "radiusX": 100,
- "radiusY": 200,
- "rotation": 0,
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
-]
-`;
-
-exports[`selection generates shapes: generated rectangle from code 1`] = `
-Array [
- Object {
- "childIndex": 1,
- "id": "test-rectangle",
- "isGenerated": true,
- "name": "Test Rectangle",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 200,
- 200,
- ],
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
-]
-`;
-
-exports[`selection updates a code control: data in state after changing control 1`] = `
-Object {
- "test-number-control": Object {
- "id": "test-number-control",
- "label": "x",
- "step": 1,
- "type": "number",
- "value": 100,
- },
- "test-vector-control": Object {
- "id": "test-vector-control",
- "isNormalized": false,
- "label": "size",
- "type": "vector",
- "value": Array [
- 0,
- 0,
- ],
- },
-}
-`;
-
-exports[`selection updates a code control: rectangle in state after changing code control 1`] = `
-Object {
- "childIndex": 1,
- "id": "test-rectangle",
- "isGenerated": true,
- "name": "Test Rectangle",
- "parentId": "page1",
- "point": Array [
- 0,
- 100,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 0,
- 0,
- ],
- "style": Object {
- "color": "Red",
- "dash": "Dotted",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
-}
-`;
diff --git a/__tests__/__snapshots__/dashes.test.ts.snap b/__tests__/__snapshots__/dashes.test.ts.snap
deleted file mode 100644
index 409a3a653..000000000
--- a/__tests__/__snapshots__/dashes.test.ts.snap
+++ /dev/null
@@ -1,57 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`ellipse dash props renders dashed props on a circle correctly: large dashed circle dash props 1`] = `
-Object {
- "strokeDasharray": "16 17.333333333333332",
- "strokeDashoffset": "8",
-}
-`;
-
-exports[`ellipse dash props renders dashed props on a circle correctly: large dashed ellipse dash props 1`] = `
-Object {
- "strokeDasharray": "16 17.333333333333332",
- "strokeDashoffset": "8",
-}
-`;
-
-exports[`ellipse dash props renders dashed props on a circle correctly: small dashed circle dash props 1`] = `
-Object {
- "strokeDasharray": "8 8.666666666666666",
- "strokeDashoffset": "4",
-}
-`;
-
-exports[`ellipse dash props renders dashed props on a circle correctly: small dashed ellipse dash props 1`] = `
-Object {
- "strokeDasharray": "8 8.666666666666666",
- "strokeDashoffset": "4",
-}
-`;
-
-exports[`ellipse dash props renders dotted props on a circle correctly: large dotted circle dash props 1`] = `
-Object {
- "strokeDasharray": "0.08 16.586666666666666",
- "strokeDashoffset": "0",
-}
-`;
-
-exports[`ellipse dash props renders dotted props on a circle correctly: large dotted ellipse dash props 1`] = `
-Object {
- "strokeDasharray": "0.08 16.586666666666666",
- "strokeDashoffset": "0",
-}
-`;
-
-exports[`ellipse dash props renders dotted props on a circle correctly: small dotted circle dash props 1`] = `
-Object {
- "strokeDasharray": "0.04 8.293333333333333",
- "strokeDashoffset": "0",
-}
-`;
-
-exports[`ellipse dash props renders dotted props on a circle correctly: small dotted ellipse dash props 1`] = `
-Object {
- "strokeDasharray": "0.04 8.293333333333333",
- "strokeDashoffset": "0",
-}
-`;
diff --git a/__tests__/__snapshots__/project.test.ts.snap b/__tests__/__snapshots__/project.test.ts.snap
deleted file mode 100644
index 9c0ee0649..000000000
--- a/__tests__/__snapshots__/project.test.ts.snap
+++ /dev/null
@@ -1,809 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`project loads file from json: data after mount from file 1`] = `
-Object {
- "code": Object {
- "file0": Object {
- "code": "
-const draw = new Draw({
- points: [
- ...Utils.getPointsBetween([0, 0], [20, 50]),
- ...Utils.getPointsBetween([20, 50], [100, 20], 3),
- ...Utils.getPointsBetween([100, 20], [100, 100], 10),
- [100, 100],
- ],
-})
-
-const rectangle = new Rectangle({
- point: [200, 0],
- style: {
- color: ColorStyle.Blue,
- },
-})
-
-const ellipse = new Ellipse({
- point: [400, 0],
-})
-
-const arrow = new Arrow({
- start: [600, 0],
- end: [700, 100],
-})
-
-const radius = 1000
-const count = 100
-const center = [350, 50]
-
-for (let i = 0; i < count; i++) {
- const point = Vec.rotWith(
- Vec.add(center, [radius, 0]),
- center,
- (Math.PI * 2 * i) / count
- )
-
- const dot = new Dot({
- point,
- })
-}
- ",
- "id": "file0",
- "name": "index.ts",
- },
- },
- "id": "TESTING",
- "name": "My Document",
- "pages": Object {
- "page1": Object {
- "childIndex": 0,
- "id": "page1",
- "name": "Page 1",
- "shapes": Object {
- "13448777-d8f5-46cd-8a70-a4259211902e": Object {
- "childIndex": 4,
- "id": "13448777-d8f5-46cd-8a70-a4259211902e",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 500,
- 400,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 200,
- 200,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "2d842ace-ebc5-4e83-acdf-de29352e5e62": Object {
- "bend": 0,
- "childIndex": 10,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 1.2250000000000227,
- 92.60000000000002,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 2.4500000000000455,
- 185.20000000000005,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "2d842ace-ebc5-4e83-acdf-de29352e5e62",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 616.9,
- 1124.3,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- "38e9e750-16c2-4476-93ab-21aeb5f8858f": Object {
- "childIndex": 12,
- "id": "38e9e750-16c2-4476-93ab-21aeb5f8858f",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 207.16,
- 1422.4,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "3c688979-b190-4270-915b-7d8dd22a2bb7": Object {
- "childIndex": 14,
- "id": "3c688979-b190-4270-915b-7d8dd22a2bb7",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 564.06,
- 1558.1,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "51641de1-9787-41b8-afcc-2c85fd1b24c7": Object {
- "childIndex": 7,
- "id": "51641de1-9787-41b8-afcc-2c85fd1b24c7",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 517.18,
- 783.54,
- ],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "5ba998df-c036-447a-9b88-d96c71394f52": Object {
- "childIndex": 13,
- "id": "5ba998df-c036-447a-9b88-d96c71394f52",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 389.57,
- 1496.5,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "75010635-8dfb-48ea-9250-719e50e58f02": Object {
- "childIndex": 5,
- "id": "75010635-8dfb-48ea-9250-719e50e58f02",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 384.09,
- 378.45,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 95.20999999999992,
- 91.1799999999999,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f": Object {
- "bend": 0,
- "childIndex": 11,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 0.9250000000000114,
- 47.85000000000002,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 1.8500000000000227,
- 95.70000000000005,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 425.18,
- 1143.2,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- "c892d665-3311-4e25-a0bf-c4632d777f7e": Object {
- "childIndex": 6,
- "id": "c892d665-3311-4e25-a0bf-c4632d777f7e",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 162.45,
- 679.23,
- ],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "e08c415e-3db3-4d3b-878e-28ce693ec1b0": Object {
- "childIndex": 8,
- "id": "e08c415e-3db3-4d3b-878e-28ce693ec1b0",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 398.99,
- 810.79,
- ],
- "radiusX": 45.484999999999985,
- "radiusY": 45.48499999999996,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "e43559cb-6f41-4ae4-9c49-158ed1ad2f72": Object {
- "childIndex": 3,
- "id": "e43559cb-6f41-4ae4-9c49-158ed1ad2f72",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 100,
- 100,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "fee77127-e779-4576-882b-b1bf7c7e132f": Object {
- "bend": 0,
- "childIndex": 9,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 0.045000000000001705,
- 104,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 0.09000000000000341,
- 208,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "fee77127-e779-4576-882b-b1bf7c7e132f",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 252.85,
- 1057.5,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- },
- "type": "page",
- },
- },
-}
-`;
-
-exports[`restoring project remounts the state after mutating the current state: data after re-mount from file 1`] = `
-Object {
- "code": Object {
- "file0": Object {
- "code": "
-const draw = new Draw({
- points: [
- ...Utils.getPointsBetween([0, 0], [20, 50]),
- ...Utils.getPointsBetween([20, 50], [100, 20], 3),
- ...Utils.getPointsBetween([100, 20], [100, 100], 10),
- [100, 100],
- ],
-})
-
-const rectangle = new Rectangle({
- point: [200, 0],
- style: {
- color: ColorStyle.Blue,
- },
-})
-
-const ellipse = new Ellipse({
- point: [400, 0],
-})
-
-const arrow = new Arrow({
- start: [600, 0],
- end: [700, 100],
-})
-
-const radius = 1000
-const count = 100
-const center = [350, 50]
-
-for (let i = 0; i < count; i++) {
- const point = Vec.rotWith(
- Vec.add(center, [radius, 0]),
- center,
- (Math.PI * 2 * i) / count
- )
-
- const dot = new Dot({
- point,
- })
-}
- ",
- "id": "file0",
- "name": "index.ts",
- },
- },
- "id": "TESTING",
- "name": "My Document",
- "pages": Object {
- "page1": Object {
- "childIndex": 0,
- "id": "page1",
- "name": "Page 1",
- "shapes": Object {
- "13448777-d8f5-46cd-8a70-a4259211902e": Object {
- "childIndex": 4,
- "id": "13448777-d8f5-46cd-8a70-a4259211902e",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 500,
- 400,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 200,
- 200,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "2d842ace-ebc5-4e83-acdf-de29352e5e62": Object {
- "bend": 0,
- "childIndex": 10,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 1.2250000000000227,
- 92.60000000000002,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 2.4500000000000455,
- 185.20000000000005,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "2d842ace-ebc5-4e83-acdf-de29352e5e62",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 616.9,
- 1124.3,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- "38e9e750-16c2-4476-93ab-21aeb5f8858f": Object {
- "childIndex": 12,
- "id": "38e9e750-16c2-4476-93ab-21aeb5f8858f",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 207.16,
- 1422.4,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "3c688979-b190-4270-915b-7d8dd22a2bb7": Object {
- "childIndex": 14,
- "id": "3c688979-b190-4270-915b-7d8dd22a2bb7",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 564.06,
- 1558.1,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "51641de1-9787-41b8-afcc-2c85fd1b24c7": Object {
- "childIndex": 7,
- "id": "51641de1-9787-41b8-afcc-2c85fd1b24c7",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 517.18,
- 783.54,
- ],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "5ba998df-c036-447a-9b88-d96c71394f52": Object {
- "childIndex": 13,
- "id": "5ba998df-c036-447a-9b88-d96c71394f52",
- "name": "Text",
- "parentId": "page1",
- "point": Array [
- 389.57,
- 1496.5,
- ],
- "rotation": 0,
- "scale": 1,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "text": "Hello",
- "type": "text",
- },
- "75010635-8dfb-48ea-9250-719e50e58f02": Object {
- "childIndex": 5,
- "id": "75010635-8dfb-48ea-9250-719e50e58f02",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 384.09,
- 378.45,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 95.20999999999992,
- 91.1799999999999,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f": Object {
- "bend": 0,
- "childIndex": 11,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 0.9250000000000114,
- 47.85000000000002,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 1.8500000000000227,
- 95.70000000000005,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "b8e4e2c5-c662-4587-bf80-b9820ad8ad7f",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 425.18,
- 1143.2,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- "c892d665-3311-4e25-a0bf-c4632d777f7e": Object {
- "childIndex": 6,
- "id": "c892d665-3311-4e25-a0bf-c4632d777f7e",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 162.45,
- 679.23,
- ],
- "radiusX": 102.99999999999997,
- "radiusY": 102.99999999999994,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "e08c415e-3db3-4d3b-878e-28ce693ec1b0": Object {
- "childIndex": 8,
- "id": "e08c415e-3db3-4d3b-878e-28ce693ec1b0",
- "name": "Ellipse",
- "parentId": "page1",
- "point": Array [
- 398.99,
- 810.79,
- ],
- "radiusX": 45.484999999999985,
- "radiusY": 45.48499999999996,
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "ellipse",
- },
- "e43559cb-6f41-4ae4-9c49-158ed1ad2f72": Object {
- "childIndex": 3,
- "id": "e43559cb-6f41-4ae4-9c49-158ed1ad2f72",
- "name": "Rectangle",
- "parentId": "page1",
- "point": Array [
- 100,
- 100,
- ],
- "radius": 2,
- "rotation": 0,
- "size": Array [
- 100,
- 100,
- ],
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "rectangle",
- },
- "fee77127-e779-4576-882b-b1bf7c7e132f": Object {
- "bend": 0,
- "childIndex": 9,
- "decorations": Object {
- "end": "Arrow",
- "middle": null,
- "start": null,
- },
- "handles": Object {
- "bend": Object {
- "id": "bend",
- "index": 2,
- "point": Array [
- 0.045000000000001705,
- 104,
- ],
- },
- "end": Object {
- "id": "end",
- "index": 1,
- "point": Array [
- 0.09000000000000341,
- 208,
- ],
- },
- "start": Object {
- "id": "start",
- "index": 0,
- "point": Array [
- 0,
- 0,
- ],
- },
- },
- "id": "fee77127-e779-4576-882b-b1bf7c7e132f",
- "name": "Arrow",
- "parentId": "page1",
- "point": Array [
- 252.85,
- 1057.5,
- ],
- "rotation": 0,
- "style": Object {
- "color": "Black",
- "dash": "Draw",
- "isFilled": false,
- "size": "Medium",
- },
- "type": "arrow",
- },
- },
- "type": "page",
- },
- },
-}
-`;
diff --git a/__tests__/bounds.test.ts b/__tests__/bounds.test.ts
deleted file mode 100644
index fee0821c3..000000000
--- a/__tests__/bounds.test.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { getShapeUtils } from 'state/shape-utils'
-import { getCommonBounds } from 'utils'
-import TestState, { arrowId, rectangleId } from './test-utils'
-
-describe('selection', () => {
- const tt = new TestState()
-
- it('measures correct bounds for selected item', () => {
- // Note: Each item should test its own bounds in its ./shapes/[shape].tsx file
-
- const shape = tt.getShape(rectangleId)
-
- tt.deselectAll().clickShape(rectangleId)
-
- expect(tt.state.values.selectedBounds).toStrictEqual(
- getShapeUtils(shape).getBounds(shape)
- )
- })
-
- it('measures correct bounds for rotated selected item', () => {
- const shape = tt.getShape(rectangleId)
-
- getShapeUtils(shape).rotateBy(shape, Math.PI * 2 * Math.random())
-
- tt.deselectAll().clickShape(rectangleId)
-
- expect(tt.state.values.selectedBounds).toStrictEqual(
- getShapeUtils(shape).getBounds(shape)
- )
-
- getShapeUtils(shape).rotateBy(shape, -Math.PI * 2 * Math.random())
-
- expect(tt.state.values.selectedBounds).toStrictEqual(
- getShapeUtils(shape).getBounds(shape)
- )
- })
-
- it('measures correct bounds for selected items', () => {
- const shape1 = tt.getShape(rectangleId)
- const shape2 = tt.getShape(arrowId)
-
- tt.deselectAll()
- .clickShape(shape1.id)
- .clickShape(shape2.id, { shiftKey: true })
-
- expect(tt.state.values.selectedBounds).toStrictEqual(
- getCommonBounds(
- getShapeUtils(shape1).getRotatedBounds(shape1),
- getShapeUtils(shape2).getRotatedBounds(shape2)
- )
- )
- })
-
- it('measures correct bounds for rotated selected items', () => {
- const shape1 = tt.getShape(rectangleId)
- const shape2 = tt.getShape(arrowId)
-
- getShapeUtils(shape1).rotateBy(shape1, Math.PI * 2 * Math.random())
- getShapeUtils(shape2).rotateBy(shape2, Math.PI * 2 * Math.random())
-
- tt.deselectAll()
- .clickShape(shape1.id)
- .clickShape(shape2.id, { shiftKey: true })
-
- expect(tt.state.values.selectedBounds).toStrictEqual(
- getCommonBounds(
- getShapeUtils(shape1).getRotatedBounds(shape1),
- getShapeUtils(shape2).getRotatedBounds(shape2)
- )
- )
- })
-})
diff --git a/__tests__/children.test.ts b/__tests__/children.test.ts
deleted file mode 100644
index 98f3e5dc9..000000000
--- a/__tests__/children.test.ts
+++ /dev/null
@@ -1,232 +0,0 @@
-import { MoveType, ShapeType } from 'types'
-import TestState from './test-utils'
-
-describe('shapes with children', () => {
- const tt = new TestState()
-
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'delete-me-bottom'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 2,
- },
- '1'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [300, 0],
- size: [100, 100],
- childIndex: 3,
- },
- '2'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 300],
- size: [100, 100],
- childIndex: 4,
- },
- 'delete-me-middle'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 300],
- size: [100, 100],
- childIndex: 5,
- },
- '3'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [300, 300],
- size: [100, 100],
- childIndex: 6,
- },
- '4'
- )
-
- // Delete shapes at the start and in the middle of the list
-
- tt.clickShape('delete-me-bottom')
- .send('DELETED')
- .clickShape('delete-me-middle')
- .send('DELETED')
-
- it('has shapes in order', () => {
- expect(
- Object.values(tt.data.document.pages[tt.data.currentParentId].shapes)
- .sort((a, b) => a.childIndex - b.childIndex)
- .map((shape) => shape.childIndex)
- ).toStrictEqual([2, 3, 5, 6])
- })
-
- it('moves a shape to back', () => {
- tt.clickShape('3').send('MOVED', {
- type: MoveType.ToBack,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '2', '4'])
- })
-
- it('moves two adjacent siblings to back', () => {
- tt.clickShape('4').clickShape('2', { shiftKey: true }).send('MOVED', {
- type: MoveType.ToBack,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '4', '3', '1'])
- })
-
- it('moves two non-adjacent siblings to back', () => {
- tt.clickShape('4').clickShape('1', { shiftKey: true }).send('MOVED', {
- type: MoveType.ToBack,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '2', '3'])
- })
-
- it('moves a shape backward', () => {
- tt.clickShape('3').send('MOVED', {
- type: MoveType.Backward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '3', '2'])
- })
-
- it('moves a shape at first index backward', () => {
- tt.clickShape('4').send('MOVED', {
- type: MoveType.Backward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '3', '2'])
- })
-
- it('moves two adjacent siblings backward', () => {
- tt.clickShape('3').clickShape('2', { shiftKey: true }).send('MOVED', {
- type: MoveType.Backward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '3', '2', '1'])
- })
-
- it('moves two non-adjacent siblings backward', () => {
- tt.clickShape('3')
- .clickShape('1', { shiftKey: true })
- .send('MOVED', { type: MoveType.Backward })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '4', '1', '2'])
- })
-
- it('moves two adjacent siblings backward at zero index', () => {
- tt.clickShape('3').clickShape('4', { shiftKey: true }).send('MOVED', {
- type: MoveType.Backward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '4', '1', '2'])
- })
-
- it('moves a shape forward', () => {
- tt.clickShape('4').send('MOVED', {
- type: MoveType.Forward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '4', '2'])
- })
-
- it('moves a shape forward at the top index', () => {
- tt.clickShape('2').send('MOVED', {
- type: MoveType.Forward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '4', '2'])
- })
-
- it('moves two adjacent siblings forward', () => {
- tt.deselectAll()
- .clickShape('4')
- .clickShape('1', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.Forward,
- })
-
- expect(tt.idsAreSelected(['1', '4'])).toBe(true)
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '2', '1', '4'])
- })
-
- it('moves two non-adjacent siblings forward', () => {
- tt.deselectAll()
- .clickShape('3')
- .clickShape('1', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.Forward,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '3', '4', '1'])
- })
-
- it('moves two adjacent siblings forward at top index', () => {
- tt.deselectAll()
- .clickShape('3')
- .clickShape('1', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.Forward,
- })
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '4', '3', '1'])
- })
-
- it('moves a shape to front', () => {
- tt.deselectAll().clickShape('2').send('MOVED', {
- type: MoveType.ToFront,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '3', '1', '2'])
- })
-
- it('moves two adjacent siblings to front', () => {
- tt.deselectAll()
- .clickShape('3')
- .clickShape('1', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.ToFront,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '2', '3', '1'])
- })
-
- it('moves two non-adjacent siblings to front', () => {
- tt.deselectAll()
- .clickShape('4')
- .clickShape('3', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.ToFront,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '1', '4', '3'])
- })
-
- it('moves siblings already at front to front', () => {
- tt.deselectAll()
- .clickShape('4')
- .clickShape('3', { shiftKey: true })
- .send('MOVED', {
- type: MoveType.ToFront,
- })
-
- expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '1', '4', '3'])
- })
-})
diff --git a/__tests__/code.test.ts b/__tests__/code.test.ts
deleted file mode 100644
index e37926766..000000000
--- a/__tests__/code.test.ts
+++ /dev/null
@@ -1,284 +0,0 @@
-import { generateFromCode } from 'state/code/generate'
-import * as json from './__mocks__/document.json'
-import TestState from './test-utils'
-
-jest.useRealTimers()
-
-const tt = new TestState()
-tt.resetDocumentState()
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
- .send('CLEARED_PAGE')
- .save()
-
-describe('selection', () => {
- it('opens and closes the code panel', () => {
- expect(tt.data.settings.isCodeOpen).toBe(false)
- tt.send('TOGGLED_CODE_PANEL_OPEN')
- expect(tt.data.settings.isCodeOpen).toBe(true)
- tt.send('TOGGLED_CODE_PANEL_OPEN')
- expect(tt.data.settings.isCodeOpen).toBe(false)
- })
-
- it('saves changes to code', () => {
- expect(tt.getSortedPageShapeIds().length).toBe(0)
-
- const code = `// hello world!`
-
- tt.send('SAVED_CODE', { code })
-
- expect(tt.data.document.code[tt.data.currentCodeFileId].code).toBe(code)
- })
-
- it('generates shapes', async () => {
- const code = `
- const rectangle = new Rectangle({
- id: "test-rectangle",
- name: 'Test Rectangle',
- point: [100, 100],
- size: [200, 200],
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated rectangle from code')
- })
-
- it('creates a code control', async () => {
- const code = `
- new NumberControl({
- id: "test-number-control",
- label: "x"
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.data.codeControls).toMatchSnapshot(
- 'generated code controls from code'
- )
- })
-
- it('updates a code control', async () => {
- const code = `
- new NumberControl({
- id: "test-number-control",
- label: "x"
- })
-
- new VectorControl({
- id: "test-vector-control",
- label: "size"
- })
-
- const rectangle = new Rectangle({
- id: "test-rectangle",
- name: 'Test Rectangle',
- point: [controls.x, 100],
- size: controls.size,
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- tt.send('CHANGED_CODE_CONTROL', { 'test-number-control': 100 })
-
- expect(tt.data.codeControls).toMatchSnapshot(
- 'data in state after changing control'
- )
-
- expect(tt.getShape('test-rectangle')).toMatchSnapshot(
- 'rectangle in state after changing code control'
- )
- })
-
- /* -------------------- Readonly -------------------- */
-
- it('does not saves changes to code when readonly', () => {
- tt.send('CLEARED_PAGE')
-
- expect(tt.getShapes().length).toBe(0)
-
- const code = `// hello world!`
-
- tt.send('SAVED_CODE', { code })
- .send('TOGGLED_READ_ONLY')
- .send('SAVED_CODE', { code: '' })
-
- expect(tt.data.document.code[tt.data.currentCodeFileId].code).toBe(code)
-
- tt.send('TOGGLED_READ_ONLY').send('SAVED_CODE', { code: '' })
-
- expect(tt.data.document.code[tt.data.currentCodeFileId].code).toBe('')
- })
-
- /* --------------------- Methods -------------------- */
-
- it('moves shape to front', async () => {
- null
- })
-
- it('moves shape forward', async () => {
- null
- })
-
- it('moves shape backward', async () => {
- null
- })
-
- it('moves shape to back', async () => {
- null
- })
-
- it('rotates a shape', async () => {
- null
- })
-
- it('rotates a shape by a delta', async () => {
- null
- })
-
- it('translates a shape', async () => {
- null
- })
-
- it('translates a shape by a delta', async () => {
- null
- })
-
- /* --------------------- Shapes --------------------- */
-
- it('generates a rectangle shape', async () => {
- tt.send('CLEARED_PAGE')
- const code = `
- const rectangle = new Rectangle({
- id: "test-rectangle",
- name: 'Test Rectangle',
- point: [100, 100],
- size: [200, 200],
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated rectangle from code')
- })
-
- it('changes a rectangle size', async () => {
- null
- })
-
- it('generates an ellipse shape', async () => {
- tt.send('CLEARED_PAGE')
- const code = `
- const ellipse = new Ellipse({
- id: 'test-ellipse',
- name: 'Test ellipse',
- point: [100, 100],
- radiusX: 100,
- radiusY: 200,
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated ellipse from code')
- })
-
- it('generates a draw shape', async () => {
- tt.send('CLEARED_PAGE')
- const code = `
- const ellipse = new Draw({
- id: 'test-draw',
- name: 'Test draw',
- points: [[100, 100], [200,200], [300,300]],
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated draw from code')
- })
-
- it('generates an arrow shape', async () => {
- tt.send('CLEARED_PAGE')
- const code = `
- const draw = new Arrow({
- id: 'test-draw',
- name: 'Test draw',
- points: [[100, 100], [200,200], [300,300]],
- style: {
- size: SizeStyle.Medium,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated draw from code')
- })
-
- it('generates a text shape', async () => {
- tt.send('CLEARED_PAGE')
- const code = `
- const text = new Text({
- id: 'test-text',
- name: 'Test text',
- point: [100, 100],
- text: 'Hello world!',
- style: {
- size: SizeStyle.Large,
- color: ColorStyle.Red,
- dash: DashStyle.Dotted,
- },
- })
- `
-
- const { controls, shapes } = await generateFromCode(tt.data, code)
-
- tt.send('GENERATED_FROM_CODE', { controls, shapes })
-
- expect(tt.getShapes()).toMatchSnapshot('generated draw from code')
- })
-})
diff --git a/__tests__/commands/__snapshots__/transform.test.ts.snap b/__tests__/commands/__snapshots__/transform.test.ts.snap
deleted file mode 100644
index cd0c460ac..000000000
--- a/__tests__/commands/__snapshots__/transform.test.ts.snap
+++ /dev/null
@@ -1,852 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`transform command snapshot tests shift-transforms corners 1`] = `
-Object {
- "height": 593.73,
- "maxX": 700,
- "maxY": 600,
- "minX": -12.476,
- "minY": 6.27,
- "width": 712.476,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 2`] = `
-Object {
- "rect1": Object {
- "point": Array [
- -12.476,
- 6.27,
- ],
- "size": Array [
- 118.75,
- 118.75,
- ],
- },
- "rect2": Object {
- "point": Array [
- 462.51,
- 362.51,
- ],
- "size": Array [
- 237.49,
- 237.49,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 3`] = `
-Object {
- "height": 531.6320000000001,
- "maxX": 737.9599999999999,
- "maxY": 600,
- "minX": 100,
- "minY": 68.368,
- "width": 637.9599999999999,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 4`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 68.368,
- ],
- "size": Array [
- 106.33,
- 106.33,
- ],
- },
- "rect2": Object {
- "point": Array [
- 525.31,
- 387.35,
- ],
- "size": Array [
- 212.65,
- 212.65,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 5`] = `
-Object {
- "height": 533.62,
- "maxX": 740.3499999999999,
- "maxY": 633.62,
- "minX": 100,
- "minY": 100,
- "width": 640.3499999999999,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 6`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 106.72,
- 106.72,
- ],
- },
- "rect2": Object {
- "point": Array [
- 526.9,
- 420.17,
- ],
- "size": Array [
- 213.45,
- 213.45,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 7`] = `
-Object {
- "height": 490.52,
- "maxX": 700,
- "maxY": 590.52,
- "minX": 111.38,
- "minY": 100,
- "width": 588.62,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms corners 8`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 111.38,
- 100,
- ],
- "size": Array [
- 98.104,
- 98.104,
- ],
- },
- "rect2": Object {
- "point": Array [
- 503.79,
- 394.31,
- ],
- "size": Array [
- 196.21,
- 196.21,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 1`] = `
-Object {
- "height": 593.73,
- "maxX": 756.24,
- "maxY": 600,
- "minX": 43.762,
- "minY": 6.27,
- "width": 712.4780000000001,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 2`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 43.762,
- 6.27,
- ],
- "size": Array [
- 118.75,
- 118.75,
- ],
- },
- "rect2": Object {
- "point": Array [
- 518.75,
- 362.51,
- ],
- "size": Array [
- 237.49,
- 237.49,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 3`] = `
-Object {
- "height": 531.6260000000001,
- "maxX": 737.9599999999999,
- "maxY": 615.8100000000001,
- "minX": 100,
- "minY": 84.184,
- "width": 637.9599999999999,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 4`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 84.184,
- ],
- "size": Array [
- 106.33,
- 106.33,
- ],
- },
- "rect2": Object {
- "point": Array [
- 525.31,
- 403.16,
- ],
- "size": Array [
- 212.65,
- 212.65,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 5`] = `
-Object {
- "height": 411.35,
- "maxX": 646.81,
- "maxY": 511.35,
- "minX": 153.19,
- "minY": 100,
- "width": 493.61999999999995,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 6`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 153.19,
- 100,
- ],
- "size": Array [
- 82.269,
- 82.269,
- ],
- },
- "rect2": Object {
- "point": Array [
- 482.27,
- 346.81,
- ],
- "size": Array [
- 164.54,
- 164.54,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 7`] = `
-Object {
- "height": 490.52,
- "maxX": 700,
- "maxY": 595.26,
- "minX": 111.38,
- "minY": 104.74,
- "width": 588.62,
-}
-`;
-
-exports[`transform command snapshot tests shift-transforms edges 8`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 111.38,
- 104.74,
- ],
- "size": Array [
- 98.104,
- 98.104,
- ],
- },
- "rect2": Object {
- "point": Array [
- 503.79,
- 399.05,
- ],
- "size": Array [
- 196.21,
- 196.21,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 1`] = `
-Object {
- "height": 593.73,
- "maxX": 700,
- "maxY": 600,
- "minX": 27.892,
- "minY": 6.27,
- "width": 672.108,
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 2`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 27.892,
- 6.27,
- ],
- "size": Array [
- 112.02,
- 118.75,
- ],
- },
- "rect2": Object {
- "point": Array [
- 475.96,
- 362.51,
- ],
- "size": Array [
- 224.04,
- 237.49,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 3`] = `
-Object {
- "height": 490.17,
- "maxX": 737.9599999999999,
- "maxY": 600,
- "minX": 100,
- "minY": 109.83,
- "width": 637.9599999999999,
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 4`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 109.83,
- ],
- "size": Array [
- 106.33,
- 98.034,
- ],
- },
- "rect2": Object {
- "point": Array [
- 525.31,
- 403.93,
- ],
- "size": Array [
- 212.65,
- 196.07,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 5`] = `
-Object {
- "height": 411.35,
- "maxX": 740.3499999999999,
- "maxY": 511.35,
- "minX": 100,
- "minY": 100,
- "width": 640.3499999999999,
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 6`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 106.72,
- 82.269,
- ],
- },
- "rect2": Object {
- "point": Array [
- 526.9,
- 346.81,
- ],
- "size": Array [
- 213.45,
- 164.54,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 7`] = `
-Object {
- "height": 437.4,
- "maxX": 700,
- "maxY": 537.4,
- "minX": 111.38,
- "minY": 100,
- "width": 588.62,
-}
-`;
-
-exports[`transform command snapshot tests transforms corners 8`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 111.38,
- 100,
- ],
- "size": Array [
- 98.104,
- 87.479,
- ],
- },
- "rect2": Object {
- "point": Array [
- 503.79,
- 362.44,
- ],
- "size": Array [
- 196.21,
- 174.96,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 1`] = `
-Object {
- "height": 593.73,
- "maxX": 700,
- "maxY": 600,
- "minX": 100,
- "minY": 6.27,
- "width": 600,
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 2`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 6.27,
- ],
- "size": Array [
- 100,
- 118.75,
- ],
- },
- "rect2": Object {
- "point": Array [
- 500,
- 362.51,
- ],
- "size": Array [
- 200,
- 237.49,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 3`] = `
-Object {
- "height": 500,
- "maxX": 737.9599999999999,
- "maxY": 600,
- "minX": 100,
- "minY": 100,
- "width": 637.9599999999999,
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 4`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 106.33,
- 100,
- ],
- },
- "rect2": Object {
- "point": Array [
- 525.31,
- 400,
- ],
- "size": Array [
- 212.65,
- 200,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 5`] = `
-Object {
- "height": 411.35,
- "maxX": 700,
- "maxY": 511.35,
- "minX": 100,
- "minY": 100,
- "width": 600,
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 6`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 100,
- 82.269,
- ],
- },
- "rect2": Object {
- "point": Array [
- 500,
- 346.81,
- ],
- "size": Array [
- 200,
- 164.54,
- ],
- },
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 7`] = `
-Object {
- "height": 500,
- "maxX": 700,
- "maxY": 600,
- "minX": 111.38,
- "minY": 100,
- "width": 588.62,
-}
-`;
-
-exports[`transform command snapshot tests transforms edges 8`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 111.38,
- 100,
- ],
- "size": Array [
- 98.104,
- 100,
- ],
- },
- "rect2": Object {
- "point": Array [
- 503.79,
- 400,
- ],
- "size": Array [
- 196.21,
- 200,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the bottom edge 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 100,
- 120,
- ],
- },
- "rect2": Object {
- "point": Array [
- 500,
- 460,
- ],
- "size": Array [
- 200,
- 240,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the bottom-left corner 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 200,
- 100,
- ],
- "size": Array [
- 83.333,
- 120,
- ],
- },
- "rect2": Object {
- "point": Array [
- 533.33,
- 460,
- ],
- "size": Array [
- 166.67,
- 240,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the bottom-right corner 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 116.67,
- 120,
- ],
- },
- "rect2": Object {
- "point": Array [
- 566.67,
- 460,
- ],
- "size": Array [
- 233.33,
- 240,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the left edge 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 200,
- 100,
- ],
- "size": Array [
- 83.333,
- 100,
- ],
- },
- "rect2": Object {
- "point": Array [
- 533.33,
- 400,
- ],
- "size": Array [
- 166.67,
- 200,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the right edge 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 116.67,
- 100,
- ],
- },
- "rect2": Object {
- "point": Array [
- 566.67,
- 400,
- ],
- "size": Array [
- 233.33,
- 200,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the top edge 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 200,
- ],
- "size": Array [
- 100,
- 80,
- ],
- },
- "rect2": Object {
- "point": Array [
- 500,
- 440,
- ],
- "size": Array [
- 200,
- 160,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the top-left corner 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 200,
- 200,
- ],
- "size": Array [
- 83.333,
- 80,
- ],
- },
- "rect2": Object {
- "point": Array [
- 533.33,
- 440,
- ],
- "size": Array [
- 166.67,
- 160,
- ],
- },
-}
-`;
-
-exports[`transform command transforms from the top-right corner 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 200,
- ],
- "size": Array [
- 116.67,
- 80,
- ],
- },
- "rect2": Object {
- "point": Array [
- 566.67,
- 440,
- ],
- "size": Array [
- 233.33,
- 160,
- ],
- },
-}
-`;
-
-exports[`transform command when transforming from the bottom-right corner does command 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 116.67,
- 120,
- ],
- },
- "rect2": Object {
- "point": Array [
- 566.67,
- 460,
- ],
- "size": Array [
- 233.33,
- 240,
- ],
- },
-}
-`;
-
-exports[`transform command when transforming from the bottom-right corner re-does command 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 116.67,
- 120,
- ],
- },
- "rect2": Object {
- "point": Array [
- 566.67,
- 460,
- ],
- "size": Array [
- 233.33,
- 240,
- ],
- },
-}
-`;
-
-exports[`transform command when transforming from the bottom-right corner un-does command 1`] = `
-Object {
- "rect1": Object {
- "point": Array [
- 100,
- 100,
- ],
- "size": Array [
- 100,
- 100,
- ],
- },
- "rect2": Object {
- "point": Array [
- 500,
- 400,
- ],
- "size": Array [
- 200,
- 200,
- ],
- },
-}
-`;
diff --git a/__tests__/commands/align.test.ts b/__tests__/commands/align.test.ts
deleted file mode 100644
index cc2de7824..000000000
--- a/__tests__/commands/align.test.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import TestState from '../test-utils'
-
-describe('align command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- describe('when one item is selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-
- describe('when multiple items are selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-})
diff --git a/__tests__/commands/change-page.test.ts b/__tests__/commands/change-page.test.ts
deleted file mode 100644
index 266dddca8..000000000
--- a/__tests__/commands/change-page.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import TestState from '../test-utils'
-
-describe('change page command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/create-page.test.ts b/__tests__/commands/create-page.test.ts
deleted file mode 100644
index abdf36b65..000000000
--- a/__tests__/commands/create-page.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import TestState from '../test-utils'
-
-describe('create page command', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('creates a page', () => {
- it('does command', () => {
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
-
- tt.send('CREATED_PAGE')
-
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
- })
-
- it('changes to the new page', () => {
- tt.restore().send('CREATED_PAGE')
-
- const pageId = Object.keys(tt.data.document.pages)[1]
-
- expect(tt.data.currentPageId).toBe(pageId)
- })
-
- it('un-does command', () => {
- tt.restore().send('CREATED_PAGE').undo()
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
- const pageId = Object.keys(tt.data.document.pages)[0]
- expect(tt.data.currentPageId).toBe(pageId)
- })
-
- it('re-does command', () => {
- tt.restore().send('CREATED_PAGE').undo().redo()
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
- const pageId = Object.keys(tt.data.document.pages)[1]
- expect(tt.data.currentPageId).toBe(pageId)
- })
- })
-})
diff --git a/__tests__/commands/delete-page.test.ts b/__tests__/commands/delete-page.test.ts
deleted file mode 100644
index 0c32877ba..000000000
--- a/__tests__/commands/delete-page.test.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-import TestState from '../test-utils'
-
-describe('delete page command', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- it('does command', () => {
- tt.reset().restore().send('CREATED_PAGE')
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- const pageId = Object.keys(tt.data.document.pages)[1]
- tt.send('DELETED_PAGE', { id: pageId })
-
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
-
- const firstPageId = Object.keys(tt.data.document.pages)[0]
- expect(tt.data.currentPageId).toBe(firstPageId)
- })
-
- it('un-does command', () => {
- tt.reset().restore().send('CREATED_PAGE')
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- const pageId = Object.keys(tt.data.document.pages)[1]
- tt.send('DELETED_PAGE', { id: pageId }).undo()
-
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- expect(tt.data.currentPageId).toBe(pageId)
- })
-
- it('re-does command', () => {
- tt.reset().restore().send('CREATED_PAGE')
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- const pageId = Object.keys(tt.data.document.pages)[1]
- tt.send('DELETED_PAGE', { id: pageId }).undo().redo()
-
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
-
- const firstPageId = Object.keys(tt.data.document.pages)[0]
- expect(tt.data.currentPageId).toBe(firstPageId)
- })
-
- describe('when first page is selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-
- describe('when project only has one page', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-})
diff --git a/__tests__/commands/delete-selected.ts b/__tests__/commands/delete-selected.ts
deleted file mode 100644
index 7df2eacc8..000000000
--- a/__tests__/commands/delete-selected.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import TestState from '../test-utils'
-
-describe('delete-selected command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- describe('when one item is selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-
- describe('when multiple items are selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-})
diff --git a/__tests__/commands/delete.test.ts b/__tests__/commands/delete.test.ts
deleted file mode 100644
index 2ce7fd65b..000000000
--- a/__tests__/commands/delete.test.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-import { ShapeType } from 'types'
-import TestState, { rectangleId, arrowId } from '../test-utils'
-
-describe('delete command', () => {
- const tt = new TestState()
-
- describe('deleting single shapes', () => {
- it('deletes a shape and undoes the delete', () => {
- tt.deselectAll().clickShape(rectangleId).pressDelete()
-
- expect(tt.idsAreSelected([])).toBe(true)
-
- expect(tt.getShape(rectangleId)).toBe(undefined)
-
- tt.undo()
-
- expect(tt.getShape(rectangleId)).toBeTruthy()
- expect(tt.idsAreSelected([rectangleId])).toBe(true)
-
- tt.redo()
-
- expect(tt.getShape(rectangleId)).toBe(undefined)
- })
- })
-
- describe('deleting and restoring grouped shapes', () => {
- it('creates a group', () => {
- tt.reset()
- .deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
- .send('GROUPED')
-
- const group = tt.getOnlySelectedShape()
-
- // Should select the group
- expect(tt.assertShapeProps(group, { type: ShapeType.Group })).toBe(true)
-
- const arrow = tt.getShape(arrowId)
-
- // The arrow should be have the group as its parent
- expect(tt.assertShapeProps(arrow, { parentId: group.id })).toBe(true)
- })
-
- it('selects the new group', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- expect(tt.idsAreSelected([groupId])).toBe(true)
- })
-
- it('assigns a new parent', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- expect(groupId === tt.data.currentPageId).toBe(false)
- })
-
- // Rectangle has the same new parent?
- it('assigns new parent to all selected shapes', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- expect(tt.hasParent(arrowId, groupId)).toBe(true)
- })
- })
-
- describe('selecting within the group', () => {
- it('selects the group when pointing a shape', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- tt.deselectAll().clickShape(rectangleId)
-
- expect(tt.idsAreSelected([groupId])).toBe(true)
- })
-
- it('keeps selection when pointing group shape', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- tt.deselectAll().clickShape(groupId)
-
- expect(tt.idsAreSelected([groupId])).toBe(true)
- })
-
- it('selects a grouped shape by double-pointing', () => {
- tt.deselectAll().doubleClickShape(rectangleId)
-
- expect(tt.idsAreSelected([rectangleId])).toBe(true)
- })
-
- it('selects a sibling on point after double-pointing into a grouped shape children', () => {
- tt.deselectAll().doubleClickShape(rectangleId).clickShape(arrowId)
-
- expect(tt.idsAreSelected([arrowId])).toBe(true)
- })
-
- it('rises up a selection level when escape is pressed', () => {
- const groupId = tt.getShape(arrowId).parentId
-
- tt.deselectAll().doubleClickShape(rectangleId).send('CANCELLED')
-
- tt.clickShape(rectangleId)
-
- expect(tt.idsAreSelected([groupId])).toBe(true)
- })
-
- // it('deletes and restores one shape', () => {
- // // Delete the rectangle first
- // state.send('UNDO')
-
- // expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
- // expect(tt.idsAreSelected([rectangleId])).toBe(true)
-
- // state.send('REDO')
-
- // expect(tld.getShape(tt.data, rectangleId)).toBe(undefined)
-
- // state.send('UNDO')
-
- // expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
- // expect(tt.idsAreSelected([rectangleId])).toBe(true)
- })
-})
diff --git a/__tests__/commands/distribute.test.ts b/__tests__/commands/distribute.test.ts
deleted file mode 100644
index dd0a86868..000000000
--- a/__tests__/commands/distribute.test.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import TestState from '../test-utils'
-
-describe('distribute command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- describe('when one item is selected', () => {
- it('does not change anything', () => {
- // TODO
- null
- })
- })
-
- describe('when two items are selected', () => {
- it('does not change anything', () => {
- // TODO
- null
- })
- })
-
- describe('when three or more items are selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-})
diff --git a/__tests__/commands/draw.test.ts b/__tests__/commands/draw.test.ts
deleted file mode 100644
index 545b5ac9d..000000000
--- a/__tests__/commands/draw.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import TestState from '../test-utils'
-
-describe('draw command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/duplicate-page.test.ts b/__tests__/commands/duplicate-page.test.ts
deleted file mode 100644
index 255b26f23..000000000
--- a/__tests__/commands/duplicate-page.test.ts
+++ /dev/null
@@ -1,109 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('duplicate page command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .save()
-
- describe('duplicates a page', () => {
- it('does, undoes, and redoes command', () => {
- tt.reset().restore()
-
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
- const pageId = Object.keys(tt.data.document.pages)[0]
- expect(tt.getShape('rect1').parentId).toBe(pageId)
-
- tt.send('DUPLICATED_PAGE', { id: pageId })
-
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- const newPageId = Object.keys(tt.data.document.pages)[1]
-
- expect(tt.data.currentPageId).toBe(newPageId)
-
- expect(tt.getShape('rect1').parentId).toBe(newPageId)
-
- tt.undo()
-
- expect(Object.keys(tt.data.document.pages).length).toBe(1)
- expect(tt.data.currentPageId).toBe(Object.keys(tt.data.document.pages)[0])
-
- expect(tt.getShape('rect1').parentId).toBe(pageId)
-
- tt.redo()
-
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
- expect(tt.data.currentPageId).toBe(Object.keys(tt.data.document.pages)[1])
-
- expect(tt.getShape('rect1').parentId).toBe(newPageId)
- })
- })
-
- describe('duplicates a page other than the current page', () => {
- tt.restore()
- .reset()
- .send('CREATED_PAGE')
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect2'
- )
- .send('CHANGED_PAGE', { id: 'page1' })
-
- const firstPageId = Object.keys(tt.data.document.pages)[0]
-
- // We should be back on the first page
- expect(tt.data.currentPageId).toBe(firstPageId)
-
- // But we should have two pages
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- const secondPageId = Object.keys(tt.data.document.pages)[1]
-
- // Now we duplicate the second page
- tt.send('DUPLICATED_PAGE', { id: secondPageId })
-
- // We should now have three pages
- expect(Object.keys(tt.data.document.pages).length).toBe(3)
-
- // The third page should also have a shape named rect2
- const thirdPageId = Object.keys(tt.data.document.pages)[2]
-
- // We should have changed pages to the third page
- expect(tt.data.currentPageId).toBe(thirdPageId)
-
- // And it should be the parent of the third page
- expect(tt.getShape('rect2').parentId).toBe(thirdPageId)
-
- tt.undo()
-
- // We should still be on the first page, but we should
- // have only two pages; the third page should be deleted
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
- expect(tt.data.document.pages[thirdPageId]).toBe(undefined)
- expect(tt.data.currentPageId).toBe(firstPageId)
-
- tt.redo()
-
- // We should be back on the third page
- expect(Object.keys(tt.data.document.pages).length).toBe(3)
- expect(tt.data.document.pages[thirdPageId]).toBeTruthy()
- expect(tt.data.currentPageId).toBe(Object.keys(tt.data.document.pages)[2])
-
- expect(tt.getShape('rect2').parentId).toBe(thirdPageId)
- })
-})
diff --git a/__tests__/commands/duplicate.test.ts b/__tests__/commands/duplicate.test.ts
deleted file mode 100644
index 48057b7f9..000000000
--- a/__tests__/commands/duplicate.test.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('duplicate command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- },
- 'rectangleShape'
- )
- .createShape(
- {
- type: ShapeType.Ellipse,
- point: [150, 150],
- radiusX: 50,
- radiusY: 50,
- },
- 'ellipseShape'
- )
- .save()
-
- describe('when one item is selected', () => {
- it('does, undoes and redoes command', () => {
- tt.restore()
-
- const shapesBeforeDuplication = tt.getSortedPageShapeIds()
-
- tt.clickShape('rectangleShape').send('DUPLICATED')
-
- const shapesAfterDuplication = tt.getSortedPageShapeIds()
-
- const duplicatedShapeId = tt.selectedIds[0]
- const duplicatedShape = tt.getShape(duplicatedShapeId)
-
- expect(shapesAfterDuplication.length).toEqual(
- shapesBeforeDuplication.length + 1
- )
- expect(
- tt.assertShapeProps(duplicatedShape, {
- type: ShapeType.Rectangle,
- size: [100, 100],
- })
- )
-
- tt.undo()
-
- const shapesAfterUndo = tt.getSortedPageShapeIds()
-
- expect(shapesAfterUndo.length).toEqual(shapesBeforeDuplication.length)
- expect(tt.getShape(duplicatedShapeId)).toBe(undefined)
- expect(tt.idsAreSelected(['rectangleShape'])).toBe(true)
-
- tt.redo()
-
- expect(tt.getShape(duplicatedShapeId)).toBeTruthy()
- expect(tt.idsAreSelected([duplicatedShapeId])).toBe(true)
- })
- })
-
- describe('when multiple items are selected', () => {
- it('does, undoes and redoes command', () => {
- tt.restore()
-
- const shapesBeforeDuplication = tt.getSortedPageShapeIds()
-
- tt.clickShape('rectangleShape')
- .clickShape('ellipseShape', { shiftKey: true })
- .send('DUPLICATED')
-
- const shapesAfterDuplication = tt.getSortedPageShapeIds()
-
- const duplicatedShapesIds = tt.selectedIds
- const [duplicatedRectangle, duplicatedEllipse] = duplicatedShapesIds.map(
- (shapeId) => tt.getShape(shapeId)
- )
-
- expect(shapesAfterDuplication.length).toEqual(
- shapesBeforeDuplication.length * 2
- )
- expect(
- tt.assertShapeProps(duplicatedRectangle, {
- type: ShapeType.Rectangle,
- size: [100, 100],
- })
- )
- expect(
- tt.assertShapeProps(duplicatedEllipse, {
- type: ShapeType.Ellipse,
- radiusX: 50,
- radiusY: 50,
- })
- )
-
- tt.undo()
-
- const shapesAfterUndo = tt.getSortedPageShapeIds()
-
- expect(shapesAfterUndo.length).toEqual(shapesBeforeDuplication.length)
- duplicatedShapesIds.forEach((shapeId) => {
- expect(tt.getShape(shapeId)).toBe(undefined)
- })
- expect(tt.idsAreSelected(['rectangleShape', 'ellipseShape'])).toBe(true)
-
- tt.redo()
-
- duplicatedShapesIds.forEach((shapeId) => {
- expect(tt.getShape(shapeId)).toBeTruthy()
- })
- expect(tt.idsAreSelected(duplicatedShapesIds)).toBe(true)
- })
- })
-})
diff --git a/__tests__/commands/edit.test.ts b/__tests__/commands/edit.test.ts
deleted file mode 100644
index 5d9d714a8..000000000
--- a/__tests__/commands/edit.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import TestState from '../test-utils'
-
-describe('edit command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/generate.test.ts b/__tests__/commands/generate.test.ts
deleted file mode 100644
index 74e37e2a3..000000000
--- a/__tests__/commands/generate.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import TestState from '../test-utils'
-
-describe('generate command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/group.test.ts b/__tests__/commands/group.test.ts
deleted file mode 100644
index dc9a1239a..000000000
--- a/__tests__/commands/group.test.ts
+++ /dev/null
@@ -1,151 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('group command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- isLocked: false,
- isHidden: false,
- isAspectRatioLocked: false,
- },
- 'rect1'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [400, 0],
- size: [100, 100],
- childIndex: 2,
- isHidden: false,
- isLocked: false,
- isAspectRatioLocked: false,
- },
- 'rect2'
- )
- .save()
-
- // it('deletes the group if it has only one child', () => {
- // tt.restore()
- // .clickShape('rect1')
- // .clickShape('rect2', { shiftKey: true })
- // .send('GROUPED')
-
- // const groupId = tt.getShape('rect1').parentId
-
- // expect(groupId === tt.data.currentPageId).toBe(false)
-
- // tt.doubleClickShape('rect1')
-
- // tt.send('DELETED')
-
- // expect(tt.getShape(groupId)).toBe(undefined)
- // expect(tt.getShape('rect2')).toBeTruthy()
- // })
-
- it('deletes the group if all children are deleted', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(groupId === tt.data.currentPageId).toBe(false)
-
- tt.doubleClickShape('rect1').clickShape('rect2', { shiftKey: true })
-
- tt.send('DELETED')
-
- expect(tt.getShape(groupId)).toBe(undefined)
- })
-
- it('creates a group', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(groupId === tt.data.currentPageId).toBe(false)
- })
-
- it('selects the group on single click', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
- .clickShape('rect1')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(tt.selectedIds).toEqual([groupId])
- })
-
- it('selects the item on double click', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
- .doubleClickShape('rect1')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(tt.data.currentParentId).toBe(groupId)
-
- expect(tt.selectedIds).toEqual(['rect1'])
- })
-
- it('resets currentPageId when clicking the canvas', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
- .doubleClickShape('rect1')
- .clickCanvas()
- .clickShape('rect1')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(tt.data.currentParentId).toBe(tt.data.currentPageId)
-
- expect(tt.selectedIds).toEqual([groupId])
- })
-
- it('creates a group and undoes and redoes', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .send('GROUPED')
-
- const groupId = tt.getShape('rect1').parentId
-
- expect(groupId === tt.data.currentPageId).toBe(false)
-
- tt.undo()
-
- expect(tt.getShape('rect1').parentId === tt.data.currentPageId).toBe(true)
- expect(tt.getShape(groupId)).toBe(undefined)
-
- tt.redo()
-
- expect(tt.getShape('rect1').parentId === tt.data.currentPageId).toBe(false)
- expect(tt.getShape(groupId)).toBeTruthy()
- })
-
- it('groups shapes with different parents', () => {
- // TODO
- null
- })
-
- it('does not group a parent group shape and its child', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/move-to-page.test.ts b/__tests__/commands/move-to-page.test.ts
deleted file mode 100644
index f098128bb..000000000
--- a/__tests__/commands/move-to-page.test.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import TestState from '../test-utils'
-
-describe('move-to-page command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- describe('when one item is selected', () => {
- it('does not change anything', () => {
- // TODO
- null
- })
- })
-
- describe('when multiple items are selected', () => {
- it('does command', () => {
- // TODO
- null
- })
-
- it('un-does command', () => {
- // TODO
- null
- })
-
- it('re-does command', () => {
- // TODO
- null
- })
- })
-
- it('reparents children of groups to page', () => {
- // TODO
- null
- })
-
- it('correctly preserves moved groups', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/commands/rename-page.test.ts b/__tests__/commands/rename-page.test.ts
deleted file mode 100644
index 1f70cab01..000000000
--- a/__tests__/commands/rename-page.test.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import TestState from '../test-utils'
-
-describe('rename page command', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('renames a page', () => {
- it('does, undoes, and redoes command', () => {
- tt.restore().reset().send('CREATED_PAGE')
-
- const pageId = Object.keys(tt.data.document.pages)[1]
-
- expect(tt.data.document.pages[pageId].name).toBe('Page 2')
-
- tt.send('RENAMED_PAGE', { id: pageId, name: 'My First Page' })
-
- expect(tt.data.document.pages[pageId].name).toBe('My First Page')
-
- tt.undo()
-
- expect(tt.data.document.pages[pageId].name).toBe('Page 2')
-
- tt.redo()
-
- expect(tt.data.document.pages[pageId].name).toBe('My First Page')
- })
- })
-
- describe('renames a page other than the current page', () => {
- tt.restore()
- .reset()
- .send('CREATED_PAGE')
- .send('CHANGED_PAGE', { id: 'page1' })
-
- expect(Object.keys(tt.data.document.pages).length).toBe(2)
-
- expect(tt.data.currentPageId).toBe('page1')
-
- const secondPageId = Object.keys(tt.data.document.pages)[1]
-
- expect(tt.data.document.pages[secondPageId].name).toBe('Page 2')
-
- tt.send('RENAMED_PAGE', { id: secondPageId, name: 'My Second Page' })
-
- expect(tt.data.document.pages[secondPageId].name).toBe('My Second Page')
-
- tt.undo()
-
- expect(tt.data.document.pages[secondPageId].name).toBe('Page 2')
-
- tt.redo()
-
- expect(tt.data.document.pages[secondPageId].name).toBe('My Second Page')
- })
-})
diff --git a/__tests__/commands/toggle.test.ts b/__tests__/commands/toggle.test.ts
deleted file mode 100644
index a19dc7ce2..000000000
--- a/__tests__/commands/toggle.test.ts
+++ /dev/null
@@ -1,237 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('toggle command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- isLocked: false,
- isHidden: false,
- isAspectRatioLocked: false,
- },
- 'rect1'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [400, 0],
- size: [100, 100],
- childIndex: 2,
- isHidden: false,
- isLocked: false,
- isAspectRatioLocked: false,
- },
- 'rect2'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [800, 0],
- size: [100, 100],
- childIndex: 3,
- isHidden: true,
- isLocked: true,
- isAspectRatioLocked: true,
- },
- 'rect3'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [1000, 0],
- size: [100, 100],
- childIndex: 4,
- isHidden: true,
- isLocked: true,
- isAspectRatioLocked: true,
- },
- 'rect4'
- )
- .save()
-
- describe('toggles properties on single shape', () => {
- it('does command', () => {
- tt.restore().clickShape('rect1')
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
- })
-
- it('undoes and redoes command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore().clickShape('rect1')
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- tt.send('UNDO')
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
-
- tt.send('REDO')
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- })
- })
-
- describe('toggles properties on shapes with matching properties, starting from false', () => {
- it('does command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore().clickShape('rect1').clickShape('rect2', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- expect(tt.getShape('rect2').isLocked).toBe(true)
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
- expect(tt.getShape('rect2').isLocked).toBe(false)
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- expect(tt.getShape('rect2').isLocked).toBe(true)
- })
-
- it('undoes and redoes command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore().clickShape('rect1').clickShape('rect2', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK').undo()
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
- expect(tt.getShape('rect2').isLocked).toBe(false)
-
- tt.redo()
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- expect(tt.getShape('rect2').isLocked).toBe(true)
- })
- })
-
- describe('toggles properties on shapes with matching properties, starting from true', () => {
- it('does command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore().clickShape('rect3').clickShape('rect4', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect3').isLocked).toBe(false)
- expect(tt.getShape('rect4').isLocked).toBe(false)
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect3').isLocked).toBe(true)
- expect(tt.getShape('rect4').isLocked).toBe(true)
- })
-
- it('undoes and redoes command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore().clickShape('rect3').clickShape('rect4', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK').undo()
-
- expect(tt.getShape('rect3').isLocked).toBe(true)
- expect(tt.getShape('rect4').isLocked).toBe(true)
-
- tt.redo()
-
- expect(tt.getShape('rect3').isLocked).toBe(false)
- expect(tt.getShape('rect4').isLocked).toBe(false)
- })
- })
-
- describe('toggles properties on shapes with different properties', () => {
- it('does command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .clickShape('rect3', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- expect(tt.getShape('rect2').isLocked).toBe(true)
- expect(tt.getShape('rect3').isLocked).toBe(true)
-
- tt.send('TOGGLED_SHAPE_LOCK')
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
- expect(tt.getShape('rect2').isLocked).toBe(false)
- expect(tt.getShape('rect3').isLocked).toBe(false)
- })
-
- it('undoes and redoes command', () => {
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .clickShape('rect3', { shiftKey: true })
-
- tt.send('TOGGLED_SHAPE_LOCK').undo()
-
- expect(tt.getShape('rect1').isLocked).toBe(false)
- expect(tt.getShape('rect2').isLocked).toBe(false)
- expect(tt.getShape('rect3').isLocked).toBe(true)
-
- tt.redo()
-
- expect(tt.getShape('rect1').isLocked).toBe(true)
- expect(tt.getShape('rect2').isLocked).toBe(true)
- expect(tt.getShape('rect3').isLocked).toBe(true)
- })
- })
-
- describe('catch all for other toggle props', () => {
- const eventPropertyPairs = {
- TOGGLED_SHAPE_LOCK: 'isLocked',
- TOGGLED_SHAPE_HIDE: 'isHidden',
- TOGGLED_SHAPE_ASPECT_LOCK: 'isAspectRatioLocked',
- }
-
- it('toggles all event property pairs', () => {
- Object.entries(eventPropertyPairs).forEach(([eventName, propName]) => {
- // Restore the saved data state, with the initial selection
- tt.restore()
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .clickShape('rect3', { shiftKey: true })
-
- tt.send(eventName)
-
- expect(tt.getShape('rect1')[propName]).toBe(true)
- expect(tt.getShape('rect2')[propName]).toBe(true)
- expect(tt.getShape('rect3')[propName]).toBe(true)
-
- tt.undo()
-
- expect(tt.getShape('rect1')[propName]).toBe(false)
- expect(tt.getShape('rect2')[propName]).toBe(false)
- expect(tt.getShape('rect3')[propName]).toBe(true)
-
- tt.redo()
-
- expect(tt.getShape('rect1')[propName]).toBe(true)
- expect(tt.getShape('rect2')[propName]).toBe(true)
- expect(tt.getShape('rect3')[propName]).toBe(true)
-
- tt.send(eventName)
-
- expect(tt.getShape('rect1')[propName]).toBe(false)
- expect(tt.getShape('rect2')[propName]).toBe(false)
- expect(tt.getShape('rect3')[propName]).toBe(false)
- })
- })
- })
-})
diff --git a/__tests__/commands/transform.test.ts b/__tests__/commands/transform.test.ts
deleted file mode 100644
index b8e859647..000000000
--- a/__tests__/commands/transform.test.ts
+++ /dev/null
@@ -1,347 +0,0 @@
-import { Corner, Edge, RectangleShape, ShapeType } from 'types'
-import { rng } from 'utils'
-import TestState from '../test-utils'
-
-describe('transform command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [100, 100],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [500, 400],
- size: [200, 200],
- childIndex: 2,
- },
- 'rect2'
- )
- .clickShape('rect1')
- .clickShape('rect2', { shiftKey: true })
- .save()
-
- function getSnapInfo() {
- return {
- rect1: {
- point: tt.getShape('rect1').point,
- size: tt.getShape('rect1').size,
- },
- rect2: {
- point: tt.getShape('rect2').point,
- size: tt.getShape('rect2').size,
- },
- }
- }
-
- it('sets up initial bounds', () => {
- expect(tt.selectedIds).toEqual(['rect1', 'rect2'])
-
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 700,
- maxY: 600,
- width: 600,
- height: 500,
- })
- })
-
- describe('when transforming from the bottom-right corner', () => {
- it('does command', () => {
- // Restore the saved data state, with the initial selection
- tt.restore()
-
- // Move the bounds handle
- tt.startClickingBoundsHandle(Corner.BottomRight)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 800,
- maxY: 700,
- width: 700,
- height: 600,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('un-does command', () => {
- // Repeat the same actions, but add an undo at the end
- tt.restore()
- .startClickingBoundsHandle(Corner.BottomRight)
- .movePointerBy([100, 100])
- .stopClickingBounds()
- .undo()
-
- // Expect the bounds to be the initial bounds
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 700,
- maxY: 600,
- width: 600,
- height: 500,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('re-does command', () => {
- // Repeat the same actions but add an undo and a redo at the end
- tt.restore()
- .startClickingBoundsHandle(Corner.BottomRight)
- .movePointerBy([100, 100])
- .stopClickingBounds()
- .undo()
- .redo()
-
- // Expect the bounds to be the transformed bounds
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 800,
- maxY: 700,
- width: 700,
- height: 600,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
- })
-
- // From here on, let's assume that the undo and redos work as expected,
- // so let's only test the command's execution.
-
- it('transforms from the top edge', () => {
- tt.restore()
- .startClickingBoundsHandle(Edge.Top)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 200,
- maxX: 700,
- maxY: 600,
- width: 600,
- height: 400,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the right edge', () => {
- tt.restore()
- .startClickingBoundsHandle(Edge.Right)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 800,
- maxY: 600,
- width: 700,
- height: 500,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the bottom edge', () => {
- tt.restore()
- .startClickingBoundsHandle(Edge.Bottom)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 700,
- maxY: 700,
- width: 600,
- height: 600,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the left edge', () => {
- tt.restore()
- .startClickingBoundsHandle(Edge.Left)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 200,
- minY: 100,
- maxX: 700,
- maxY: 600,
- width: 500,
- height: 500,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the top-left corner', () => {
- tt.restore()
- .startClickingBoundsHandle(Corner.TopLeft)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 200,
- minY: 200,
- maxX: 700,
- maxY: 600,
- width: 500,
- height: 400,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the top-right corner', () => {
- tt.restore()
- .startClickingBoundsHandle(Corner.TopRight)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 200,
- maxX: 800,
- maxY: 600,
- width: 700,
- height: 400,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the bottom-right corner', () => {
- tt.restore()
- .startClickingBoundsHandle(Corner.BottomRight)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 100,
- minY: 100,
- maxX: 800,
- maxY: 700,
- width: 700,
- height: 600,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- it('transforms from the bottom-left corner', () => {
- tt.restore()
- .startClickingBoundsHandle(Corner.BottomLeft)
- .movePointerBy([100, 100])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchObject({
- minX: 200,
- minY: 100,
- maxX: 700,
- maxY: 700,
- width: 500,
- height: 600,
- })
-
- expect(getSnapInfo()).toMatchSnapshot()
- })
-
- describe('snapshot tests', () => {
- it('transforms corners', () => {
- const getRandom = rng('transform-tests-random-number-generator')
-
- for (const corner of Object.values(Corner)) {
- tt.restore()
- .startClickingBoundsHandle(corner)
- .movePointerBy([getRandom() * 200, getRandom() * 200])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchSnapshot()
-
- expect(getSnapInfo()).toMatchSnapshot()
- }
- })
-
- it('transforms edges', () => {
- const getRandom = rng('transform-tests-random-number-generator')
-
- for (const edge of Object.values(Edge)) {
- tt.restore()
- .startClickingBoundsHandle(edge)
- .movePointerBy([getRandom() * 200, getRandom() * 200])
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchSnapshot()
-
- expect(getSnapInfo()).toMatchSnapshot()
- }
- })
-
- it('shift-transforms corners', () => {
- const getRandom = rng('transform-tests-random-number-generator')
-
- for (const corner of Object.values(Corner)) {
- tt.restore()
- .startClickingBoundsHandle(corner)
- .movePointerBy([getRandom() * 200, getRandom() * 200], {
- shiftKey: true,
- })
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchSnapshot()
-
- expect(getSnapInfo()).toMatchSnapshot()
- }
- })
-
- it('shift-transforms edges', () => {
- const getRandom = rng('transform-tests-random-number-generator')
-
- for (const edge of Object.values(Edge)) {
- tt.restore()
- .startClickingBoundsHandle(edge)
- .movePointerBy([getRandom() * 200, getRandom() * 200], {
- shiftKey: true,
- })
- .stopClickingBounds()
-
- // Ensure the bounds have been transformed
- expect(tt.state.values.selectedBounds).toMatchSnapshot()
-
- expect(getSnapInfo()).toMatchSnapshot()
- }
- })
- })
-})
diff --git a/__tests__/commands/translate.test.ts b/__tests__/commands/translate.test.ts
deleted file mode 100644
index d9ea22c8a..000000000
--- a/__tests__/commands/translate.test.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import TestState from '../test-utils'
-
-describe('translate command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('translates a single selected shape', () => {
- // TODO
- null
- })
-
- it('translates multiple selected shape', () => {
- // TODO
- null
- })
-
- it('translates while axis-locked', () => {
- // TODO
- null
- })
-
- it('translates after leaving axis-locked state', () => {
- // TODO
- null
- })
-
- it('creates clones while translating', () => {
- // TODO
- null
- })
-
- it('removes clones after leaving cloning state', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/coop.test.ts b/__tests__/coop.test.ts
deleted file mode 100644
index 0702ea18c..000000000
--- a/__tests__/coop.test.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import state from 'state'
-import coopState from 'state/coop/coop-state'
-import * as json from './__mocks__/document.json'
-
-state.reset()
-state
- .send('MOUNTED')
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-state.send('CLEARED_PAGE')
-
-coopState.reset()
-
-describe('coop', () => {
- it('joins a room', () => {
- // TODO
- null
- })
-
- it('leaves a room', () => {
- // TODO
- null
- })
-
- it('rejoins a room', () => {
- // TODO
- null
- })
-
- it('handles another user joining room', () => {
- // TODO
- null
- })
-
- it('handles another user leaving room', () => {
- // TODO
- null
- })
-
- it('sends mouse movements', () => {
- // TODO
- null
- })
-
- it('receives mouse movements', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/create.test.ts b/__tests__/create.test.ts
deleted file mode 100644
index 152585a77..000000000
--- a/__tests__/create.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import state from 'state'
-import * as json from './__mocks__/document.json'
-
-state.reset()
-state
- .send('MOUNTED')
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-state.send('CLEARED_PAGE')
-
-describe('arrow shape', () => {
- it('creates a shape', () => {
- // TODO
- null
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
-
- it('removes shape on undo and restores it on redo', () => {
- // TODO
- null
- })
-
- it('does not create shape when readonly', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/dashes.test.ts b/__tests__/dashes.test.ts
deleted file mode 100644
index a6e923e00..000000000
--- a/__tests__/dashes.test.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { DashStyle } from 'types'
-import { getPerfectDashProps } from 'utils'
-
-describe('ellipse dash props', () => {
- it('renders dashed props on a circle correctly', () => {
- expect(getPerfectDashProps(100, 4, DashStyle.Dashed)).toMatchSnapshot(
- 'small dashed circle dash props'
- )
- expect(getPerfectDashProps(100, 4, DashStyle.Dashed)).toMatchSnapshot(
- 'small dashed ellipse dash props'
- )
- expect(getPerfectDashProps(200, 8, DashStyle.Dashed)).toMatchSnapshot(
- 'large dashed circle dash props'
- )
- expect(getPerfectDashProps(200, 8, DashStyle.Dashed)).toMatchSnapshot(
- 'large dashed ellipse dash props'
- )
- })
-
- it('renders dotted props on a circle correctly', () => {
- expect(getPerfectDashProps(100, 4, DashStyle.Dotted)).toMatchSnapshot(
- 'small dotted circle dash props'
- )
- expect(getPerfectDashProps(100, 4, DashStyle.Dotted)).toMatchSnapshot(
- 'small dotted ellipse dash props'
- )
- expect(getPerfectDashProps(200, 8, DashStyle.Dotted)).toMatchSnapshot(
- 'large dotted circle dash props'
- )
- expect(getPerfectDashProps(200, 8, DashStyle.Dotted)).toMatchSnapshot(
- 'large dotted ellipse dash props'
- )
- })
-})
diff --git a/__tests__/locked.test.ts b/__tests__/locked.test.ts
deleted file mode 100644
index b0f089e09..000000000
--- a/__tests__/locked.test.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import TestState from './test-utils'
-
-describe('lock command', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('toggles a locked shape', () => {
- // TODO
- null
- })
-
- it('selects a locked shape', () => {
- // TODO
- null
- })
-
- it('does not translate a locked shape', () => {
- // TODO
- null
- })
-
- it('does not translate a locked shape in a group', () => {
- // TODO
- null
- })
-
- it('does not rotate a locked shape', () => {
- // TODO
- null
- })
-
- it('does not rotate a locked shape in a group', () => {
- // TODO
- null
- })
-
- it('dpes not transform a locked single shape', () => {
- // TODO
- null
- })
-
- it('does not transform a locked shape in a multiple selection', () => {
- // TODO
- null
- })
-
- it('does not transform a locked shape in a group', () => {
- // TODO
- null
- })
-
- it('does not change the style of a locked shape', () => {
- // TODO
- null
- })
-
- it('does not change the handles of a locked shape', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/project.test.ts b/__tests__/project.test.ts
deleted file mode 100644
index a027ec6c2..000000000
--- a/__tests__/project.test.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import state from 'state'
-import * as json from './__mocks__/document.json'
-
-describe('project', () => {
- state.reset()
- state.enableLog(true)
-
- it('mounts the state', () => {
- state.send('MOUNTED').send('MOUNTED_SHAPES')
-
- expect(state.isIn('ready')).toBe(true)
- })
-
- it('loads file from json', () => {
- state.send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-
- expect(state.isIn('ready')).toBe(true)
- expect(state.data.document).toMatchSnapshot('data after mount from file')
- })
-})
-
-describe('restoring project', () => {
- state.reset()
- state.enableLog(true)
-
- it('remounts the state after mutating the current state', () => {
- state
- .send('MOUNTED')
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
- .send('CLEARED_PAGE')
-
- expect(
- state.data.document.pages[state.data.currentPageId].shapes
- ).toStrictEqual({})
-
- state
- .send('MOUNTED')
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-
- expect(state.data.document).toMatchSnapshot('data after re-mount from file')
- })
-})
diff --git a/__tests__/selection.test.ts b/__tests__/selection.test.ts
deleted file mode 100644
index 960bace48..000000000
--- a/__tests__/selection.test.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-import TestState, { rectangleId, arrowId } from './test-utils'
-
-describe('selection', () => {
- const tt = new TestState()
-
- it('selects a shape', () => {
- tt.deselectAll().clickShape(rectangleId)
-
- expect(tt.idsAreSelected([rectangleId])).toBe(true)
- })
-
- it('selects and deselects a shape', () => {
- tt.deselectAll().clickShape(rectangleId).clickCanvas()
-
- expect(tt.idsAreSelected([])).toBe(true)
- })
-
- it('selects multiple shapes', () => {
- tt.deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
-
- expect(tt.idsAreSelected([rectangleId, arrowId])).toBe(true)
- })
-
- it('shift-selects to deselect shapes', () => {
- tt.deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
- .clickShape(rectangleId, { shiftKey: true })
-
- expect(tt.idsAreSelected([arrowId])).toBe(true)
- })
-
- it('single-selects shape in selection on click', () => {
- tt.deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
- .clickShape(arrowId)
-
- expect(tt.idsAreSelected([arrowId])).toBe(true)
- })
-
- it('single-selects shape in selection on pointerup only', () => {
- tt.deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
-
- expect(tt.idsAreSelected([rectangleId, arrowId])).toBe(true)
-
- tt.startClick(arrowId)
-
- expect(tt.idsAreSelected([rectangleId, arrowId])).toBe(true)
-
- tt.stopClick(arrowId)
-
- expect(tt.idsAreSelected([arrowId])).toBe(true)
- })
-
- it('selects shapes if shift key is lifted before pointerup', () => {
- tt.deselectAll()
- .clickShape(rectangleId)
- .clickShape(arrowId, { shiftKey: true })
- .startClick(rectangleId, { shiftKey: true })
- .stopClick(rectangleId)
-
- expect(tt.idsAreSelected([rectangleId])).toBe(true)
- })
-
- it('does not select on meta-click', () => {
- tt.deselectAll().clickShape(rectangleId, { ctrlKey: true })
-
- expect(tt.idsAreSelected([])).toBe(true)
- })
-
- it('does not select on meta-shift-click', () => {
- tt.deselectAll().clickShape(rectangleId, { ctrlKey: true, shiftKey: true })
-
- expect(tt.idsAreSelected([])).toBe(true)
- })
-})
diff --git a/__tests__/shapes/arrow.test.ts b/__tests__/shapes/arrow.test.ts
deleted file mode 100644
index 82b1fee0d..000000000
--- a/__tests__/shapes/arrow.test.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-import { ArrowShape, ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('arrow shape', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('creating arrows', () => {
- it('creates shape', () => {
- tt.reset().restore().send('SELECTED_ARROW_TOOL')
-
- expect(tt.state.isIn('arrow.creating')).toBe(true)
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
-
- const id = tt.getSortedPageShapeIds()[0]
-
- const shape = tt.getShape(id)
-
- tt.assertShapeType(id, ShapeType.Arrow)
-
- expect(shape.handles.start.point).toEqual([0, 0])
- expect(shape.handles.bend.point).toEqual([50.5, 50.5])
- expect(shape.handles.end.point).toEqual([101, 101])
- })
-
- it('creates shapes when pointing a shape', () => {
- tt.reset().restore().send('SELECTED_ARROW_TOOL').send('TOGGLED_TOOL_LOCK')
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
- tt.startClick('canvas').movePointerBy([-200, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('creates shapes when shape locked', () => {
- tt.reset()
- .restore()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .send('SELECTED_ARROW_TOOL')
-
- tt.startClick('rect1').movePointerBy([100, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
- })
-
- it('moves shape', () => {
- // TODO
- null
- })
-
- it('rotates shape', () => {
- // TODO
- null
- })
-
- it('rotates shape in a group', () => {
- // TODO
- null
- })
-
- it('measures shape bounds', () => {
- // TODO
- null
- })
-
- it('measures shape rotated bounds', () => {
- // TODO
- null
- })
-
- it('transforms single shape', () => {
- // TODO
- null
- })
-
- it('transforms in a group', () => {
- // TODO
- null
- })
-
- /* -------------------- Specific -------------------- */
-
- it('creates compass-aligned shape with shift key', () => {
- // TODO
- null
- })
-
- it('changes start handle', () => {
- // TODO
- null
- })
-
- it('changes end handle', () => {
- // TODO
- null
- })
-
- it('changes bend handle', () => {
- // TODO
- null
- })
-
- it('resets bend handle when double-pointed', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/shapes/draw.test.ts b/__tests__/shapes/draw.test.ts
deleted file mode 100644
index a261344fc..000000000
--- a/__tests__/shapes/draw.test.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('draw shape', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('creating draws', () => {
- it('creates shape', () => {
- tt.reset().restore().send('SELECTED_DRAW_TOOL')
-
- expect(tt.state.isIn('draw.creating')).toBe(true)
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
-
- const id = tt.getSortedPageShapeIds()[0]
-
- tt.assertShapeType(id, ShapeType.Draw)
- })
-
- it('creates shapes when pointing a shape', () => {
- tt.reset().restore().send('SELECTED_DRAW_TOOL').send('TOGGLED_TOOL_LOCK')
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
- tt.startClick('canvas').movePointerBy([-200, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('creates shapes when shape locked', () => {
- tt.reset()
- .restore()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .send('SELECTED_DRAW_TOOL')
-
- tt.startClick('rect1').movePointerBy([100, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
- })
-
- it('moves shape', () => {
- // TODO
- null
- })
-
- it('rotates shape', () => {
- // TODO
- null
- })
-
- it('rotates shape in a group', () => {
- // TODO
- null
- })
-
- it('measures shape bounds', () => {
- // TODO
- null
- })
-
- it('measures shape rotated bounds', () => {
- // TODO
- null
- })
-
- it('transforms single shape', () => {
- // TODO
- null
- })
-
- it('transforms in a group', () => {
- // TODO
- null
- })
-
- /* -------------------- Specific -------------------- */
-
- it('closes the shape when the start and end points are near enough', () => {
- // TODO
- null
- })
-
- it('remains closed after resizing up', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/shapes/ellipse.test.ts b/__tests__/shapes/ellipse.test.ts
deleted file mode 100644
index 9f4f2cd13..000000000
--- a/__tests__/shapes/ellipse.test.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('ellipse shape', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('creating ellipses', () => {
- it('creates shape', () => {
- tt.reset().restore().send('SELECTED_ELLIPSE_TOOL')
-
- expect(tt.state.isIn('ellipse.creating')).toBe(true)
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
-
- const id = tt.getSortedPageShapeIds()[0]
-
- tt.assertShapeType(id, ShapeType.Ellipse)
- })
-
- it('creates shapes when pointing a shape', () => {
- tt.reset()
- .restore()
- .send('SELECTED_ELLIPSE_TOOL')
- .send('TOGGLED_TOOL_LOCK')
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
- tt.startClick('canvas').movePointerBy([-200, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('creates shapes when shape locked', () => {
- tt.reset()
- .restore()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .send('SELECTED_ELLIPSE_TOOL')
-
- tt.startClick('rect1').movePointerBy([100, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
- })
-
- it('moves shape', () => {
- // TODO
- null
- })
-
- it('rotates shape', () => {
- // TODO
- null
- })
-
- it('rotates shape in a group', () => {
- // TODO
- null
- })
-
- it('measures shape bounds', () => {
- // TODO
- null
- })
-
- it('measures shape rotated bounds', () => {
- // TODO
- null
- })
-
- it('transforms single shape', () => {
- // TODO
- null
- })
-
- it('transforms in a group', () => {
- // TODO
- null
- })
-
- /* -------------------- Specific -------------------- */
-
- it('creates aspect-ratio-locked shape with shift key', () => {
- // TODO
- null
- })
-
- it('resizes aspect-ratio-locked shape with shift key', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/shapes/rectangle.test.ts b/__tests__/shapes/rectangle.test.ts
deleted file mode 100644
index ee331ca28..000000000
--- a/__tests__/shapes/rectangle.test.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-import { ShapeType } from 'types'
-import TestState from '../test-utils'
-
-describe('rectangle shape', () => {
- const tt = new TestState()
- tt.resetDocumentState().save()
-
- describe('creating rectangles', () => {
- it('creates shape', () => {
- tt.reset().restore().send('SELECTED_RECTANGLE_TOOL')
-
- expect(tt.state.isIn('rectangle.creating')).toBe(true)
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
-
- const id = tt.getSortedPageShapeIds()[0]
-
- tt.assertShapeType(id, ShapeType.Rectangle)
- })
-
- it('creates shapes when pointing a shape', () => {
- tt.reset()
- .restore()
- .send('SELECTED_RECTANGLE_TOOL')
- .send('TOGGLED_TOOL_LOCK')
-
- tt.startClick('canvas').movePointerBy([100, 100]).stopClick('canvas')
- tt.startClick('canvas').movePointerBy([-200, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('creates shapes when shape locked', () => {
- tt.reset()
- .restore()
- .createShape(
- {
- type: ShapeType.Rectangle,
- point: [0, 0],
- size: [100, 100],
- childIndex: 1,
- },
- 'rect1'
- )
- .send('SELECTED_RECTANGLE_TOOL')
-
- tt.startClick('rect1').movePointerBy([100, 100]).stopClick('canvas')
-
- expect(tt.getSortedPageShapeIds()).toHaveLength(2)
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
- })
-
- it('moves shape', () => {
- // TODO
- null
- })
-
- it('rotates shape', () => {
- // TODO
- null
- })
-
- it('rotates shape in a group', () => {
- // TODO
- null
- })
-
- it('measures shape bounds', () => {
- // TODO
- null
- })
-
- it('measures shape rotated bounds', () => {
- // TODO
- null
- })
-
- it('transforms single shape', () => {
- // TODO
- null
- })
-
- it('transforms in a group', () => {
- // TODO
- null
- })
-
- /* -------------------- Specific -------------------- */
-
- it('creates aspect-ratio-locked shape with shift key', () => {
- // TODO
- null
- })
-
- it('resizes aspect-ratio-locked shape with shift key', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/shapes/text.test.ts b/__tests__/shapes/text.test.ts
deleted file mode 100644
index f70bf3443..000000000
--- a/__tests__/shapes/text.test.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import TestState from '../test-utils'
-
-describe('arrow shape', () => {
- const tt = new TestState()
- tt.resetDocumentState()
-
- it('creates shape', () => {
- tt.send('SELECTED_TEXT_TOOL')
-
- expect(tt.state.isIn('text.creating')).toBe(true)
-
- const id = tt.getSortedPageShapeIds()[0]
-
- tt.clickCanvas()
-
- expect(tt.state.isIn('editingShape')).toBe(true)
-
- tt.send('EDITED_SHAPE', {
- id,
- change: { text: 'Hello world' },
- })
-
- tt.send('BLURRED_EDITING_SHAPE', { id: id })
-
- expect(tt.state.isIn('selecting')).toBe(true)
- })
-
- it('cancels shape while creating', () => {
- // TODO
- null
- })
-
- it('moves shape', () => {
- // TODO
- null
- })
-
- it('rotates shape', () => {
- // TODO
- null
- })
-
- it('rotates shape in a group', () => {
- // TODO
- null
- })
-
- it('measures shape bounds', () => {
- // TODO
- null
- })
-
- it('measures shape rotated bounds', () => {
- // TODO
- null
- })
-
- it('transforms single shape', () => {
- // TODO
- null
- })
-
- it('transforms in a group', () => {
- // TODO
- null
- })
-
- /* -------------------- Specific -------------------- */
-
- it('scales', () => {
- // TODO
- null
- })
-
- it('selects different text on tap while editing', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/style.test.ts b/__tests__/style.test.ts
deleted file mode 100644
index 65969e081..000000000
--- a/__tests__/style.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import state from 'state'
-import * as json from './__mocks__/document.json'
-
-state.reset()
-state
- .send('MOUNTED')
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-state.send('CLEARED_PAGE')
-
-describe('shape styles', () => {
- it('sets the color style of a shape', () => {
- // TODO
- null
- })
-
- it('sets the size style of a shape', () => {
- // TODO
- null
- })
-
- it('sets the dash style of a shape', () => {
- // TODO
- null
- })
-
- it('sets the isFilled style of a shape', () => {
- // TODO
- null
- })
-})
diff --git a/__tests__/test-utils.ts b/__tests__/test-utils.ts
deleted file mode 100644
index 2d99cbc50..000000000
--- a/__tests__/test-utils.ts
+++ /dev/null
@@ -1,836 +0,0 @@
-import _state from 'state'
-import tld from 'utils/tld'
-import inputs from 'state/inputs'
-import { createShape, getShapeUtils } from 'state/shape-utils'
-import { Corner, Data, Edge, Shape, ShapeType, ShapeUtility } from 'types'
-import { deepClone, deepCompareArrays, uniqueId, vec } from 'utils'
-import * as mockDocument from './__mocks__/document.json'
-
-type State = typeof _state
-
-export const rectangleId = 'e43559cb-6f41-4ae4-9c49-158ed1ad2f72'
-export const arrowId = 'fee77127-e779-4576-882b-b1bf7c7e132f'
-
-interface PointerOptions {
- id?: number
- x?: number
- y?: number
- shiftKey?: boolean
- altKey?: boolean
- ctrlKey?: boolean
-}
-
-class TestState {
- _state: State
- snapshot: Data
-
- constructor() {
- this._state = _state
- this.state.send('TOGGLED_TEST_MODE')
- this.snapshot = deepClone(this.state.data)
- this.reset()
- }
-
- /**
- * Get the underlying state-designer state.
- *
- * ### Example
- *
- *```ts
- * tt.state
- *```
- */
- get state(): State {
- return this._state
- }
-
- /**
- * Get the state's current data.
- *
- * ### Example
- *
- *```ts
- * tt.data
- *```
- */
- get data(): Readonly {
- return this.state.data
- }
-
- /* -------- Reimplemenation of State Methods -------- */
-
- /**
- * Send a message to the state.
- *
- * ### Example
- *
- *```ts
- * tt.send("MOVED_TO_FRONT")
- *```
- */
- send(eventName: string, payload?: unknown): TestState {
- this.state.send(eventName, payload)
- return this
- }
-
- /**
- * Check whether a state node is active. If multiple names are provided, then the method will return true only if ALL of the provided state nodes are active.
- *
- * ### Example
- *
- *```ts
- * tt.isIn("ready") // true
- * tt.isIn("ready", "selecting") // true
- * tt.isInAny("ready", "notReady") // false
- *```
- */
- isIn(...ids: string[]): boolean {
- return this.state.isIn(...ids)
- }
-
- /**
- * Check whether a state node is active. If multiple names are provided, then the method will return true if ANY of the provided state nodes are active.
- *
- * ### Example
- *
- *```ts
- * tt.isIn("ready") // true
- * tt.isIn("ready", "selecting") // true
- * tt.isInAny("ready", "notReady") // true
- *```
- */
- isInAny(...ids: string[]): boolean {
- return this.state.isInAny(...ids)
- }
-
- /**
- * Check whether the state can handle a certain event (and optionally payload). The method will return true if the event is handled by one or more currently active state nodes and if the event will pass its conditions (if present) in at least one of those handlers.
- *
- * ### Example
- *
- *```ts
- * example
- *```
- */
- can(eventName: string, payload?: unknown): boolean {
- return this.state.can(eventName, payload)
- }
-
- /* -------------------- Specific -------------------- */
-
- /**
- * Save a snapshot of the state's current data.
- *
- * ### Example
- *
- *```ts
- * tt.save()
- * tt.restore()
- *```
- */
- save(): TestState {
- this.snapshot = deepClone(this.data)
- return this
- }
-
- /**
- * Restore the state's saved data.
- *
- * ### Example
- *
- *```ts
- * tt.save()
- * tt.restore()
- *```
- */
- restore(): TestState {
- this.state.forceData(this.snapshot)
- return this
- }
-
- /**
- * Reset the test state.
- *
- * ### Example
- *
- *```ts
- * tt.reset()
- *```
- */
- reset(): TestState {
- this.state.reset()
- this.state
- .send('UNMOUNTED')
- .send('MOUNTED', { roomId: 'TESTING' })
- .send('MOUNTED_SHAPES')
- .send('LOADED_FROM_FILE', { json: JSON.stringify(mockDocument) })
-
- return this
- }
-
- /**
- * Reset the document state. Will remove all shapes and extra pages.
- *
- * ### Example
- *
- *```ts
- * tt.resetDocumentState()
- *```
- */
- resetDocumentState(): TestState {
- this.state.send('RESET_DOCUMENT_STATE').send('TOGGLED_TEST_MODE')
- return this
- }
-
- /**
- * Create a new shape on the current page. Optionally provide an id.
- *
- * ### Example
- *
- *```ts
- * tt.createShape({ type: ShapeType.Rectangle, point: [100, 100]})
- * tt.createShape({ type: ShapeType.Rectangle, point: [100, 100]}, "myId")
- *```
- */
- createShape(props: Partial, id = uniqueId()): TestState {
- const shape = createShape(props.type, props)
-
- getShapeUtils(shape)
- .setProperty(shape, 'id', id)
- .setProperty(shape, 'parentId', this.data.currentPageId)
-
- this.data.document.pages[this.data.currentPageId].shapes[shape.id] = shape
- return this
- }
-
- /**
- * Click a shape.
- *
- * ### Example
- *
- *```ts
- * tt.clickShape("myShapeId")
- *```
- */
- clickShape(id: string, options: PointerOptions = {}): TestState {
- const shape = tld.getShape(this.data, id)
- const [x, y] = shape ? vec.add(shape.point, [1, 1]) : [0, 0]
-
- this.state
- .send(
- 'POINTED_SHAPE',
- inputs.pointerDown(TestState.point({ x, y, ...options }), id)
- )
- .send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Start a click (but do not stop it).
- *
- * ### Example
- *
- *```ts
- * tt.startClick("myShapeId")
- *```
- */
- startClick(id: string, options: PointerOptions = {}): TestState {
- const shape = tld.getShape(this.data, id)
- const [x, y] = shape ? vec.add(shape.point, [1, 1]) : [0, 0]
-
- if (id === 'canvas') {
- this.state.send(
- 'POINTED_CANVAS',
- inputs.pointerDown(TestState.point({ x, y, ...options }), id)
- )
- return this
- }
-
- this.state.send(
- 'POINTED_SHAPE',
- inputs.pointerDown(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Stop a click (after starting it).
- *
- * ### Example
- *
- *```ts
- * tt.stopClick("myShapeId")
- *```
- */
- stopClick(id: string, options: PointerOptions = {}): TestState {
- const shape = tld.getShape(this.data, id)
- const [x, y] = shape ? vec.add(shape.point, [1, 1]) : [0, 0]
-
- this.state.send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Double click a shape.
- *
- * ### Example
- *
- *```ts
- * tt.clickShape("myShapeId")
- *```
- */
- doubleClickShape(id: string, options: PointerOptions = {}): TestState {
- const shape = tld.getShape(this.data, id)
- const [x, y] = shape ? vec.add(shape.point, [1, 1]) : [0, 0]
-
- this.state
- .send(
- 'DOUBLE_POINTED_SHAPE',
- inputs.pointerDown(TestState.point({ x, y, ...options }), id)
- )
- .send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Click the canvas.
- *
- * ### Example
- *
- *```ts
- * tt.clickCanvas("myShapeId")
- *```
- */
- clickCanvas(options: PointerOptions = {}): TestState {
- this.state
- .send(
- 'POINTED_CANVAS',
- inputs.pointerDown(TestState.point(options), 'canvas')
- )
- .send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point(options), 'canvas')
- )
-
- return this
- }
-
- /**
- * Click the background / body of the bounding box.
- *
- * ### Example
- *
- *```ts
- * tt.clickBounds()
- *```
- */
- clickBounds(options: PointerOptions = {}): TestState {
- this.state
- .send(
- 'POINTED_BOUNDS',
- inputs.pointerDown(TestState.point(options), 'bounds')
- )
- .send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point(options), 'bounds')
- )
-
- return this
- }
-
- /**
- * Start clicking bounds.
- *
- * ### Example
- *
- *```ts
- * tt.startClickingBounds()
- *```
- */
- startClickingBounds(options: PointerOptions = {}): TestState {
- this.state.send(
- 'POINTED_BOUNDS',
- inputs.pointerDown(TestState.point(options), 'bounds')
- )
-
- return this
- }
-
- /**
- * Stop clicking the bounding box.
- *
- * ### Example
- *
- *```ts
- * tt.stopClickingBounds()
- *```
- */
- stopClickingBounds(options: PointerOptions = {}): TestState {
- this.state.send(
- 'STOPPED_POINTING',
- inputs.pointerUp(TestState.point(options), 'bounds')
- )
-
- return this
- }
-
- /**
- * Start clicking a bounds handle.
- *
- * ### Example
- *
- *```ts
- * tt.startClickingBoundsHandle(Edge.Top)
- *```
- */
- startClickingBoundsHandle(
- handle: Corner | Edge | 'center',
- options: PointerOptions = {}
- ): TestState {
- this.state.send(
- 'POINTED_BOUNDS_HANDLE',
- inputs.pointerDown(TestState.point(options), handle)
- )
-
- return this
- }
-
- /**
- * Move the pointer to a new point, or to several points in order.
- *
- * ### Example
- *
- *```ts
- * tt.movePointerTo([100, 100])
- * tt.movePointerTo([100, 100], { shiftKey: true })
- * tt.movePointerTo([[100, 100], [150, 150], [200, 200]])
- *```
- */
- movePointerTo(
- to: number[] | number[][],
- options: Omit = {}
- ): TestState {
- if (Array.isArray(to[0])) {
- ;(to as number[][]).forEach(([x, y]) => {
- this.state.send(
- 'MOVED_POINTER',
- inputs.pointerMove(TestState.point({ x, y, ...options }))
- )
- })
- } else {
- const [x, y] = to as number[]
- this.state.send(
- 'MOVED_POINTER',
- inputs.pointerMove(TestState.point({ x, y, ...options }))
- )
- }
-
- return this
- }
-
- /**
- * Move the pointer by a delta.
- *
- * ### Example
- *
- *```ts
- * tt.movePointerBy([10,10])
- * tt.movePointerBy([10,10], { shiftKey: true })
- *```
- */
- movePointerBy(
- by: number[] | number[][],
- options: Omit = {}
- ): TestState {
- let pt = inputs.pointer?.point || [0, 0]
-
- if (Array.isArray(by[0])) {
- ;(by as number[][]).forEach((delta) => {
- pt = vec.add(pt, delta)
-
- this.state.send(
- 'MOVED_POINTER',
- inputs.pointerMove(
- TestState.point({ x: pt[0], y: pt[1], ...options })
- )
- )
- })
- } else {
- pt = vec.add(pt, by as number[])
-
- this.state.send(
- 'MOVED_POINTER',
- inputs.pointerMove(TestState.point({ x: pt[0], y: pt[1], ...options }))
- )
- }
-
- return this
- }
-
- /**
- * Move pointer over a shape. Will move the pointer to the top-left corner of the shape.
- *
- * ###
- * ```
- * tt.movePointerOverShape('myShapeId', [100, 100])
- * ```
- */
- movePointerOverShape(
- id: string,
- options: Omit = {}
- ): TestState {
- const shape = tld.getShape(this.state.data, id)
- const [x, y] = vec.add(shape.point, [1, 1])
-
- this.state.send(
- 'MOVED_OVER_SHAPE',
- inputs.pointerEnter(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Move the pointer over a group. Will move the pointer to the top-left corner of the group.
- *
- * ### Example
- *
- *```ts
- * tt.movePointerOverHandle('myGroupId')
- * tt.movePointerOverHandle('myGroupId', { shiftKey: true })
- *```
- */
- movePointerOverGroup(
- id: string,
- options: Omit = {}
- ): TestState {
- const shape = tld.getShape(this.state.data, id)
- const [x, y] = vec.add(shape.point, [1, 1])
-
- this.state.send(
- 'MOVED_OVER_GROUP',
- inputs.pointerEnter(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Move the pointer over a handle. Will move the pointer to the top-left corner of the handle.
- *
- * ### Example
- *
- *```ts
- * tt.movePointerOverHandle('bend')
- * tt.movePointerOverHandle('bend', { shiftKey: true })
- *```
- */
- movePointerOverHandle(
- id: string,
- options: Omit = {}
- ): TestState {
- const shape = tld.getShape(this.state.data, id)
- const handle = shape.handles?.[id]
- const [x, y] = vec.add(handle.point, [1, 1])
-
- this.state.send(
- 'MOVED_OVER_HANDLE',
- inputs.pointerEnter(TestState.point({ x, y, ...options }), id)
- )
-
- return this
- }
-
- /**
- * Select all shapes.
- *
- * ### Example
- *
- *```ts
- * tt.deselectAll()
- *```
- */
- selectAll(): TestState {
- this.state.send('SELECTED_ALL')
- return this
- }
-
- /**
- * Deselect all shapes.
- *
- * ### Example
- *
- *```ts
- * tt.deselectAll()
- *```
- */
- deselectAll(): TestState {
- this.state.send('DESELECTED_ALL')
- return this
- }
-
- /**
- * Delete the selected shapes.
- *
- * ### Example
- *
- *```ts
- * tt.pressDelete()
- *```
- */
- pressDelete(): TestState {
- this.state.send('DELETED')
- return this
- }
-
- /**
- * Undo.
- *
- * ### Example
- *
- *```ts
- * tt.undo()
- *```
- */
- undo(): TestState {
- this.state.send('UNDO')
- return this
- }
-
- /**
- * Redo.
- *
- * ### Example
- *
- *```ts
- * tt.redo()
- *```
- */
- redo(): TestState {
- this.state.send('REDO')
- return this
- }
-
- /* ---------------- Getting Data Out ---------------- */
-
- /**
- * Get a shape by its id. Note: the shape must be in the current page.
- *
- * ### Example
- *
- *```ts
- * tt.getShape("myShapeId")
- *```
- */
- getShape(id: string): T {
- return tld.getShape(this.data, id) as T
- }
-
- /**
- * Get the current selected ids.
- *
- * ### Example
- *
- *```ts
- * example
- *```
- */
- get selectedIds(): string[] {
- return tld.getSelectedIds(this.data)
- }
-
- /**
- * Get shapes for the current page.
- *
- * ### Example
- *
- *```ts
- * tt.getShapes()
- *```
- */
- getShapes(): Shape[] {
- return Object.values(
- this.data.document.pages[this.data.currentPageId].shapes
- )
- }
-
- /**
- * Get ids of the page's children sorted by their child index.
- *
- * ### Example
- *
- *```ts
- * tt.getSortedPageShapes()
- *```
- */
- getSortedPageShapeIds(): string[] {
- return this.getShapes()
- .sort((a, b) => a.childIndex - b.childIndex)
- .map((shape) => shape.id)
- }
-
- /**
- * Get the only selected shape. If more than one shape is selected, the test will fail.
- *
- * ### Example
- *
- *```ts
- * tt.getOnlySelectedShape()
- *```
- */
- getOnlySelectedShape(): Shape {
- const selectedShapes = tld.getSelectedShapes(this.data)
- return selectedShapes.length === 1 ? selectedShapes[0] : undefined
- }
-
- /**
- * Get whether the provided ids are the current selected ids. If the `strict` argument is `true`, then the result will be false if the state has selected ids in addition to those provided.
- *
- * ### Example
- *
- *```ts
- * tt.idsAreSelected(state.data, ['rectangleId', 'ellipseId'])
- * tt.idsAreSelected(state.data, ['rectangleId', 'ellipseId'], true)
- *```
- */
- idsAreSelected(ids: string[], strict = true): boolean {
- const selectedIds = tld.getSelectedIds(this.data)
- return (
- (strict ? selectedIds.length === ids.length : true) &&
- ids.every((id) => selectedIds.includes(id))
- )
- }
-
- /**
- * Get whether the shape with the provided id has the provided parent id.
- *
- * ### Example
- *
- *```ts
- * tt.hasParent('childId', 'parentId')
- *```
- */
- hasParent(childId: string, parentId: string): boolean {
- return tld.getShape(this.data, childId).parentId === parentId
- }
-
- /**
- * Assert that a shape has the provided type.
- *
- * ### Example
- *
- *```ts
- * tt.example
- *```
- */
- assertShapeType(shapeId: string, type: ShapeType): boolean {
- const shape = tld.getShape(this.data, shapeId)
- if (shape.type !== type) {
- throw new TypeError(
- `expected shape ${shapeId} to be of type ${type}, found ${shape?.type} instead`
- )
- }
- return true
- }
-
- /**
- * Assert that the provided shape has the provided props.
- *
- * ### Example
- *
- *```
- * tt.assertShapeProps(myShape, { point: [0,0], style: { color: ColorStyle.Blue } } )
- *```
- */
- assertShapeProps(
- shape: T,
- props: { [K in keyof Partial]: T[K] }
- ): boolean {
- for (const key in props) {
- let result: boolean
- const value = props[key]
-
- if (Array.isArray(value)) {
- result = deepCompareArrays(value, shape[key] as typeof value)
- } else if (typeof value === 'object') {
- const target = shape[key] as typeof value
- result =
- target &&
- Object.entries(value).every(([k, v]) => target[k] === props[key][v])
- } else {
- result = shape[key] === value
- }
-
- if (!result) {
- throw new TypeError(
- `expected shape ${shape.id} to have property ${key}: ${props[key]}, found ${key}: ${shape[key]} instead`
- )
- }
- }
-
- return true
- }
-
- /**
- * Get a shape and test it.
- *
- * ### Example
- *
- *```ts
- * tt.testShape("myShapeId", (myShape, utils) => expect(utils(myShape).getBounds()).toMatchSnapshot() )
- *```
- */
- testShape(
- id: string,
- fn: (shape: T, shapeUtils: ShapeUtility) => boolean
- ): boolean {
- const shape = this.getShape(id)
- return fn(shape, shape && getShapeUtils(shape))
- }
-
- /**
- * Get a fake PointerEvent.
- *
- * ### Example
- *
- *```ts
- * tt.point()
- * tt.point({ x: 0, y: 0})
- * tt.point({ x: 0, y: 0, shiftKey: true } )
- *```
- */
- static point(options: PointerOptions = {} as PointerOptions): PointerEvent {
- const {
- id = 1,
- x = 0,
- y = 0,
- shiftKey = false,
- altKey = false,
- ctrlKey = false,
- } = options
-
- return {
- shiftKey,
- altKey,
- ctrlKey,
- pointerId: id,
- clientX: x,
- clientY: y,
- } as any
- }
-}
-
-export default TestState
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
deleted file mode 100644
index b86a64d21..000000000
--- a/__tests__/tools.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import TestState from './test-utils'
-
-const TOOLS = [
- 'draw',
- 'rectangle',
- 'ellipse',
- 'arrow',
- 'text',
- 'line',
- 'ray',
- 'dot',
-]
-
-describe('when selecting tools', () => {
- const tt = new TestState()
-
- TOOLS.forEach((tool) => {
- it(`selects ${tool} tool`, () => {
- tt.reset().send(`SELECTED_${tool.toUpperCase()}_TOOL`)
-
- expect(tt.data.activeTool).toBe(tool)
- expect(tt.state.isIn(tool)).toBe(true)
- })
-
- TOOLS.forEach((otherTool) => {
- if (otherTool === tool) return
-
- it(`selects ${tool} tool from ${otherTool} tool`, () => {
- tt.reset()
- .send(`SELECTED_${tool.toUpperCase()}_TOOL`)
- .send(`SELECTED_${otherTool.toUpperCase()}_TOOL`)
-
- expect(tt.data.activeTool).toBe(otherTool)
- expect(tt.state.isIn(otherTool)).toBe(true)
- })
- })
- })
-})
diff --git a/babel.config.js b/babel.config.js
deleted file mode 100644
index bc6c51008..000000000
--- a/babel.config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- presets: ['next/babel'],
-}
diff --git a/components/canvas/bounds/bounding-box.tsx b/components/canvas/bounds/bounding-box.tsx
deleted file mode 100644
index 15c068e08..000000000
--- a/components/canvas/bounds/bounding-box.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-import * as React from 'react'
-import { Edge, Corner } from 'types'
-import { useSelector } from 'state'
-import { getBoundsCenter, isMobile } from 'utils'
-import tld from 'utils/tld'
-import CenterHandle from './center-handle'
-import CornerHandle from './corner-handle'
-import EdgeHandle from './edge-handle'
-import RotateHandle from './rotate-handle'
-
-export default function Bounds(): JSX.Element {
- const isBrushing = useSelector((s) => s.isIn('brushSelecting'))
-
- const shouldDisplay = useSelector((s) =>
- s.isInAny('selecting', 'selectPinching')
- )
-
- const zoom = useSelector((s) => tld.getCurrentCamera(s.data).zoom)
-
- const bounds = useSelector((s) => s.values.selectedBounds)
-
- const rotation = useSelector((s) => s.values.selectedRotation)
-
- const isAllLocked = useSelector((s) => {
- const page = tld.getPage(s.data)
- return s.values.selectedIds.every((id) => page.shapes[id]?.isLocked)
- })
-
- const isSingleHandles = useSelector((s) => {
- const page = tld.getPage(s.data)
- return (
- s.values.selectedIds.length === 1 &&
- page.shapes[s.values.selectedIds[0]]?.handles !== undefined
- )
- })
-
- if (!bounds) return null
-
- if (!shouldDisplay) return null
-
- if (isSingleHandles) return null
-
- const size = (isMobile() ? 10 : 8) / zoom // Touch target size
- const center = getBoundsCenter(bounds)
-
- return (
-
-
- {!isAllLocked && (
- <>
-
-
-
-
-
-
-
-
-
- >
- )}
-
- )
-}
diff --git a/components/canvas/bounds/bounds-bg.tsx b/components/canvas/bounds/bounds-bg.tsx
deleted file mode 100644
index 64b497370..000000000
--- a/components/canvas/bounds/bounds-bg.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { useRef } from 'react'
-import state, { useSelector } from 'state'
-import inputs from 'state/inputs'
-import styled from 'styles'
-import tld from 'utils/tld'
-
-function handlePointerDown(e: React.PointerEvent) {
- if (!inputs.canAccept(e.pointerId)) return
- e.stopPropagation()
- e.currentTarget.setPointerCapture(e.pointerId)
- const info = inputs.pointerDown(e, 'bounds')
-
- if (e.button === 0) {
- state.send('POINTED_BOUNDS', info)
- } else if (e.button === 2) {
- state.send('RIGHT_POINTED', info)
- }
-}
-
-function handlePointerUp(e: React.PointerEvent) {
- if (!inputs.canAccept(e.pointerId)) return
- e.stopPropagation()
- e.currentTarget.releasePointerCapture(e.pointerId)
- state.send('STOPPED_POINTING', inputs.pointerUp(e, 'bounds'))
-}
-
-export default function BoundsBg(): JSX.Element {
- const rBounds = useRef(null)
-
- const bounds = useSelector((state) => state.values.selectedBounds)
-
- const shouldDisplay = useSelector((s) =>
- s.isInAny('selecting', 'selectPinching')
- )
-
- const rotation = useSelector((s) => s.values.selectedRotation)
-
- const isAllHandles = useSelector((s) => {
- const selectedIds = s.values.selectedIds
-
- if (selectedIds.length === 1) {
- const page = tld.getPage(s.data)
- const selected = selectedIds[0]
-
- return (
- selectedIds.length === 1 && page.shapes[selected]?.handles !== undefined
- )
- }
- })
-
- if (isAllHandles) return null
- if (!bounds) return null
- if (!shouldDisplay) return null
-
- const { width, height } = bounds
-
- return (
-
- )
-}
-
-const StyledBoundsBg = styled('rect', {
- fill: '$boundsBg',
-})
diff --git a/components/canvas/bounds/center-handle.tsx b/components/canvas/bounds/center-handle.tsx
deleted file mode 100644
index 2ab9fa110..000000000
--- a/components/canvas/bounds/center-handle.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import styled from 'styles'
-import { Bounds } from 'types'
-
-export default function CenterHandle({
- bounds,
- isLocked,
-}: {
- bounds: Bounds
- isLocked: boolean
-}): JSX.Element {
- return (
-
- )
-}
-
-const StyledBounds = styled('rect', {
- fill: 'none',
- stroke: '$bounds',
- zStrokeWidth: 1.5,
-
- variants: {
- isLocked: {
- true: {
- zStrokeWidth: 1.5,
- zDash: 2,
- },
- },
- },
-})
diff --git a/components/canvas/bounds/corner-handle.tsx b/components/canvas/bounds/corner-handle.tsx
deleted file mode 100644
index b77fbe547..000000000
--- a/components/canvas/bounds/corner-handle.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import useBoundsEvents from 'hooks/useBoundsEvents'
-import styled from 'styles'
-import { Corner, Bounds } from 'types'
-
-export default function CornerHandle({
- size,
- corner,
- bounds,
-}: {
- size: number
- bounds: Bounds
- corner: Corner
-}): JSX.Element {
- const events = useBoundsEvents(corner)
-
- const isTop = corner === Corner.TopLeft || corner === Corner.TopRight
- const isLeft = corner === Corner.TopLeft || corner === Corner.BottomLeft
-
- return (
-
-
-
-
- )
-}
-
-const StyledCorner = styled('rect', {
- stroke: 'none',
- fill: 'transparent',
- variants: {
- corner: {
- [Corner.TopLeft]: { cursor: 'nwse-resize' },
- [Corner.TopRight]: { cursor: 'nesw-resize' },
- [Corner.BottomRight]: { cursor: 'nwse-resize' },
- [Corner.BottomLeft]: { cursor: 'nesw-resize' },
- },
- },
-})
-
-const StyledCornerInner = styled('rect', {
- stroke: '$bounds',
- fill: '$canvas',
- zStrokeWidth: 1.5,
-})
diff --git a/components/canvas/bounds/edge-handle.tsx b/components/canvas/bounds/edge-handle.tsx
deleted file mode 100644
index 583dd1ff3..000000000
--- a/components/canvas/bounds/edge-handle.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import useBoundsEvents from 'hooks/useBoundsEvents'
-import styled from 'styles'
-import { Edge, Bounds } from 'types'
-
-export default function EdgeHandle({
- size,
- bounds,
- edge,
-}: {
- size: number
- bounds: Bounds
- edge: Edge
-}): JSX.Element {
- const events = useBoundsEvents(edge)
-
- const isHorizontal = edge === Edge.Top || edge === Edge.Bottom
- const isFarEdge = edge === Edge.Right || edge === Edge.Bottom
-
- const { height, width } = bounds
-
- return (
-
- )
-}
-
-const StyledEdge = styled('rect', {
- stroke: 'none',
- fill: 'none',
- variants: {
- edge: {
- [Edge.Top]: { cursor: 'ns-resize' },
- [Edge.Right]: { cursor: 'ew-resize' },
- [Edge.Bottom]: { cursor: 'ns-resize' },
- [Edge.Left]: { cursor: 'ew-resize' },
- },
- },
-})
diff --git a/components/canvas/bounds/handles.tsx b/components/canvas/bounds/handles.tsx
deleted file mode 100644
index ce810cfea..000000000
--- a/components/canvas/bounds/handles.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import useHandleEvents from 'hooks/useHandleEvents'
-import { getShapeUtils } from 'state/shape-utils'
-import { useRef } from 'react'
-import { useSelector } from 'state'
-import styled from 'styles'
-import tld from 'utils/tld'
-import vec from 'utils/vec'
-
-export default function Handles(): JSX.Element {
- const shape = useSelector(
- (s) =>
- s.values.selectedIds.length === 1 &&
- tld.getPage(s.data).shapes[s.values.selectedIds[0]]
- )
-
- const isSelecting = useSelector((s) =>
- s.isInAny('notPointing', 'pinching', 'translatingHandles')
- )
-
- if (!shape || !shape.handles || !isSelecting) return null
-
- const center = getShapeUtils(shape).getCenter(shape)
-
- return (
-
- {Object.values(shape.handles).map((handle) => (
-
- ))}
-
- )
-}
-
-function Handle({ id, point }: { id: string; point: number[] }) {
- const rGroup = useRef(null)
- const events = useHandleEvents(id, rGroup)
-
- return (
-
-
-
-
- )
-}
-
-const StyledGroup = styled('g', {
- '&:hover': {
- cursor: 'pointer',
- },
- '&:active': {
- cursor: 'none',
- },
-})
-
-const HandleCircleOuter = styled('circle', {
- fill: 'transparent',
- stroke: 'none',
- opacity: 0.2,
- pointerEvents: 'all',
- cursor: 'pointer',
- transform: 'scale(var(--scale))',
- '&:hover': {
- fill: '$selected',
- '& > *': {
- stroke: '$selected',
- },
- },
- '&:active': {
- fill: '$selected',
- },
-})
diff --git a/components/canvas/bounds/rotate-handle.tsx b/components/canvas/bounds/rotate-handle.tsx
deleted file mode 100644
index 5f86f1dfa..000000000
--- a/components/canvas/bounds/rotate-handle.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import useHandleEvents from 'hooks/useBoundsEvents'
-import styled from 'styles'
-import { Bounds } from 'types'
-
-export default function Rotate({
- bounds,
- size,
-}: {
- bounds: Bounds
- size: number
-}): JSX.Element {
- const events = useHandleEvents('rotate')
-
- return (
-
-
-
-
- )
-}
-
-const StyledRotateHandle = styled('circle', {
- stroke: '$bounds',
- fill: '$canvas',
- zStrokeWidth: 1.5,
- cursor: 'grab',
-})
diff --git a/components/canvas/brush.tsx b/components/canvas/brush.tsx
deleted file mode 100644
index 009e4a658..000000000
--- a/components/canvas/brush.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import { useSelector } from 'state'
-import styled from 'styles'
-
-export default function Brush(): JSX.Element {
- const brush = useSelector(({ data }) => data.brush)
-
- if (!brush) return null
-
- return (
-
- )
-}
-
-const BrushRect = styled('rect', {
- fill: '$brushFill',
- stroke: '$brushStroke',
- zStrokeWidth: 1,
-})
diff --git a/components/canvas/canvas.tsx b/components/canvas/canvas.tsx
deleted file mode 100644
index 5f54df786..000000000
--- a/components/canvas/canvas.tsx
+++ /dev/null
@@ -1,99 +0,0 @@
-import * as Sentry from '@sentry/node'
-import React, { useEffect, useRef } from 'react'
-
-import { ErrorBoundary } from 'react-error-boundary'
-import state, { useSelector } from 'state'
-import styled from 'styles'
-import useCamera from 'hooks/useCamera'
-import useCanvasEvents from 'hooks/useCanvasEvents'
-import useZoomEvents from 'hooks/useZoomEvents'
-import Bounds from './bounds/bounding-box'
-import BoundsBg from './bounds/bounds-bg'
-import Handles from './bounds/handles'
-import ContextMenu from './context-menu/context-menu'
-import Coop from './coop/coop'
-import Brush from './brush'
-import Defs from './defs'
-import Page from './page'
-import useSafariFocusOutFix from 'hooks/useSafariFocusOutFix'
-
-function resetError() {
- null
-}
-
-export default function Canvas(): JSX.Element {
- const rCanvas = useRef(null)
- const rGroup = useRef(null)
-
- useCamera(rGroup)
-
- useZoomEvents()
-
- useSafariFocusOutFix()
-
- const events = useCanvasEvents(rCanvas)
-
- const isSettingCamera = useSelector((s) => s.isIn('settingCamera'))
- const isReady = useSelector((s) => s.isIn('ready'))
-
- useEffect(() => {
- if (isSettingCamera) {
- state.send('MOUNTED_SHAPES')
- }
- }, [isSettingCamera])
-
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- )
-}
-
-const MainSVG = styled('svg', {
- position: 'fixed',
- overflow: 'hidden',
- top: 0,
- left: 0,
- width: '100%',
- height: '100%',
- touchAction: 'none',
- zIndex: 100,
- pointerEvents: 'all',
- backgroundColor: '$canvas',
- borderTop: '1px solid $border',
- borderBottom: '1px solid $border',
-
- '& *': {
- userSelect: 'none',
- },
-})
-
-function ErrorFallback({ error, resetErrorBoundary }) {
- React.useEffect(() => {
- const copy =
- 'Sorry, something went wrong. Press Ok to reset the document, or press cancel to continue and see if it resolves itself.'
-
- console.error(error)
-
- Sentry.captureException(error)
-
- if (window.confirm(copy)) {
- state.send('RESET_DOCUMENT_STATE')
- resetErrorBoundary()
- }
- }, [])
-
- return
-}
diff --git a/components/canvas/context-menu/context-menu.tsx b/components/canvas/context-menu/context-menu.tsx
deleted file mode 100644
index 7fec2fcd5..000000000
--- a/components/canvas/context-menu/context-menu.tsx
+++ /dev/null
@@ -1,368 +0,0 @@
-import * as _ContextMenu from '@radix-ui/react-context-menu'
-import styled from 'styles'
-import {
- IconWrapper,
- breakpoints,
- RowButton,
- ContextMenuArrow,
- ContextMenuDivider,
- ContextMenuButton,
- ContextMenuSubMenu,
- ContextMenuIconButton,
- ContextMenuRoot,
- MenuContent,
-} from 'components/shared'
-import { commandKey, deepCompareArrays } from 'utils'
-import state, { useSelector } from 'state'
-import {
- AlignType,
- DistributeType,
- MoveType,
- ShapeType,
- StretchType,
-} from 'types'
-import tld from 'utils/tld'
-import React, { useRef } from 'react'
-import {
- ChevronRightIcon,
- AlignBottomIcon,
- AlignCenterHorizontallyIcon,
- AlignCenterVerticallyIcon,
- AlignLeftIcon,
- AlignRightIcon,
- AlignTopIcon,
- SpaceEvenlyHorizontallyIcon,
- SpaceEvenlyVerticallyIcon,
- StretchHorizontallyIcon,
- StretchVerticallyIcon,
-} from '@radix-ui/react-icons'
-import { Kbd } from 'components/shared'
-
-function alignTop() {
- state.send('ALIGNED', { type: AlignType.Top })
-}
-
-function alignCenterVertical() {
- state.send('ALIGNED', { type: AlignType.CenterVertical })
-}
-
-function alignBottom() {
- state.send('ALIGNED', { type: AlignType.Bottom })
-}
-
-function stretchVertically() {
- state.send('STRETCHED', { type: StretchType.Vertical })
-}
-
-function distributeVertically() {
- state.send('DISTRIBUTED', { type: DistributeType.Vertical })
-}
-
-function alignLeft() {
- state.send('ALIGNED', { type: AlignType.Left })
-}
-
-function alignCenterHorizontal() {
- state.send('ALIGNED', { type: AlignType.CenterHorizontal })
-}
-
-function alignRight() {
- state.send('ALIGNED', { type: AlignType.Right })
-}
-
-function stretchHorizontally() {
- state.send('STRETCHED', { type: StretchType.Horizontal })
-}
-
-function distributeHorizontally() {
- state.send('DISTRIBUTED', { type: DistributeType.Horizontal })
-}
-
-export default function ContextMenu({
- children,
-}: {
- children: React.ReactNode
-}): JSX.Element {
- const selectedShapeIds = useSelector(
- (s) => s.values.selectedIds,
- deepCompareArrays
- )
-
- const rContent = useRef(null)
-
- const hasGroupSelected = useSelector((s) =>
- selectedShapeIds.some(
- (id) => tld.getShape(s.data, id)?.type === ShapeType.Group
- )
- )
-
- const hasTwoOrMore = selectedShapeIds.length > 1
- const hasThreeOrMore = selectedShapeIds.length > 2
-
- return (
-
- <_ContextMenu.Trigger>{children}
-
- {selectedShapeIds.length ? (
- <>
- {/* state.send('COPIED')}>
- Copy
-
- {commandKey()}
- C
-
-
- state.send('CUT')}>
- Cut
-
- {commandKey()}
- X
-
-
- */}
- state.send('DUPLICATED')}>
- Duplicate
-
- {commandKey()}
- D
-
-
-
- {hasGroupSelected ||
- (hasTwoOrMore && (
- <>
- {hasGroupSelected && (
- state.send('UNGROUPED')}>
- Ungroup
-
- {commandKey()}
- ⇧
- G
-
-
- )}
- {hasTwoOrMore && (
- state.send('GROUPED')}>
- Group
-
- {commandKey()}
- G
-
-
- )}
- >
- ))}
-
-
- state.send('MOVED', {
- type: MoveType.ToFront,
- })
- }
- >
- To Front
-
- {commandKey()}
- ⇧
- ]
-
-
-
-
- state.send('MOVED', {
- type: MoveType.Forward,
- })
- }
- >
- Forward
-
- {commandKey()}
- ]
-
-
-
- state.send('MOVED', {
- type: MoveType.Backward,
- })
- }
- >
- Backward
-
- {commandKey()}
- [
-
-
-
- state.send('MOVED', {
- type: MoveType.ToBack,
- })
- }
- >
- To Back
-
- {commandKey()}
- ⇧
- [
-
-
-
- {hasTwoOrMore && (
-
- )}
-
- state.send('COPIED_TO_SVG')}>
- Copy to SVG
-
- {commandKey()}
- ⇧
- C
-
-
-
- state.send('DELETED')}>
- Delete
-
- ⌫
-
-
- >
- ) : (
- <>
- state.send('UNDO')}>
- Undo
-
- {commandKey()}
- Z
-
-
- state.send('REDO')}>
- Redo
-
- {commandKey()}
- ⇧
- Z
-
-
- >
- )}
-
-
- )
-}
-
-function AlignDistributeSubMenu({
- hasThreeOrMore,
-}: {
- hasTwoOrMore: boolean
- hasThreeOrMore: boolean
-}) {
- return (
-
- <_ContextMenu.TriggerItem as={RowButton} bp={breakpoints}>
- Align / Distribute
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {hasThreeOrMore && (
-
-
-
- )}
-
-
-
-
-
-
-
-
-
-
-
-
-
- {hasThreeOrMore && (
-
-
-
- )}
-
-
-
- )
-}
-
-const StyledGrid = styled(MenuContent, {
- display: 'grid',
- variants: {
- selectedStyle: {
- threeOrMore: {
- gridTemplateColumns: 'repeat(5, auto)',
- },
- twoOrMore: {
- gridTemplateColumns: 'repeat(4, auto)',
- },
- },
- },
-})
-
-function MoveToPageMenu() {
- const documentPages = useSelector((s) => s.data.document.pages)
- const currentPageId = useSelector((s) => s.data.currentPageId)
-
- if (!documentPages[currentPageId]) return null
-
- const sorted = Object.values(documentPages)
- .sort((a, b) => a.childIndex - b.childIndex)
- .filter((a) => a.id !== currentPageId)
-
- if (sorted.length === 0) return null
-
- return (
-
-
- Move To Page
-
-
-
-
-
- {sorted.map(({ id, name }) => (
- state.send('MOVED_TO_PAGE', { id })}
- >
- {name}
-
- ))}
-
-
-
- )
-}
diff --git a/components/canvas/coop/coop.tsx b/components/canvas/coop/coop.tsx
deleted file mode 100644
index 3d576889b..000000000
--- a/components/canvas/coop/coop.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import Cursor from './cursor'
-import { useCoopSelector } from 'state/coop/coop-state'
-import { useSelector } from 'state'
-
-export default function Presence(): JSX.Element {
- const others = useCoopSelector((s) => s.data.others)
- const currentPageId = useSelector((s) => s.data.currentPageId)
-
- if (!others) return null
-
- return (
- <>
- {Object.values(others)
- .filter(({ presence }) => presence?.pageId === currentPageId)
- .map(({ connectionId, presence }) => {
- return (
-
- )
- })}
- >
- )
-}
diff --git a/components/canvas/coop/cursor.tsx b/components/canvas/coop/cursor.tsx
deleted file mode 100644
index 191bbe65a..000000000
--- a/components/canvas/coop/cursor.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import React from 'react'
-import styled from 'styles'
-import { motion } from 'framer-motion'
-
-export default function Cursor({
- color = 'dodgerblue',
- duration = 0,
- bufferedXs = [],
- bufferedYs = [],
- times = [],
-}: {
- color: string
- duration: number
- bufferedXs: number[]
- bufferedYs: number[]
- times: number[]
-}): JSX.Element {
- return (
-
-
-
-
-
-
- )
-}
-
-const StyledCursor = styled(motion.g, {
- position: 'absolute',
- zIndex: 1000,
- top: 0,
- left: 0,
-})
diff --git a/components/canvas/defs.tsx b/components/canvas/defs.tsx
deleted file mode 100644
index b26154bed..000000000
--- a/components/canvas/defs.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import React from 'react'
-import { useSelector } from 'state'
-import tld from 'utils/tld'
-import { DotCircle, Handle } from './misc'
-import styled from 'styles'
-
-export default function Defs(): JSX.Element {
- return (
-
-
-
-
-
-
- )
-}
-
-function ExpandDef() {
- const zoom = useSelector((s) => tld.getCurrentCamera(s.data).zoom)
- return (
-
-
-
- )
-}
-
-function HoverDef() {
- return (
-
-
-
- )
-}
-
-const StyledShadow = styled('feDropShadow', {
- floodColor: '$selected',
-})
diff --git a/components/canvas/hovered-shape.tsx b/components/canvas/hovered-shape.tsx
deleted file mode 100644
index 08969d8a3..000000000
--- a/components/canvas/hovered-shape.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import { memo } from 'react'
-import tld from 'utils/tld'
-import { getShapeUtils } from 'state/shape-utils'
-import vec from 'utils/vec'
-import styled from 'styles'
-import { useSelector } from 'state'
-import { getShapeStyle } from 'state/shape-styles'
-
-function HoveredShape({ id }: { id: string }) {
- const transform = useSelector((s) => {
- const shape = tld.getShape(s.data, id)
- const center = getShapeUtils(shape).getCenter(shape)
- const rotation = shape.rotation * (180 / Math.PI)
- const parentPoint = tld.getShape(s.data, shape.parentId)?.point || [0, 0]
-
- return `
- translate(${vec.neg(parentPoint)})
- rotate(${rotation}, ${center})
- translate(${shape.point})
- `
- })
-
- const strokeWidth = useSelector((s) => {
- const shape = tld.getShape(s.data, id)
- const style = getShapeStyle(shape.style, s.data.settings.isDarkMode)
- return +style.strokeWidth
- })
-
- return (
-
- )
-}
-
-const StyledHoverShape = styled('use', {
- stroke: '$selected',
- opacity: 0.1,
-})
-
-export default memo(HoveredShape)
diff --git a/components/canvas/misc.tsx b/components/canvas/misc.tsx
deleted file mode 100644
index 5c0b43591..000000000
--- a/components/canvas/misc.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import styled from 'styles'
-
-export const DotCircle = styled('circle', {
- transform: 'scale(var(--scale))',
- fill: '$canvas',
- stroke: '$text',
- strokeWidth: '2',
-})
-
-export const Handle = styled('circle', {
- transform: 'scale(var(--scale))',
- fill: '$canvas',
- stroke: '$selected',
- strokeWidth: '2',
-})
-
-export const ThinLine = styled('line', {
- zStrokeWidth: 1,
-})
diff --git a/components/canvas/page.tsx b/components/canvas/page.tsx
deleted file mode 100644
index 70dd6bbdc..000000000
--- a/components/canvas/page.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import { useSelector } from 'state'
-import { ShapeTreeNode } from 'types'
-import ShapeComponent from './shape'
-
-export default function Page(): JSX.Element {
- const shapesToRender = useSelector((s) => s.values.shapesToRender)
-
- const allowHovers = useSelector((s) =>
- s.isInAny('selecting', 'text', 'editingShape')
- )
-
- return (
- <>
- {shapesToRender.map((node) => (
-
- ))}
- >
- )
-}
-
-interface ShapeNodeProps {
- node: ShapeTreeNode
- allowHovers: boolean
-}
-
-const ShapeNode = ({
- node: {
- shape,
- children,
- isEditing,
- isHovered,
- isDarkMode,
- isSelected,
- isCurrentParent,
- },
- allowHovers,
-}: ShapeNodeProps) => {
- return (
- <>
-
- {children.map((childNode) => (
-
- ))}
- >
- )
-}
diff --git a/components/canvas/shape.tsx b/components/canvas/shape.tsx
deleted file mode 100644
index b70845771..000000000
--- a/components/canvas/shape.tsx
+++ /dev/null
@@ -1,149 +0,0 @@
-import useShapeEvents from 'hooks/useShapeEvents'
-import { Shape as _Shape, ShapeType, TextShape } from 'types'
-import { getShapeUtils } from 'state/shape-utils'
-import { shallowEqual } from 'utils'
-import { memo, useRef } from 'react'
-import styled from 'styles'
-
-interface ShapeProps {
- shape: _Shape
- isEditing: boolean
- isHovered: boolean
- isSelected: boolean
- isDarkMode: boolean
- isCurrentParent: boolean
-}
-
-const Shape = memo(
- ({
- shape,
- isEditing,
- isHovered,
- isSelected,
- isDarkMode,
- isCurrentParent,
- }: ShapeProps) => {
- const rGroup = useRef(null)
- const events = useShapeEvents(shape.id, isCurrentParent, rGroup)
- const utils = getShapeUtils(shape)
-
- const center = utils.getCenter(shape)
- const rotation = shape.rotation * (180 / Math.PI)
- const transform = `rotate(${rotation}, ${center}) translate(${shape.point})`
-
- return (
-
- {isEditing && shape.type === ShapeType.Text ? (
-
- ) : (
-
- )}
-
- )
- },
- shallowEqual
-)
-
-export default Shape
-
-interface RenderedShapeProps {
- shape: _Shape
- isEditing: boolean
- isHovered: boolean
- isSelected: boolean
- isDarkMode: boolean
- isCurrentParent: boolean
-}
-
-const RenderedShape = memo(
- function RenderedShape({
- shape,
- isEditing,
- isHovered,
- isSelected,
- isDarkMode,
- isCurrentParent,
- }: RenderedShapeProps) {
- return getShapeUtils(shape).render(shape, {
- isEditing,
- isHovered,
- isSelected,
- isDarkMode,
- isCurrentParent,
- })
- },
- (prev, next) => {
- if (
- prev.isEditing !== next.isEditing ||
- prev.isHovered !== next.isHovered ||
- prev.isSelected !== next.isSelected ||
- prev.isDarkMode !== next.isDarkMode ||
- prev.isCurrentParent !== next.isCurrentParent
- ) {
- return false
- }
-
- if (next.shape !== prev.shape) {
- return !getShapeUtils(next.shape).shouldRender(next.shape, prev.shape)
- }
-
- return true
- }
-)
-
-function EditingTextShape({
- shape,
- isDarkMode,
-}: {
- shape: TextShape
- isDarkMode: boolean
-}) {
- const ref = useRef(null)
-
- return getShapeUtils(shape).render(shape, {
- ref,
- isEditing: true,
- isHovered: false,
- isSelected: false,
- isDarkMode,
- isCurrentParent: false,
- })
-}
-
-const ShapeGroup = styled('g', {
- outline: 'none',
-
- '& > *[data-shy=true]': {
- opacity: 0,
- },
-
- '&:hover': {
- '& > *[data-shy=true]': {
- opacity: 1,
- },
- },
-
- variants: {
- isCurrentParent: {
- true: {
- '& > *[data-shy=true]': {
- opacity: 1,
- },
- },
- },
- },
-})
diff --git a/components/code-panel/code-docs.tsx b/components/code-panel/code-docs.tsx
deleted file mode 100644
index ca148816c..000000000
--- a/components/code-panel/code-docs.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-import styled from 'styles'
-import ReactMarkdown from 'react-markdown'
-import docs from './docs-content'
-
-export default function CodeDocs({
- isHidden,
-}: {
- isHidden: boolean
-}): JSX.Element {
- return (
-
- {docs.content}
-
- )
-}
-
-const StyledDocs = styled('div', {
- position: 'absolute',
- backgroundColor: '$panel',
- top: 0,
- left: 0,
- width: '100%',
- height: '100%',
- padding: 16,
- overflowY: 'scroll',
- userSelect: 'none',
- paddingBottom: 64,
- fontFamily: '$body',
- fontWeight: 500,
-
- variants: {
- isHidden: {
- true: {
- visibility: 'hidden',
- },
- false: {
- visibility: 'visible',
- },
- },
- },
-
- '& p': {
- fontSize: '$3',
- lineHeight: '1.3',
- },
-
- '& ol, ul': {
- fontSize: '$3',
- lineHeight: '1.3',
- marginTop: 16,
- marginBottom: 16,
- },
-
- '& li': {
- fontSize: '$3',
- lineHeight: '1.5',
- },
-
- '& code': {
- font: '$mono',
- },
-
- '& hr': {
- margin: '32px 0',
- borderColor: '$muted',
- },
-
- '& h2': {
- margin: '40px 0px 24px 0',
- },
-
- '& h3': {
- fontSize: 20,
- margin: '48px 0px 32px 0px',
- },
-
- '& h3 > code': {
- fontWeight: 600,
- font: '$mono',
- },
-
- '& h4': {
- margin: '32px 0px 0px 0px',
- },
-
- '& h4 > code': {
- font: '$mono',
- fontSize: 16,
- userSelect: 'all',
- },
-
- '& h4 > code > i': {
- fontSize: 14,
- color: '$muted',
- },
-
- '& pre': {
- border: '1px solid $brushStroke',
- font: '$mono',
- fontWeight: 420,
- lineHeight: 1.5,
- padding: 16,
- borderRadius: 4,
- userSelect: 'all',
- margin: '24px 0',
- },
-
- '& p > code, blockquote > code': {
- padding: '2px 4px',
- borderRadius: 2,
- color: '$text',
- backgroundColor: '$codeHl',
- },
-
- '& blockquote': {
- backgroundColor: '$overlay',
- padding: 12,
- margin: '20px 0',
- borderRadius: 8,
- },
-})
diff --git a/components/code-panel/code-editor.tsx b/components/code-panel/code-editor.tsx
deleted file mode 100644
index 92d21ccf9..000000000
--- a/components/code-panel/code-editor.tsx
+++ /dev/null
@@ -1,248 +0,0 @@
-import Editor, { Monaco } from '@monaco-editor/react'
-import { useTheme } from 'next-themes'
-import libImport from './es5-lib'
-import typesImport from './types-import'
-import React, { useCallback, useEffect, useRef } from 'react'
-import styled from 'styles'
-import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
-import { getFormattedCode } from 'utils/code'
-import { metaKey } from 'utils'
-
-export type IMonaco = typeof monaco
-
-export type IMonacoEditor = monaco.editor.IStandaloneCodeEditor
-
-const modifierKeys = ['Escape', 'Meta', 'Control', 'Shift', 'Option', 'Alt']
-
-interface Props {
- value: string
- error: { line: number; column: number }
- fontSize: number
- monacoRef?: React.MutableRefObject
- editorRef?: React.MutableRefObject
- readOnly?: boolean
- onMount?: (value: string, editor: IMonacoEditor) => void
- onUnmount?: (editor: IMonacoEditor) => void
- onChange?: (value: string, editor: IMonacoEditor) => void
- onSave?: (value: string, editor: IMonacoEditor) => void
- onError?: (error: Error, line: number, col: number) => void
- onKey?: () => void
-}
-
-export default function CodeEditor({
- editorRef,
- monacoRef,
- fontSize,
- value,
- error,
- readOnly,
- onChange,
- onSave,
- onKey,
-}: Props): JSX.Element {
- const { theme } = useTheme()
-
- const rEditor = useRef(null)
- const rMonaco = useRef(null)
-
- const handleBeforeMount = useCallback((monaco: Monaco) => {
- if (monacoRef) {
- monacoRef.current = monaco
- }
-
- rMonaco.current = monaco
-
- // Set the compiler options.
-
- monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
- allowJs: true,
- checkJs: true,
- strict: true,
- noLib: true,
- lib: ['es6'],
- target: monaco.languages.typescript.ScriptTarget.ES2016,
- allowNonTsExtensions: true,
- })
-
- // Sync the intellisense on load.
-
- monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true)
-
- // Run both semantic and syntax validation.
-
- monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
- noSemanticValidation: false,
- noSyntaxValidation: false,
- })
-
- // Add custom types
-
- monaco.languages.typescript.typescriptDefaults.addExtraLib(
- typesImport.content
- )
-
- // Add es5 library types
-
- monaco.languages.typescript.typescriptDefaults.addExtraLib(
- libImport.content
- )
-
- // Use prettier as a formatter
-
- monaco.languages.registerDocumentFormattingEditProvider('typescript', {
- async provideDocumentFormattingEdits(model) {
- try {
- const text = getFormattedCode(model.getValue())
-
- return [
- {
- range: model.getFullModelRange(),
- text,
- },
- ]
- } catch (e) {
- return [
- {
- range: model.getFullModelRange(),
- text: model.getValue(),
- },
- ]
- }
- },
- })
- }, [])
-
- const handleMount = useCallback((editor: IMonacoEditor) => {
- if (editorRef) {
- editorRef.current = editor
- }
- rEditor.current = editor
-
- editor.updateOptions({
- fontSize,
- fontFamily: "'Recursive Mono', monospace",
- wordBasedSuggestions: false,
- minimap: { enabled: false },
- lightbulb: {
- enabled: false,
- },
- readOnly,
- })
- }, [])
-
- const handleChange = useCallback((code: string | undefined) => {
- onChange(code, rEditor.current)
- }, [])
-
- const handleKeydown = useCallback(
- (e: React.KeyboardEvent) => {
- e.stopPropagation()
-
- !modifierKeys.includes(e.key) && onKey?.()
-
- if ((e.key === 's' || e.key === 'Enter') && metaKey(e)) {
- const editor = rEditor.current
-
- if (!editor) return
-
- editor
- .getAction('editor.action.formatDocument')
- .run()
- .then(() =>
- onSave(rEditor.current?.getModel().getValue(), rEditor.current)
- )
-
- e.preventDefault()
- }
- if (e.key === 'p' && metaKey(e)) {
- e.preventDefault()
- }
-
- if (e.key === 'd' && metaKey(e)) {
- e.preventDefault()
- }
- },
- []
- )
-
- const handleKeyUp = useCallback(
- (e: React.KeyboardEvent) => e.stopPropagation(),
- []
- )
-
- const rDecorations = useRef([])
-
- useEffect(() => {
- const monaco = rMonaco.current
- if (!monaco) return
- const editor = rEditor.current
- if (!editor) return
-
- if (!error) {
- rDecorations.current = editor.deltaDecorations(rDecorations.current, [])
- return
- }
-
- if (!error.line) return
-
- rDecorations.current = editor.deltaDecorations(rDecorations.current, [
- {
- range: new monaco.Range(
- Number(error.line) - 1,
- 0,
- Number(error.line) - 1,
- 0
- ),
- options: {
- isWholeLine: true,
- className: 'editorLineError',
- },
- },
- ])
- }, [error])
-
- useEffect(() => {
- const monaco = rMonaco.current
- if (!monaco) return
- monaco.editor.setTheme(theme === 'dark' ? 'vs-dark' : 'light')
- }, [theme])
-
- useEffect(() => {
- const editor = rEditor.current
- if (!editor) return
-
- editor.updateOptions({
- fontSize,
- })
- }, [fontSize])
-
- return (
-
-
-
- )
-}
-
-const EditorContainer = styled('div', {
- height: '100%',
- pointerEvents: 'all',
- userSelect: 'all',
-
- '& > *': {
- userSelect: 'all',
- pointerEvents: 'all',
- },
-
- '.editorLineError': {
- backgroundColor: '$lineError',
- },
-})
diff --git a/components/code-panel/code-panel.tsx b/components/code-panel/code-panel.tsx
deleted file mode 100644
index 2f10ff676..000000000
--- a/components/code-panel/code-panel.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-/* eslint-disable @typescript-eslint/ban-ts-comment */
-import styled from 'styles'
-import { useStateDesigner } from '@state-designer/react'
-import React, { useCallback, useEffect, useRef } from 'react'
-import state, { useSelector } from 'state'
-import { CodeError, CodeFile, CodeResult } from 'types'
-import CodeDocs from './code-docs'
-import { generateFromCode } from 'state/code/generate'
-import * as Panel from '../panel'
-import { breakpoints, IconButton } from '../shared'
-import {
- Cross2Icon,
- CodeIcon,
- PlayIcon,
- ChevronUpIcon,
- ChevronDownIcon,
-} from '@radix-ui/react-icons'
-import dynamic from 'next/dynamic'
-import { ReaderIcon } from '@radix-ui/react-icons'
-const CodeEditor = dynamic(() => import('./code-editor'))
-
-const increaseCodeSize = () => state.send('INCREASED_CODE_FONT_SIZE')
-const decreaseCodeSize = () => state.send('DECREASED_CODE_FONT_SIZE')
-const toggleCodePanel = () => state.send('TOGGLED_CODE_PANEL_OPEN')
-const handleWheel = (e: React.WheelEvent) => e.stopPropagation()
-
-export default function CodePanel(): JSX.Element {
- const rContainer = useRef(null)
- const isReadOnly = useSelector((s) => s.data.isReadOnly)
- const fileId = useSelector((s) => s.data.currentCodeFileId)
- const file = useSelector(
- (s) => s.data.document.code[s.data.currentCodeFileId]
- )
- const isOpen = useSelector((s) => s.data.settings.isCodeOpen)
- const fontSize = useSelector((s) => s.data.settings.fontSize)
-
- const local = useStateDesigner({
- data: {
- code: file.code,
- error: null as CodeError | null,
- },
- on: {
- MOUNTED: 'setCode',
- CHANGED_FILE: 'loadFile',
- },
- initial: 'editingCode',
- states: {
- editingCode: {
- on: {
- RAN_CODE: { do: 'saveCode', to: 'evaluatingCode' },
- SAVED_CODE: { do: 'saveCode', to: 'evaluatingCode' },
- CHANGED_CODE: { secretlyDo: 'setCode' },
- CLEARED_ERROR: { if: 'hasError', do: 'clearError' },
- TOGGLED_DOCS: { to: 'viewingDocs' },
- },
- },
- evaluatingCode: {
- async: {
- await: 'evalCode',
- onResolve: {
- do: ['clearError', 'sendResultToGlobalState'],
- to: 'editingCode',
- },
- onReject: { do: 'setErrorFromResult', to: 'editingCode' },
- },
- },
- viewingDocs: {
- on: {
- TOGGLED_DOCS: { to: 'editingCode' },
- },
- },
- },
- conditions: {
- hasError(data) {
- return !!data.error
- },
- },
- actions: {
- loadFile(data, payload: { file: CodeFile }) {
- data.code = payload.file.code
- },
- setCode(data, payload: { code: string }) {
- data.code = payload.code
- },
- saveCode(data) {
- const { code } = data
- state.send('SAVED_CODE', { code })
- },
- clearError(data) {
- data.error = null
- },
- setErrorFromResult(data, payload, result: CodeResult) {
- data.error = result.error
- },
- sendResultToGlobalState(data, payload, result: CodeResult) {
- state.send('GENERATED_FROM_CODE', result)
- },
- },
- asyncs: {
- evalCode(data) {
- return new Promise((resolve, reject) => {
- generateFromCode(state.data, data.code).then((result) => {
- if (result.error !== null) {
- reject(result)
- } else {
- resolve(result)
- }
- })
- })
- },
- },
- })
-
- useEffect(() => {
- local.send('CHANGED_FILE', { file })
- }, [file])
-
- useEffect(() => {
- local.send('MOUNTED', { code: state.data.document.code[fileId].code })
- return () => {
- state.send('CHANGED_CODE', { fileId, code: local.data.code })
- }
- }, [])
-
- const handleCodeChange = useCallback(
- (code: string) => local.send('CHANGED_CODE', { code }),
- [local]
- )
-
- const handleSave = useCallback(() => local.send('SAVED_CODE'), [local])
-
- const handleKey = useCallback(() => local.send('CLEARED_ERROR'), [local])
-
- const toggleDocs = useCallback(() => local.send('TOGGLED_DOCS'), [local])
-
- const { error } = local.data
-
- return (
-
- {isOpen ? (
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {error && {error.message}}
-
- ) : (
-
-
-
- )}
-
- )
-}
-
-const ButtonsGroup = styled('div', {
- gridRow: '1',
- gridColumn: '3',
- display: 'flex',
-})
-
-const FontSizeButtons = styled('div', {
- paddingRight: 4,
- display: 'flex',
- flexDirection: 'column',
-
- '& > button': {
- height: '50%',
- '&:nth-of-type(1)': {
- alignItems: 'flex-end',
- },
-
- '&:nth-of-type(2)': {
- alignItems: 'flex-start',
- },
-
- '& svg': {
- height: 12,
- },
- },
-})
diff --git a/components/code-panel/docs-content.ts b/components/code-panel/docs-content.ts
deleted file mode 100644
index 036c32399..000000000
--- a/components/code-panel/docs-content.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/* eslint-disable */
-
-// HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
-// ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/docs-gen.js
-// ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
-
-export default {
- name: 'docs-content.ts',
- content: `
-Welcome to the documentation for tldraw's code editor. You can use the code editor to create shapes using JavaScript or TypeScript code.
-
-\`\`\`ts
-const rect = new Rectangle({
- point: [100, 100],
- size: [200, 200],
- style: {
- color: ColorStyle.Blue,
- },
-})
-
-rect.x = 300
-\`\`\`
-
-To run your code, press **Command + S**.
-
-Your new shapes will appear on the canvas. You can interact with code-created shapes just like any other shape: you can move the shape, change its style, delete it, etc.
-
-Each time you run your code, any existing code-created shapes will be replaced by your new code-created shapes. If you want to keep your code-created shapes, select the shapes that you want to keep, press **Command + D** to duplicate them, and move them off to the side.
-
-## Shapes
-
-You can use the code editor to create any of the regular shapes:
-
-- Draw
-- Rectangle
-- Ellipse
-- Arrow
-- Text
-
-You can also create shapes that can _only_ be created with code:
-
-- Dot
-- Ray
-- Line
-- Polyline
-
-Each of these shapes is a \`class\`. To create the shape, use the following syntax:
-
-\`\`\`ts
-const myShape = new Rectangle()
-\`\`\`
-
-You can also create a shape with custom properties like this:
-
-\`\`\`ts
-const myShape = new Rectangle({
- point: [100, 100],
- size: [200, 200],
- style: {
- color: ColorStyle.Blue,
- size: SizeStyle.Large,
- dash: DashStyle.Dotted,
- },
-})
-\`\`\`
-
-Once you've created a shape, you can set its properties like this:
-
-\`\`\`ts
-const myShape = new Rectangle()
-
-myShape.x = 100
-myShape.color = ColorStyle.Red
-\`\`\`
-
-You can find more information on each shape class by clicking its name in the list above.
-
-## Controls
-
-In addition to shapes, you can also use code to create controls.
-
-\`\`\`ts
-new NumberControl({
- label: 'x',
- value: 0,
-})
-
-const myShape = new Rectangle({
- point: [controls.x, 0],
-})
-\`\`\`
-
-Once you've created a control, the app's will display a panel where you can edit the control's value. As you edit the value, your code will run again with the control's new value.
-
-There are two kinds of controls:
-
-- NumberControl
-- VectorControl
-- TextControl
-
-Each of these controls is a \`class\`. To create the control, use the following syntax:
-
-\`\`\`ts
-const control = new TextControl({
- label: 'myLabel',
- value: 'my value',
-})
-\`\`\`
-
-Once you've created a control, you can use its value in your code like this:
-
-\`\`\`ts
-const myShape = new Text({
- text: controls.myLabel,
-})
-\`\`\`
-
-You can find more information on each control class by clicking its name in the list above.
-
-## Shape Classes
-
-...
-
-## Control Classes
-
-...
-
-`,
-}
diff --git a/components/code-panel/es5-lib.ts b/components/code-panel/es5-lib.ts
deleted file mode 100644
index 9374b3f54..000000000
--- a/components/code-panel/es5-lib.ts
+++ /dev/null
@@ -1,5459 +0,0 @@
-/* eslint-disable */
-
-// HEY! DO NOT MODIFY THIS FILE.
-
-export default {
- name: 'es5-lib.d.ts',
- content: `
-
-/*! *****************************************************************************
-Copyright (c) Microsoft Corporation. All rights reserved.
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use
-this file except in compliance with the License. You may obtain a copy of the
-License at http://www.apache.org/licenses/LICENSE-2.0
-
-THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
-WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
-MERCHANTABLITY OR NON-INFRINGEMENT.
-
-See the Apache Version 2.0 License for specific language governing permissions
-and limitations under the License.
-***************************************************************************** */
-
-///
-
-/////////////////////////////
-/// ECMAScript APIs
-/////////////////////////////
-
-declare let NaN: number
-declare let Infinity: number
-
-/**
- * Evaluates JavaScript code and executes it.
- * @param x A String value that contains valid JavaScript code.
- */
-declare function eval(x: string): any
-
-/**
- * Converts a string to an integer.
- * @param string A string to convert into a number.
- * @param radix A value between 2 and 36 that specifies the base of the number in \`string\`.
- * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
- * All other strings are considered decimal.
- */
-declare function parseInt(string: string, radix?: number): number
-
-/**
- * Converts a string to a floating-point number.
- * @param string A string that contains a floating-point number.
- */
-declare function parseFloat(string: string): number
-
-/**
- * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
- * @param number A numeric value.
- */
-declare function isNaN(number: number): boolean
-
-/**
- * Determines whether a supplied number is finite.
- * @param number Any numeric value.
- */
-declare function isFinite(number: number): boolean
-
-/**
- * Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
- * @param encodedURI A value representing an encoded URI.
- */
-declare function decodeURI(encodedURI: string): string
-
-/**
- * Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
- * @param encodedURIComponent A value representing an encoded URI component.
- */
-declare function decodeURIComponent(encodedURIComponent: string): string
-
-/**
- * Encodes a text string as a valid Uniform Resource Identifier (URI)
- * @param uri A value representing an encoded URI.
- */
-declare function encodeURI(uri: string): string
-
-/**
- * Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
- * @param uriComponent A value representing an encoded URI component.
- */
-declare function encodeURIComponent(
- uriComponent: string | number | boolean
-): string
-
-/**
- * Computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
- * @param string A string value
- */
-declare function escape(string: string): string
-
-/**
- * Computes a new string in which hexadecimal escape sequences are replaced with the character that it represents.
- * @param string A string value
- */
-declare function unescape(string: string): string
-
-interface Symbol {
- /** Returns a string representation of an object. */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): symbol
-}
-
-declare type PropertyKey = string | number | symbol
-
-interface PropertyDescriptor {
- configurable?: boolean
- enumerable?: boolean
- value?: any
- writable?: boolean
- get?(): any
- set?(v: any): void
-}
-
-interface PropertyDescriptorMap {
- [s: string]: PropertyDescriptor
-}
-
-interface Object {
- /** The initial value of Object.prototype.constructor is the standard built-in Object constructor. */
- constructor: Function
-
- /** Returns a string representation of an object. */
- toString(): string
-
- /** Returns a date converted to a string using the current locale. */
- toLocaleString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Object
-
- /**
- * Determines whether an object has a property with the specified name.
- * @param v A property name.
- */
- hasOwnProperty(v: PropertyKey): boolean
-
- /**
- * Determines whether an object exists in another object's prototype chain.
- * @param v Another object whose prototype chain is to be checked.
- */
- isPrototypeOf(v: Object): boolean
-
- /**
- * Determines whether a specified property is enumerable.
- * @param v A property name.
- */
- propertyIsEnumerable(v: PropertyKey): boolean
-}
-
-interface ObjectConstructor {
- new (value?: any): Object
- (): any
- (value: any): any
-
- /** A reference to the prototype for a class of objects. */
- readonly prototype: Object
-
- /**
- * Returns the prototype of an object.
- * @param o The object that references the prototype.
- */
- getPrototypeOf(o: any): any
-
- /**
- * Gets the own property descriptor of the specified object.
- * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
- * @param o Object that contains the property.
- * @param p Name of the property.
- */
- getOwnPropertyDescriptor(
- o: any,
- p: PropertyKey
- ): PropertyDescriptor | undefined
-
- /**
- * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly
- * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.
- * @param o Object that contains the own properties.
- */
- getOwnPropertyNames(o: any): string[]
-
- /**
- * Creates an object that has the specified prototype or that has null prototype.
- * @param o Object to use as a prototype. May be null.
- */
- create(o: object | null): any
-
- /**
- * Creates an object that has the specified prototype, and that optionally contains specified properties.
- * @param o Object to use as a prototype. May be null
- * @param properties JavaScript object that contains one or more property descriptors.
- */
- create(
- o: object | null,
- properties: PropertyDescriptorMap & ThisType
- ): any
-
- /**
- * Adds a property to an object, or modifies attributes of an existing property.
- * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.
- * @param p The property name.
- * @param attributes Descriptor for the property. It can be for a data property or an accessor property.
- */
- defineProperty(
- o: T,
- p: PropertyKey,
- attributes: PropertyDescriptor & ThisType
- ): T
-
- /**
- * Adds one or more properties to an object, and/or modifies attributes of existing properties.
- * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.
- * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.
- */
- defineProperties(
- o: T,
- properties: PropertyDescriptorMap & ThisType
- ): T
-
- /**
- * Prevents the modification of attributes of existing properties, and prevents the addition of new properties.
- * @param o Object on which to lock the attributes.
- */
- seal(o: T): T
-
- /**
- * Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
- * @param o Object on which to lock the attributes.
- */
- freeze(a: T[]): readonly T[]
-
- /**
- * Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
- * @param o Object on which to lock the attributes.
- */
- freeze(f: T): T
-
- /**
- * Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
- * @param o Object on which to lock the attributes.
- */
- freeze(o: T): Readonly
-
- /**
- * Prevents the addition of new properties to an object.
- * @param o Object to make non-extensible.
- */
- preventExtensions(o: T): T
-
- /**
- * Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.
- * @param o Object to test.
- */
- isSealed(o: any): boolean
-
- /**
- * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.
- * @param o Object to test.
- */
- isFrozen(o: any): boolean
-
- /**
- * Returns a value that indicates whether new properties can be added to an object.
- * @param o Object to test.
- */
- isExtensible(o: any): boolean
-
- /**
- * Returns the names of the enumerable string properties and methods of an object.
- * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
- */
- keys(o: object): string[]
-}
-
-/**
- * Provides functionality common to all JavaScript objects.
- */
-declare var Object: ObjectConstructor
-
-/**
- * Creates a new function.
- */
-interface Function {
- /**
- * Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.
- * @param thisArg The object to be used as the this object.
- * @param argArray A set of arguments to be passed to the function.
- */
- apply(this: Function, thisArg: any, argArray?: any): any
-
- /**
- * Calls a method of an object, substituting another object for the current object.
- * @param thisArg The object to be used as the current object.
- * @param argArray A list of arguments to be passed to the method.
- */
- call(this: Function, thisArg: any, ...argArray: any[]): any
-
- /**
- * For a given function, creates a bound function that has the same body as the original function.
- * The this object of the bound function is associated with the specified object, and has the specified initial parameters.
- * @param thisArg An object to which the this keyword can refer inside the new function.
- * @param argArray A list of arguments to be passed to the new function.
- */
- bind(this: Function, thisArg: any, ...argArray: any[]): any
-
- /** Returns a string representation of a function. */
- toString(): string
-
- prototype: any
- readonly length: number
-
- // Non-standard extensions
- arguments: any
- caller: Function
-}
-
-interface FunctionConstructor {
- /**
- * Creates a new function.
- * @param args A list of arguments the function accepts.
- */
- new (...args: string[]): Function
- (...args: string[]): Function
- readonly prototype: Function
-}
-
-declare var Function: FunctionConstructor
-
-/**
- * Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
- */
-type ThisParameterType = T extends (this: infer U, ...args: any[]) => any
- ? U
- : unknown
-
-/**
- * Removes the 'this' parameter from a function type.
- */
-type OmitThisParameter = unknown extends ThisParameterType
- ? T
- : T extends (...args: infer A) => infer R
- ? (...args: A) => R
- : T
-
-interface CallableFunction extends Function {
- /**
- * Calls the function with the specified object as the this value and the elements of specified array as the arguments.
- * @param thisArg The object to be used as the this object.
- * @param args An array of argument values to be passed to the function.
- */
- apply(this: (this: T) => R, thisArg: T): R
- apply(
- this: (this: T, ...args: A) => R,
- thisArg: T,
- args: A
- ): R
-
- /**
- * Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
- * @param thisArg The object to be used as the this object.
- * @param args Argument values to be passed to the function.
- */
- call(
- this: (this: T, ...args: A) => R,
- thisArg: T,
- ...args: A
- ): R
-
- /**
- * For a given function, creates a bound function that has the same body as the original function.
- * The this object of the bound function is associated with the specified object, and has the specified initial parameters.
- * @param thisArg The object to be used as the this object.
- * @param args Arguments to bind to the parameters of the function.
- */
- bind(this: T, thisArg: ThisParameterType): OmitThisParameter
- bind(
- this: (this: T, arg0: A0, ...args: A) => R,
- thisArg: T,
- arg0: A0
- ): (...args: A) => R
- bind(
- this: (this: T, arg0: A0, arg1: A1, ...args: A) => R,
- thisArg: T,
- arg0: A0,
- arg1: A1
- ): (...args: A) => R
- bind(
- this: (this: T, arg0: A0, arg1: A1, arg2: A2, ...args: A) => R,
- thisArg: T,
- arg0: A0,
- arg1: A1,
- arg2: A2
- ): (...args: A) => R
- bind(
- this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R,
- thisArg: T,
- arg0: A0,
- arg1: A1,
- arg2: A2,
- arg3: A3
- ): (...args: A) => R
- bind(
- this: (this: T, ...args: AX[]) => R,
- thisArg: T,
- ...args: AX[]
- ): (...args: AX[]) => R
-}
-
-interface NewableFunction extends Function {
- /**
- * Calls the function with the specified object as the this value and the elements of specified array as the arguments.
- * @param thisArg The object to be used as the this object.
- * @param args An array of argument values to be passed to the function.
- */
- apply(this: new () => T, thisArg: T): void
- apply(
- this: new (...args: A) => T,
- thisArg: T,
- args: A
- ): void
-
- /**
- * Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
- * @param thisArg The object to be used as the this object.
- * @param args Argument values to be passed to the function.
- */
- call(
- this: new (...args: A) => T,
- thisArg: T,
- ...args: A
- ): void
-
- /**
- * For a given function, creates a bound function that has the same body as the original function.
- * The this object of the bound function is associated with the specified object, and has the specified initial parameters.
- * @param thisArg The object to be used as the this object.
- * @param args Arguments to bind to the parameters of the function.
- */
- bind(this: T, thisArg: any): T
- bind(
- this: new (arg0: A0, ...args: A) => R,
- thisArg: any,
- arg0: A0
- ): new (...args: A) => R
- bind(
- this: new (arg0: A0, arg1: A1, ...args: A) => R,
- thisArg: any,
- arg0: A0,
- arg1: A1
- ): new (...args: A) => R
- bind(
- this: new (arg0: A0, arg1: A1, arg2: A2, ...args: A) => R,
- thisArg: any,
- arg0: A0,
- arg1: A1,
- arg2: A2
- ): new (...args: A) => R
- bind(
- this: new (arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R,
- thisArg: any,
- arg0: A0,
- arg1: A1,
- arg2: A2,
- arg3: A3
- ): new (...args: A) => R
- bind(
- this: new (...args: AX[]) => R,
- thisArg: any,
- ...args: AX[]
- ): new (...args: AX[]) => R
-}
-
-interface IArguments {
- [index: number]: any
- length: number
- callee: Function
-}
-
-interface String {
- /** Returns a string representation of a string. */
- toString(): string
-
- /**
- * Returns the character at the specified index.
- * @param pos The zero-based index of the desired character.
- */
- charAt(pos: number): string
-
- /**
- * Returns the Unicode value of the character at the specified location.
- * @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
- */
- charCodeAt(index: number): number
-
- /**
- * Returns a string that contains the concatenation of two or more strings.
- * @param strings The strings to append to the end of the string.
- */
- concat(...strings: string[]): string
-
- /**
- * Returns the position of the first occurrence of a substring.
- * @param searchString The substring to search for in the string
- * @param position The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
- */
- indexOf(searchString: string, position?: number): number
-
- /**
- * Returns the last occurrence of a substring in the string.
- * @param searchString The substring to search for.
- * @param position The index at which to begin searching. If omitted, the search begins at the end of the string.
- */
- lastIndexOf(searchString: string, position?: number): number
-
- /**
- * Determines whether two strings are equivalent in the current locale.
- * @param that String to compare to target string
- */
- localeCompare(that: string): number
-
- /**
- * Matches a string with a regular expression, and returns an array containing the results of that search.
- * @param regexp A variable name or string literal containing the regular expression pattern and flags.
- */
- match(regexp: string | RegExp): RegExpMatchArray | null
-
- /**
- * Replaces text in a string, using a regular expression or search string.
- * @param searchValue A string to search for.
- * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
- */
- replace(searchValue: string | RegExp, replaceValue: string): string
-
- /**
- * Replaces text in a string, using a regular expression or search string.
- * @param searchValue A string to search for.
- * @param replacer A function that returns the replacement text.
- */
- replace(
- searchValue: string | RegExp,
- replacer: (substring: string, ...args: any[]) => string
- ): string
-
- /**
- * Finds the first substring match in a regular expression search.
- * @param regexp The regular expression pattern and applicable flags.
- */
- search(regexp: string | RegExp): number
-
- /**
- * Returns a section of a string.
- * @param start The index to the beginning of the specified portion of stringObj.
- * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
- * If this value is not specified, the substring continues to the end of stringObj.
- */
- slice(start?: number, end?: number): string
-
- /**
- * Split a string into substrings using the specified separator and return them as an array.
- * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
- * @param limit A value used to limit the number of elements returned in the array.
- */
- split(separator: string | RegExp, limit?: number): string[]
-
- /**
- * Returns the substring at the specified location within a String object.
- * @param start The zero-based index number indicating the beginning of the substring.
- * @param end Zero-based index number indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end.
- * If end is omitted, the characters from start through the end of the original string are returned.
- */
- substring(start: number, end?: number): string
-
- /** Converts all the alphabetic characters in a string to lowercase. */
- toLowerCase(): string
-
- /** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */
- toLocaleLowerCase(locales?: string | string[]): string
-
- /** Converts all the alphabetic characters in a string to uppercase. */
- toUpperCase(): string
-
- /** Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. */
- toLocaleUpperCase(locales?: string | string[]): string
-
- /** Removes the leading and trailing white space and line terminator characters from a string. */
- trim(): string
-
- /** Returns the length of a String object. */
- readonly length: number
-
- // IE extensions
- /**
- * Gets a substring beginning at the specified location and having the specified length.
- * @param from The starting position of the desired substring. The index of the first character in the string is zero.
- * @param length The number of characters to include in the returned substring.
- */
- substr(from: number, length?: number): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): string
-
- readonly [index: number]: string
-}
-
-interface StringConstructor {
- new (value?: any): string
- (value?: any): string
- readonly prototype: string
- fromCharCode(...codes: number[]): string
-}
-
-/**
- * Allows manipulation and formatting of text strings and determination and location of substrings within strings.
- */
-declare var String: StringConstructor
-
-interface Boolean {
- /** Returns the primitive value of the specified object. */
- valueOf(): boolean
-}
-
-interface BooleanConstructor {
- new (value?: any): boolean
- (value?: T): boolean
- readonly prototype: boolean
-}
-
-declare var Boolean: BooleanConstructor
-
-interface Number {
- /**
- * Returns a string representation of an object.
- * @param radix Specifies a radix for converting numeric values to strings. This value is only used for numbers.
- */
- toString(radix?: number): string
-
- /**
- * Returns a string representing a number in fixed-point notation.
- * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
- */
- toFixed(fractionDigits?: number): string
-
- /**
- * Returns a string containing a number represented in exponential notation.
- * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
- */
- toExponential(fractionDigits?: number): string
-
- /**
- * Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.
- * @param precision Number of significant digits. Must be in the range 1 - 21, inclusive.
- */
- toPrecision(precision?: number): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): number
-}
-
-interface NumberConstructor {
- new (value?: any): number
- (value?: any): number
- readonly prototype: number
-
- /** The largest number that can be represented in JavaScript. Equal to approximately 1.79E+308. */
- readonly MAX_VALUE: number
-
- /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */
- readonly MIN_VALUE: number
-
- /**
- * A value that is not a number.
- * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function.
- */
- readonly NaN: number
-
- /**
- * A value that is less than the largest negative number that can be represented in JavaScript.
- * JavaScript displays NEGATIVE_INFINITY values as -infinity.
- */
- readonly NEGATIVE_INFINITY: number
-
- /**
- * A value greater than the largest number that can be represented in JavaScript.
- * JavaScript displays POSITIVE_INFINITY values as infinity.
- */
- readonly POSITIVE_INFINITY: number
-}
-
-/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
-declare var Number: NumberConstructor
-
-interface TemplateStringsArray extends ReadonlyArray {
- readonly raw: readonly string[]
-}
-
-/**
- * The type of \`import.meta\`.
- *
- * If you need to declare that a given property exists on \`import.meta\`,
- * this type may be augmented via interface merging.
- */
-interface ImportMeta {}
-
-interface Math {
- /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */
- readonly E: number
- /** The natural logarithm of 10. */
- readonly LN10: number
- /** The natural logarithm of 2. */
- readonly LN2: number
- /** The base-2 logarithm of e. */
- readonly LOG2E: number
- /** The base-10 logarithm of e. */
- readonly LOG10E: number
- /** Pi. This is the ratio of the circumference of a circle to its diameter. */
- readonly PI: number
- /** The square root of 0.5, or, equivalently, one divided by the square root of 2. */
- readonly SQRT1_2: number
- /** The square root of 2. */
- readonly SQRT2: number
- /**
- * Returns the absolute value of a number (the value without regard to whether it is positive or negative).
- * For example, the absolute value of -5 is the same as the absolute value of 5.
- * @param x A numeric expression for which the absolute value is needed.
- */
- abs(x: number): number
- /**
- * Returns the arc cosine (or inverse cosine) of a number.
- * @param x A numeric expression.
- */
- acos(x: number): number
- /**
- * Returns the arcsine of a number.
- * @param x A numeric expression.
- */
- asin(x: number): number
- /**
- * Returns the arctangent of a number.
- * @param x A numeric expression for which the arctangent is needed.
- */
- atan(x: number): number
- /**
- * Returns the angle (in radians) from the X axis to a point.
- * @param y A numeric expression representing the cartesian y-coordinate.
- * @param x A numeric expression representing the cartesian x-coordinate.
- */
- atan2(y: number, x: number): number
- /**
- * Returns the smallest integer greater than or equal to its numeric argument.
- * @param x A numeric expression.
- */
- ceil(x: number): number
- /**
- * Returns the cosine of a number.
- * @param x A numeric expression that contains an angle measured in radians.
- */
- cos(x: number): number
- /**
- * Returns e (the base of natural logarithms) raised to a power.
- * @param x A numeric expression representing the power of e.
- */
- exp(x: number): number
- /**
- * Returns the greatest integer less than or equal to its numeric argument.
- * @param x A numeric expression.
- */
- floor(x: number): number
- /**
- * Returns the natural logarithm (base e) of a number.
- * @param x A numeric expression.
- */
- log(x: number): number
- /**
- * Returns the larger of a set of supplied numeric expressions.
- * @param values Numeric expressions to be evaluated.
- */
- max(...values: number[]): number
- /**
- * Returns the smaller of a set of supplied numeric expressions.
- * @param values Numeric expressions to be evaluated.
- */
- min(...values: number[]): number
- /**
- * Returns the value of a base expression taken to a specified power.
- * @param x The base value of the expression.
- * @param y The exponent value of the expression.
- */
- pow(x: number, y: number): number
- /** Returns a pseudorandom number between 0 and 1. */
- random(): number
- /**
- * Returns a supplied numeric expression rounded to the nearest integer.
- * @param x The value to be rounded to the nearest integer.
- */
- round(x: number): number
- /**
- * Returns the sine of a number.
- * @param x A numeric expression that contains an angle measured in radians.
- */
- sin(x: number): number
- /**
- * Returns the square root of a number.
- * @param x A numeric expression.
- */
- sqrt(x: number): number
- /**
- * Returns the tangent of a number.
- * @param x A numeric expression that contains an angle measured in radians.
- */
- tan(x: number): number
-}
-/** An intrinsic object that provides basic mathematics functionality and constants. */
-declare var Math: Math
-
-/** Enables basic storage and retrieval of dates and times. */
-interface Date {
- /** Returns a string representation of a date. The format of the string depends on the locale. */
- toString(): string
- /** Returns a date as a string value. */
- toDateString(): string
- /** Returns a time as a string value. */
- toTimeString(): string
- /** Returns a value as a string value appropriate to the host environment's current locale. */
- toLocaleString(): string
- /** Returns a date as a string value appropriate to the host environment's current locale. */
- toLocaleDateString(): string
- /** Returns a time as a string value appropriate to the host environment's current locale. */
- toLocaleTimeString(): string
- /** Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. */
- valueOf(): number
- /** Gets the time value in milliseconds. */
- getTime(): number
- /** Gets the year, using local time. */
- getFullYear(): number
- /** Gets the year using Universal Coordinated Time (UTC). */
- getUTCFullYear(): number
- /** Gets the month, using local time. */
- getMonth(): number
- /** Gets the month of a Date object using Universal Coordinated Time (UTC). */
- getUTCMonth(): number
- /** Gets the day-of-the-month, using local time. */
- getDate(): number
- /** Gets the day-of-the-month, using Universal Coordinated Time (UTC). */
- getUTCDate(): number
- /** Gets the day of the week, using local time. */
- getDay(): number
- /** Gets the day of the week using Universal Coordinated Time (UTC). */
- getUTCDay(): number
- /** Gets the hours in a date, using local time. */
- getHours(): number
- /** Gets the hours value in a Date object using Universal Coordinated Time (UTC). */
- getUTCHours(): number
- /** Gets the minutes of a Date object, using local time. */
- getMinutes(): number
- /** Gets the minutes of a Date object using Universal Coordinated Time (UTC). */
- getUTCMinutes(): number
- /** Gets the seconds of a Date object, using local time. */
- getSeconds(): number
- /** Gets the seconds of a Date object using Universal Coordinated Time (UTC). */
- getUTCSeconds(): number
- /** Gets the milliseconds of a Date, using local time. */
- getMilliseconds(): number
- /** Gets the milliseconds of a Date object using Universal Coordinated Time (UTC). */
- getUTCMilliseconds(): number
- /** Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). */
- getTimezoneOffset(): number
- /**
- * Sets the date and time value in the Date object.
- * @param time A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT.
- */
- setTime(time: number): number
- /**
- * Sets the milliseconds value in the Date object using local time.
- * @param ms A numeric value equal to the millisecond value.
- */
- setMilliseconds(ms: number): number
- /**
- * Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC).
- * @param ms A numeric value equal to the millisecond value.
- */
- setUTCMilliseconds(ms: number): number
-
- /**
- * Sets the seconds value in the Date object using local time.
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setSeconds(sec: number, ms?: number): number
- /**
- * Sets the seconds value in the Date object using Universal Coordinated Time (UTC).
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setUTCSeconds(sec: number, ms?: number): number
- /**
- * Sets the minutes value in the Date object using local time.
- * @param min A numeric value equal to the minutes value.
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setMinutes(min: number, sec?: number, ms?: number): number
- /**
- * Sets the minutes value in the Date object using Universal Coordinated Time (UTC).
- * @param min A numeric value equal to the minutes value.
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setUTCMinutes(min: number, sec?: number, ms?: number): number
- /**
- * Sets the hour value in the Date object using local time.
- * @param hours A numeric value equal to the hours value.
- * @param min A numeric value equal to the minutes value.
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setHours(hours: number, min?: number, sec?: number, ms?: number): number
- /**
- * Sets the hours value in the Date object using Universal Coordinated Time (UTC).
- * @param hours A numeric value equal to the hours value.
- * @param min A numeric value equal to the minutes value.
- * @param sec A numeric value equal to the seconds value.
- * @param ms A numeric value equal to the milliseconds value.
- */
- setUTCHours(hours: number, min?: number, sec?: number, ms?: number): number
- /**
- * Sets the numeric day-of-the-month value of the Date object using local time.
- * @param date A numeric value equal to the day of the month.
- */
- setDate(date: number): number
- /**
- * Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).
- * @param date A numeric value equal to the day of the month.
- */
- setUTCDate(date: number): number
- /**
- * Sets the month value in the Date object using local time.
- * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.
- * @param date A numeric value representing the day of the month. If this value is not supplied, the value from a call to the getDate method is used.
- */
- setMonth(month: number, date?: number): number
- /**
- * Sets the month value in the Date object using Universal Coordinated Time (UTC).
- * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively.
- * @param date A numeric value representing the day of the month. If it is not supplied, the value from a call to the getUTCDate method is used.
- */
- setUTCMonth(month: number, date?: number): number
- /**
- * Sets the year of the Date object using local time.
- * @param year A numeric value for the year.
- * @param month A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified.
- * @param date A numeric value equal for the day of the month.
- */
- setFullYear(year: number, month?: number, date?: number): number
- /**
- * Sets the year value in the Date object using Universal Coordinated Time (UTC).
- * @param year A numeric value equal to the year.
- * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. Must be supplied if numDate is supplied.
- * @param date A numeric value equal to the day of the month.
- */
- setUTCFullYear(year: number, month?: number, date?: number): number
- /** Returns a date converted to a string using Universal Coordinated Time (UTC). */
- toUTCString(): string
- /** Returns a date as a string value in ISO format. */
- toISOString(): string
- /** Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. */
- toJSON(key?: any): string
-}
-
-interface DateConstructor {
- new (): Date
- new (value: number | string): Date
- new (
- year: number,
- month: number,
- date?: number,
- hours?: number,
- minutes?: number,
- seconds?: number,
- ms?: number
- ): Date
- (): string
- readonly prototype: Date
- /**
- * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.
- * @param s A date string
- */
- parse(s: string): number
- /**
- * Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
- * @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
- * @param month The month as a number between 0 and 11 (January to December).
- * @param date The date as a number between 1 and 31.
- * @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
- * @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
- * @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
- * @param ms A number from 0 to 999 that specifies the milliseconds.
- */
- UTC(
- year: number,
- month: number,
- date?: number,
- hours?: number,
- minutes?: number,
- seconds?: number,
- ms?: number
- ): number
- now(): number
-}
-
-declare var Date: DateConstructor
-
-interface RegExpMatchArray extends Array {
- index?: number
- input?: string
-}
-
-interface RegExpExecArray extends Array {
- index: number
- input: string
-}
-
-interface RegExp {
- /**
- * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
- * @param string The String object or string literal on which to perform the search.
- */
- exec(string: string): RegExpExecArray | null
-
- /**
- * Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
- * @param string String on which to perform the search.
- */
- test(string: string): boolean
-
- /** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */
- readonly source: string
-
- /** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */
- readonly global: boolean
-
- /** Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. */
- readonly ignoreCase: boolean
-
- /** Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. */
- readonly multiline: boolean
-
- lastIndex: number
-
- // Non-standard extensions
- compile(): this
-}
-
-interface RegExpConstructor {
- new (pattern: RegExp | string): RegExp
- new (pattern: string, flags?: string): RegExp
- (pattern: RegExp | string): RegExp
- (pattern: string, flags?: string): RegExp
- readonly prototype: RegExp
-
- // Non-standard extensions
- $1: string
- $2: string
- $3: string
- $4: string
- $5: string
- $6: string
- $7: string
- $8: string
- $9: string
- lastMatch: string
-}
-
-declare var RegExp: RegExpConstructor
-
-interface Error {
- name: string
- message: string
- stack?: string
-}
-
-interface ErrorConstructor {
- new (message?: string): Error
- (message?: string): Error
- readonly prototype: Error
-}
-
-declare var Error: ErrorConstructor
-
-type EvalError = Error
-
-interface EvalErrorConstructor extends ErrorConstructor {
- new (message?: string): EvalError
- (message?: string): EvalError
- readonly prototype: EvalError
-}
-
-declare var EvalError: EvalErrorConstructor
-
-type RangeError = Error
-
-interface RangeErrorConstructor extends ErrorConstructor {
- new (message?: string): RangeError
- (message?: string): RangeError
- readonly prototype: RangeError
-}
-
-declare var RangeError: RangeErrorConstructor
-
-type ReferenceError = Error
-
-interface ReferenceErrorConstructor extends ErrorConstructor {
- new (message?: string): ReferenceError
- (message?: string): ReferenceError
- readonly prototype: ReferenceError
-}
-
-declare var ReferenceError: ReferenceErrorConstructor
-
-type SyntaxError = Error
-
-interface SyntaxErrorConstructor extends ErrorConstructor {
- new (message?: string): SyntaxError
- (message?: string): SyntaxError
- readonly prototype: SyntaxError
-}
-
-declare var SyntaxError: SyntaxErrorConstructor
-
-type TypeError = Error
-
-interface TypeErrorConstructor extends ErrorConstructor {
- new (message?: string): TypeError
- (message?: string): TypeError
- readonly prototype: TypeError
-}
-
-declare var TypeError: TypeErrorConstructor
-
-type URIError = Error
-
-interface URIErrorConstructor extends ErrorConstructor {
- new (message?: string): URIError
- (message?: string): URIError
- readonly prototype: URIError
-}
-
-declare var URIError: URIErrorConstructor
-
-interface JSON {
- /**
- * Converts a JavaScript Object Notation (JSON) string into an object.
- * @param text A valid JSON string.
- * @param reviver A function that transforms the results. This function is called for each member of the object.
- * If a member contains nested objects, the nested objects are transformed before the parent object is.
- */
- parse(
- text: string,
- reviver?: (this: any, key: string, value: any) => any
- ): any
- /**
- * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
- * @param value A JavaScript value, usually an object or array, to be converted.
- * @param replacer A function that transforms the results.
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
- */
- stringify(
- value: any,
- replacer?: (this: any, key: string, value: any) => any,
- space?: string | number
- ): string
- /**
- * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
- * @param value A JavaScript value, usually an object or array, to be converted.
- * @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
- */
- stringify(
- value: any,
- replacer?: (number | string)[] | null,
- space?: string | number
- ): string
-}
-
-/**
- * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
- */
-declare var JSON: JSON
-
-/////////////////////////////
-/// ECMAScript Array API (specially handled by compiler)
-/////////////////////////////
-
-interface ReadonlyArray {
- /**
- * Gets the length of the array. This is a number one higher than the highest element defined in an array.
- */
- readonly length: number
- /**
- * Returns a string representation of an array.
- */
- toString(): string
- /**
- * Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
- */
- toLocaleString(): string
- /**
- * Combines two or more arrays.
- * @param items Additional items to add to the end of array1.
- */
- concat(...items: ConcatArray[]): T[]
- /**
- * Combines two or more arrays.
- * @param items Additional items to add to the end of array1.
- */
- concat(...items: (T | ConcatArray)[]): T[]
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): T[]
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
- */
- indexOf(searchElement: T, fromIndex?: number): number
- /**
- * Returns the index of the last occurrence of a specified value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
- */
- lastIndexOf(searchElement: T, fromIndex?: number): number
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: T, index: number, array: readonly T[]) => value is S,
- thisArg?: any
- ): this is readonly S[]
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
- thisArg?: any
- ): boolean
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
- thisArg?: any
- ): boolean
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: T, index: number, array: readonly T[]) => void,
- thisArg?: any
- ): void
- /**
- * Calls a defined callback function on each element of an array, and returns an array that contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: T, index: number, array: readonly T[]) => U,
- thisArg?: any
- ): U[]
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: T, index: number, array: readonly T[]) => value is S,
- thisArg?: any
- ): S[]
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: T, index: number, array: readonly T[]) => unknown,
- thisArg?: any
- ): T[]
- /**
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => T
- ): T
- reduce(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => T,
- initialValue: T
- ): T
- /**
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => U,
- initialValue: U
- ): U
- /**
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => T
- ): T
- reduceRight(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => T,
- initialValue: T
- ): T
- /**
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: T,
- currentIndex: number,
- array: readonly T[]
- ) => U,
- initialValue: U
- ): U
-
- readonly [n: number]: T
-}
-
-interface ConcatArray {
- readonly length: number
- readonly [n: number]: T
- join(separator?: string): string
- slice(start?: number, end?: number): T[]
-}
-
-interface Array {
- /**
- * Gets or sets the length of the array. This is a number one higher than the highest index in the array.
- */
- length: number
- /**
- * Returns a string representation of an array.
- */
- toString(): string
- /**
- * Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
- */
- toLocaleString(): string
- /**
- * Removes the last element from an array and returns it.
- * If the array is empty, undefined is returned and the array is not modified.
- */
- pop(): T | undefined
- /**
- * Appends new elements to the end of an array, and returns the new length of the array.
- * @param items New elements to add to the array.
- */
- push(...items: T[]): number
- /**
- * Combines two or more arrays.
- * This method returns a new array without modifying any existing arrays.
- * @param items Additional arrays and/or items to add to the end of the array.
- */
- concat(...items: ConcatArray[]): T[]
- /**
- * Combines two or more arrays.
- * This method returns a new array without modifying any existing arrays.
- * @param items Additional arrays and/or items to add to the end of the array.
- */
- concat(...items: (T | ConcatArray)[]): T[]
- /**
- * Adds all the elements of an array into a string, separated by the specified separator string.
- * @param separator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
- /**
- * Reverses the elements in an array in place.
- * This method mutates the array and returns a reference to the same array.
- */
- reverse(): T[]
- /**
- * Removes the first element from an array and returns it.
- * If the array is empty, undefined is returned and the array is not modified.
- */
- shift(): T | undefined
- /**
- * Returns a copy of a section of an array.
- * For both start and end, a negative index can be used to indicate an offset from the end of the array.
- * For example, -2 refers to the second to last element of the array.
- * @param start The beginning index of the specified portion of the array.
- * If start is undefined, then the slice begins at index 0.
- * @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'.
- * If end is undefined, then the slice extends to the end of the array.
- */
- slice(start?: number, end?: number): T[]
- /**
- * Sorts an array in place.
- * This method mutates the array and returns a reference to the same array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: T, b: T) => number): this
- /**
- * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
- * @param start The zero-based location in the array from which to start removing elements.
- * @param deleteCount The number of elements to remove.
- * @returns An array containing the elements that were deleted.
- */
- splice(start: number, deleteCount?: number): T[]
- /**
- * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
- * @param start The zero-based location in the array from which to start removing elements.
- * @param deleteCount The number of elements to remove.
- * @param items Elements to insert into the array in place of the deleted elements.
- * @returns An array containing the elements that were deleted.
- */
- splice(start: number, deleteCount: number, ...items: T[]): T[]
- /**
- * Inserts new elements at the start of an array, and returns the new length of the array.
- * @param items Elements to insert at the start of the array.
- */
- unshift(...items: T[]): number
- /**
- * Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
- */
- indexOf(searchElement: T, fromIndex?: number): number
- /**
- * Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
- */
- lastIndexOf(searchElement: T, fromIndex?: number): number
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: T, index: number, array: T[]) => value is S,
- thisArg?: any
- ): this is S[]
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: T, index: number, array: T[]) => unknown,
- thisArg?: any
- ): boolean
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: T, index: number, array: T[]) => unknown,
- thisArg?: any
- ): boolean
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: T, index: number, array: T[]) => void,
- thisArg?: any
- ): void
- /**
- * Calls a defined callback function on each element of an array, and returns an array that contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: T, index: number, array: T[]) => U,
- thisArg?: any
- ): U[]
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: T, index: number, array: T[]) => value is S,
- thisArg?: any
- ): S[]
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: T, index: number, array: T[]) => unknown,
- thisArg?: any
- ): T[]
- /**
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => T
- ): T
- reduce(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => T,
- initialValue: T
- ): T
- /**
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => U,
- initialValue: U
- ): U
- /**
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => T
- ): T
- reduceRight(
- callbackfn: (
- previousValue: T,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => T,
- initialValue: T
- ): T
- /**
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: T,
- currentIndex: number,
- array: T[]
- ) => U,
- initialValue: U
- ): U
-
- [n: number]: T
-}
-
-interface ArrayConstructor {
- new (arrayLength?: number): any[]
- new (arrayLength: number): T[]
- new (...items: T[]): T[]
- (arrayLength?: number): any[]
- (arrayLength: number): T[]
- (...items: T[]): T[]
- isArray(arg: any): arg is any[]
- readonly prototype: any[]
-}
-
-declare var Array: ArrayConstructor
-
-interface TypedPropertyDescriptor {
- enumerable?: boolean
- configurable?: boolean
- writable?: boolean
- value?: T
- get?: () => T
- set?: (value: T) => void
-}
-
-declare type ClassDecorator = (
- target: TFunction
-) => TFunction | void
-declare type PropertyDecorator = (
- target: Object,
- propertyKey: string | symbol
-) => void
-declare type MethodDecorator = (
- target: Object,
- propertyKey: string | symbol,
- descriptor: TypedPropertyDescriptor
-) => TypedPropertyDescriptor | void
-declare type ParameterDecorator = (
- target: Object,
- propertyKey: string | symbol,
- parameterIndex: number
-) => void
-
-declare type PromiseConstructorLike = new (
- executor: (
- resolve: (value: T | PromiseLike) => void,
- reject: (reason?: any) => void
- ) => void
-) => PromiseLike
-
-interface PromiseLike {
- /**
- * Attaches callbacks for the resolution and/or rejection of the Promise.
- * @param onfulfilled The callback to execute when the Promise is resolved.
- * @param onrejected The callback to execute when the Promise is rejected.
- * @returns A Promise for the completion of which ever callback is executed.
- */
- then(
- onfulfilled?:
- | ((value: T) => TResult1 | PromiseLike)
- | undefined
- | null,
- onrejected?:
- | ((reason: any) => TResult2 | PromiseLike)
- | undefined
- | null
- ): PromiseLike
-}
-
-/**
- * Represents the completion of an asynchronous operation
- */
-interface Promise {
- /**
- * Attaches callbacks for the resolution and/or rejection of the Promise.
- * @param onfulfilled The callback to execute when the Promise is resolved.
- * @param onrejected The callback to execute when the Promise is rejected.
- * @returns A Promise for the completion of which ever callback is executed.
- */
- then(
- onfulfilled?:
- | ((value: T) => TResult1 | PromiseLike)
- | undefined
- | null,
- onrejected?:
- | ((reason: any) => TResult2 | PromiseLike)
- | undefined
- | null
- ): Promise
-
- /**
- * Attaches a callback for only the rejection of the Promise.
- * @param onrejected The callback to execute when the Promise is rejected.
- * @returns A Promise for the completion of the callback.
- */
- catch(
- onrejected?:
- | ((reason: any) => TResult | PromiseLike)
- | undefined
- | null
- ): Promise
-}
-
-interface ArrayLike {
- readonly length: number
- readonly [n: number]: T
-}
-
-/**
- * Make all properties in T optional
- */
-type Partial = {
- [P in keyof T]?: T[P]
-}
-
-/**
- * Make all properties in T required
- */
-type Required = {
- [P in keyof T]-?: T[P]
-}
-
-/**
- * Make all properties in T readonly
- */
-type Readonly = {
- readonly [P in keyof T]: T[P]
-}
-
-/**
- * From T, pick a set of properties whose keys are in the union K
- */
-type Pick = {
- [P in K]: T[P]
-}
-
-/**
- * Construct a type with a set of properties K of type T
- */
-type Record = {
- [P in K]: T
-}
-
-/**
- * Exclude from T those types that are assignable to U
- */
-type Exclude = T extends U ? never : T
-
-/**
- * Extract from T those types that are assignable to U
- */
-type Extract = T extends U ? T : never
-
-/**
- * Construct a type with the properties of T except for those in type K.
- */
-type Omit = Pick>
-
-/**
- * Exclude null and undefined from T
- */
-type NonNullable = T extends null | undefined ? never : T
-
-/**
- * Obtain the parameters of a function type in a tuple
- */
-type Parameters any> = T extends (
- ...args: infer P
-) => any
- ? P
- : never
-
-/**
- * Obtain the parameters of a constructor function type in a tuple
- */
-type ConstructorParameters any> =
- T extends abstract new (...args: infer P) => any ? P : never
-
-/**
- * Obtain the return type of a function type
- */
-type ReturnType any> = T extends (
- ...args: any
-) => infer R
- ? R
- : any
-
-/**
- * Obtain the return type of a constructor function type
- */
-type InstanceType any> =
- T extends abstract new (...args: any) => infer R ? R : any
-
-/**
- * Convert string literal type to uppercase
- */
-type Uppercase = intrinsic
-
-/**
- * Convert string literal type to lowercase
- */
-type Lowercase = intrinsic
-
-/**
- * Convert first character of string literal type to uppercase
- */
-type Capitalize = intrinsic
-
-/**
- * Convert first character of string literal type to lowercase
- */
-type Uncapitalize = intrinsic
-
-/**
- * Marker for contextual 'this' type
- */
-interface ThisType {}
-
-/**
- * Represents a raw buffer of binary data, which is used to store data for the
- * different typed arrays. ArrayBuffers cannot be read from or written to directly,
- * but can be passed to a typed array or DataView Object to interpret the raw
- * buffer as needed.
- */
-interface ArrayBuffer {
- /**
- * Read-only. The length of the ArrayBuffer (in bytes).
- */
- readonly byteLength: number
-
- /**
- * Returns a section of an ArrayBuffer.
- */
- slice(begin: number, end?: number): ArrayBuffer
-}
-
-/**
- * Allowed ArrayBuffer types for the buffer of an ArrayBufferView and related Typed Arrays.
- */
-interface ArrayBufferTypes {
- ArrayBuffer: ArrayBuffer
-}
-type ArrayBufferLike = ArrayBufferTypes[keyof ArrayBufferTypes]
-
-interface ArrayBufferConstructor {
- readonly prototype: ArrayBuffer
- new (byteLength: number): ArrayBuffer
- isView(arg: any): arg is ArrayBufferView
-}
-declare var ArrayBuffer: ArrayBufferConstructor
-
-interface ArrayBufferView {
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- byteOffset: number
-}
-
-interface DataView {
- readonly buffer: ArrayBuffer
- readonly byteLength: number
- readonly byteOffset: number
- /**
- * Gets the Float32 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getFloat32(byteOffset: number, littleEndian?: boolean): number
-
- /**
- * Gets the Float64 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getFloat64(byteOffset: number, littleEndian?: boolean): number
-
- /**
- * Gets the Int8 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getInt8(byteOffset: number): number
-
- /**
- * Gets the Int16 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getInt16(byteOffset: number, littleEndian?: boolean): number
- /**
- * Gets the Int32 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getInt32(byteOffset: number, littleEndian?: boolean): number
-
- /**
- * Gets the Uint8 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getUint8(byteOffset: number): number
-
- /**
- * Gets the Uint16 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getUint16(byteOffset: number, littleEndian?: boolean): number
-
- /**
- * Gets the Uint32 value at the specified byte offset from the start of the view. There is
- * no alignment constraint; multi-byte values may be fetched from any offset.
- * @param byteOffset The place in the buffer at which the value should be retrieved.
- */
- getUint32(byteOffset: number, littleEndian?: boolean): number
-
- /**
- * Stores an Float32 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void
-
- /**
- * Stores an Float64 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void
-
- /**
- * Stores an Int8 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- */
- setInt8(byteOffset: number, value: number): void
-
- /**
- * Stores an Int16 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setInt16(byteOffset: number, value: number, littleEndian?: boolean): void
-
- /**
- * Stores an Int32 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setInt32(byteOffset: number, value: number, littleEndian?: boolean): void
-
- /**
- * Stores an Uint8 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- */
- setUint8(byteOffset: number, value: number): void
-
- /**
- * Stores an Uint16 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setUint16(byteOffset: number, value: number, littleEndian?: boolean): void
-
- /**
- * Stores an Uint32 value at the specified byte offset from the start of the view.
- * @param byteOffset The place in the buffer at which the value should be set.
- * @param value The value to set.
- * @param littleEndian If false or undefined, a big-endian value should be written,
- * otherwise a little-endian value should be written.
- */
- setUint32(byteOffset: number, value: number, littleEndian?: boolean): void
-}
-
-interface DataViewConstructor {
- readonly prototype: DataView
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- byteLength?: number
- ): DataView
-}
-declare var DataView: DataViewConstructor
-
-/**
- * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested
- * number of bytes could not be allocated an exception is raised.
- */
-interface Int8Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Int8Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Int8Array) => any,
- thisArg?: any
- ): Int8Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Int8Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Int8Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Int8Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Int8Array) => number,
- thisArg?: any
- ): Int8Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int8Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Int8Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Int8Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Int8Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Int8Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Int8Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Int8Array
-
- [index: number]: number
-}
-interface Int8ArrayConstructor {
- readonly prototype: Int8Array
- new (length: number): Int8Array
- new (array: ArrayLike | ArrayBufferLike): Int8Array
- new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): Int8Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Int8Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Int8Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Int8Array
-}
-declare var Int8Array: Int8ArrayConstructor
-
-/**
- * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
- * requested number of bytes could not be allocated an exception is raised.
- */
-interface Uint8Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Uint8Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Uint8Array) => any,
- thisArg?: any
- ): Uint8Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Uint8Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Uint8Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Uint8Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Uint8Array) => number,
- thisArg?: any
- ): Uint8Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint8Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Uint8Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Uint8Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Uint8Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Uint8Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Uint8Array
-
- [index: number]: number
-}
-
-interface Uint8ArrayConstructor {
- readonly prototype: Uint8Array
- new (length: number): Uint8Array
- new (array: ArrayLike | ArrayBufferLike): Uint8Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Uint8Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Uint8Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Uint8Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Uint8Array
-}
-declare var Uint8Array: Uint8ArrayConstructor
-
-/**
- * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0.
- * If the requested number of bytes could not be allocated an exception is raised.
- */
-interface Uint8ClampedArray {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (
- value: number,
- index: number,
- array: Uint8ClampedArray
- ) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Uint8ClampedArray) => any,
- thisArg?: any
- ): Uint8ClampedArray
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (
- value: number,
- index: number,
- obj: Uint8ClampedArray
- ) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (
- value: number,
- index: number,
- obj: Uint8ClampedArray
- ) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (
- value: number,
- index: number,
- array: Uint8ClampedArray
- ) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (
- value: number,
- index: number,
- array: Uint8ClampedArray
- ) => number,
- thisArg?: any
- ): Uint8ClampedArray
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint8ClampedArray
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Uint8ClampedArray
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Uint8ClampedArray
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (
- value: number,
- index: number,
- array: Uint8ClampedArray
- ) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Uint8ClampedArray view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Uint8ClampedArray
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Uint8ClampedArray
-
- [index: number]: number
-}
-
-interface Uint8ClampedArrayConstructor {
- readonly prototype: Uint8ClampedArray
- new (length: number): Uint8ClampedArray
- new (array: ArrayLike | ArrayBufferLike): Uint8ClampedArray
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Uint8ClampedArray
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Uint8ClampedArray
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Uint8ClampedArray
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Uint8ClampedArray
-}
-declare var Uint8ClampedArray: Uint8ClampedArrayConstructor
-
-/**
- * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the
- * requested number of bytes could not be allocated an exception is raised.
- */
-interface Int16Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Int16Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Int16Array) => any,
- thisArg?: any
- ): Int16Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Int16Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Int16Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Int16Array) => void,
- thisArg?: any
- ): void
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Int16Array) => number,
- thisArg?: any
- ): Int16Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int16Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Int16Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Int16Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Int16Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Int16Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Int16Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Int16Array
-
- [index: number]: number
-}
-
-interface Int16ArrayConstructor {
- readonly prototype: Int16Array
- new (length: number): Int16Array
- new (array: ArrayLike | ArrayBufferLike): Int16Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Int16Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Int16Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Int16Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Int16Array
-}
-declare var Int16Array: Int16ArrayConstructor
-
-/**
- * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the
- * requested number of bytes could not be allocated an exception is raised.
- */
-interface Uint16Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Uint16Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Uint16Array) => any,
- thisArg?: any
- ): Uint16Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Uint16Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Uint16Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Uint16Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Uint16Array) => number,
- thisArg?: any
- ): Uint16Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint16Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Uint16Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Uint16Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Uint16Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Uint16Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Uint16Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Uint16Array
-
- [index: number]: number
-}
-
-interface Uint16ArrayConstructor {
- readonly prototype: Uint16Array
- new (length: number): Uint16Array
- new (array: ArrayLike | ArrayBufferLike): Uint16Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Uint16Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Uint16Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Uint16Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Uint16Array
-}
-declare var Uint16Array: Uint16ArrayConstructor
-/**
- * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the
- * requested number of bytes could not be allocated an exception is raised.
- */
-interface Int32Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Int32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Int32Array) => any,
- thisArg?: any
- ): Int32Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Int32Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Int32Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Int32Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Int32Array) => number,
- thisArg?: any
- ): Int32Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Int32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Int32Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Int32Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Int32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Int32Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Int32Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Int32Array
-
- [index: number]: number
-}
-
-interface Int32ArrayConstructor {
- readonly prototype: Int32Array
- new (length: number): Int32Array
- new (array: ArrayLike | ArrayBufferLike): Int32Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Int32Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Int32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Int32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Int32Array
-}
-declare var Int32Array: Int32ArrayConstructor
-
-/**
- * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the
- * requested number of bytes could not be allocated an exception is raised.
- */
-interface Uint32Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Uint32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Uint32Array) => any,
- thisArg?: any
- ): Uint32Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Uint32Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Uint32Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Uint32Array) => void,
- thisArg?: any
- ): void
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Uint32Array) => number,
- thisArg?: any
- ): Uint32Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Uint32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Uint32Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Uint32Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Uint32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Uint32Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Uint32Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Uint32Array
-
- [index: number]: number
-}
-
-interface Uint32ArrayConstructor {
- readonly prototype: Uint32Array
- new (length: number): Uint32Array
- new (array: ArrayLike | ArrayBufferLike): Uint32Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Uint32Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Uint32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Uint32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Uint32Array
-}
-declare var Uint32Array: Uint32ArrayConstructor
-
-/**
- * A typed array of 32-bit float values. The contents are initialized to 0. If the requested number
- * of bytes could not be allocated an exception is raised.
- */
-interface Float32Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Float32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Float32Array) => any,
- thisArg?: any
- ): Float32Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Float32Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Float32Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Float32Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Float32Array) => number,
- thisArg?: any
- ): Float32Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Float32Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Float32Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Float32Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Float32Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * Gets a new Float32Array view of the ArrayBuffer store for this array, referencing the elements
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Float32Array
-
- /**
- * Converts a number to a string by using the current locale.
- */
- toLocaleString(): string
-
- /**
- * Returns a string representation of an array.
- */
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Float32Array
-
- [index: number]: number
-}
-
-interface Float32ArrayConstructor {
- readonly prototype: Float32Array
- new (length: number): Float32Array
- new (array: ArrayLike | ArrayBufferLike): Float32Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Float32Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Float32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Float32Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Float32Array
-}
-declare var Float32Array: Float32ArrayConstructor
-
-/**
- * A typed array of 64-bit float values. The contents are initialized to 0. If the requested
- * number of bytes could not be allocated an exception is raised.
- */
-interface Float64Array {
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * The ArrayBuffer instance referenced by the array.
- */
- readonly buffer: ArrayBufferLike
-
- /**
- * The length in bytes of the array.
- */
- readonly byteLength: number
-
- /**
- * The offset in bytes of the array.
- */
- readonly byteOffset: number
-
- /**
- * Returns the this object after copying a section of the array identified by start and end
- * to the same array starting at position target
- * @param target If target is negative, it is treated as length+target where length is the
- * length of the array.
- * @param start If start is negative, it is treated as length+start. If end is negative, it
- * is treated as length+end.
- * @param end If not specified, length of the this object is used as its default value.
- */
- copyWithin(target: number, start: number, end?: number): this
-
- /**
- * Determines whether all the members of an array satisfy the specified test.
- * @param predicate A function that accepts up to three arguments. The every method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- every(
- predicate: (value: number, index: number, array: Float64Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Changes all array elements from \`start\` to \`end\` index to a static \`value\` and returns the modified array
- * @param value value to fill array section with
- * @param start index to start filling the array at. If start is negative, it is treated as
- * length+start where length is the length of the array.
- * @param end index to stop filling the array at. If end is negative, it is treated as
- * length+end.
- */
- fill(value: number, start?: number, end?: number): this
-
- /**
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param predicate A function that accepts up to three arguments. The filter method calls
- * the predicate function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- filter(
- predicate: (value: number, index: number, array: Float64Array) => any,
- thisArg?: any
- ): Float64Array
-
- /**
- * Returns the value of the first element in the array where predicate is true, and undefined
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found, find
- * immediately returns that element value. Otherwise, find returns undefined.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- find(
- predicate: (value: number, index: number, obj: Float64Array) => boolean,
- thisArg?: any
- ): number | undefined
-
- /**
- * Returns the index of the first element in the array where predicate is true, and -1
- * otherwise.
- * @param predicate find calls predicate once for each element of the array, in ascending
- * order, until it finds one where predicate returns true. If such an element is found,
- * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
- * @param thisArg If provided, it will be used as the this value for each invocation of
- * predicate. If it is not provided, undefined is used instead.
- */
- findIndex(
- predicate: (value: number, index: number, obj: Float64Array) => boolean,
- thisArg?: any
- ): number
-
- /**
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- forEach(
- callbackfn: (value: number, index: number, array: Float64Array) => void,
- thisArg?: any
- ): void
-
- /**
- * Returns the index of the first occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- indexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the
- * resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string
-
- /**
- * Returns the index of the last occurrence of a value in an array.
- * @param searchElement The value to locate in the array.
- * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
- * search starts at index 0.
- */
- lastIndexOf(searchElement: number, fromIndex?: number): number
-
- /**
- * The length of the array.
- */
- readonly length: number
-
- /**
- * Calls a defined callback function on each element of an array, and returns an array that
- * contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the
- * callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- map(
- callbackfn: (value: number, index: number, array: Float64Array) => number,
- thisArg?: any
- ): Float64Array
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => number
- ): number
- reduce(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array. The return value of
- * the callback function is the accumulated result, and is provided as an argument in the next
- * call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
- * callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduce(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an
- * argument instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => number
- ): number
- reduceRight(
- callbackfn: (
- previousValue: number,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => number,
- initialValue: number
- ): number
-
- /**
- * Calls the specified callback function for all the elements in an array, in descending order.
- * The return value of the callback function is the accumulated result, and is provided as an
- * argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
- * the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start
- * the accumulation. The first call to the callbackfn function provides this value as an argument
- * instead of an array value.
- */
- reduceRight(
- callbackfn: (
- previousValue: U,
- currentValue: number,
- currentIndex: number,
- array: Float64Array
- ) => U,
- initialValue: U
- ): U
-
- /**
- * Reverses the elements in an Array.
- */
- reverse(): Float64Array
-
- /**
- * Sets a value or an array of values.
- * @param array A typed or untyped array of values to set.
- * @param offset The index in the current array at which the values are to be written.
- */
- set(array: ArrayLike, offset?: number): void
-
- /**
- * Returns a section of an array.
- * @param start The beginning of the specified portion of the array.
- * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
- */
- slice(start?: number, end?: number): Float64Array
-
- /**
- * Determines whether the specified callback function returns true for any element of an array.
- * @param predicate A function that accepts up to three arguments. The some method calls
- * the predicate function for each element in the array until the predicate returns a value
- * which is coercible to the Boolean value true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the predicate function.
- * If thisArg is omitted, undefined is used as the this value.
- */
- some(
- predicate: (value: number, index: number, array: Float64Array) => unknown,
- thisArg?: any
- ): boolean
-
- /**
- * Sorts an array.
- * @param compareFn Function used to determine the order of the elements. It is expected to return
- * a negative value if first argument is less than second argument, zero if they're equal and a positive
- * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
- * \`\`\`ts
- * [11,2,22,1].sort((a, b) => a - b)
- * \`\`\`
- */
- sort(compareFn?: (a: number, b: number) => number): this
-
- /**
- * at begin, inclusive, up to end, exclusive.
- * @param begin The index of the beginning of the array.
- * @param end The index of the end of the array.
- */
- subarray(begin?: number, end?: number): Float64Array
-
- toString(): string
-
- /** Returns the primitive value of the specified object. */
- valueOf(): Float64Array
-
- [index: number]: number
-}
-
-interface Float64ArrayConstructor {
- readonly prototype: Float64Array
- new (length: number): Float64Array
- new (array: ArrayLike | ArrayBufferLike): Float64Array
- new (
- buffer: ArrayBufferLike,
- byteOffset?: number,
- length?: number
- ): Float64Array
-
- /**
- * The size in bytes of each element in the array.
- */
- readonly BYTES_PER_ELEMENT: number
-
- /**
- * Returns a new array from a set of elements.
- * @param items A set of elements to include in the new array object.
- */
- of(...items: number[]): Float64Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- */
- from(arrayLike: ArrayLike): Float64Array
-
- /**
- * Creates an array from an array-like or iterable object.
- * @param arrayLike An array-like or iterable object to convert to an array.
- * @param mapfn A mapping function to call on every element of the array.
- * @param thisArg Value of 'this' used to invoke the mapfn.
- */
- from(
- arrayLike: ArrayLike,
- mapfn: (v: T, k: number) => number,
- thisArg?: any
- ): Float64Array
-}
-declare var Float64Array: Float64ArrayConstructor
-
-/////////////////////////////
-/// ECMAScript Internationalization API
-/////////////////////////////
-
-declare namespace Intl {
- interface CollatorOptions {
- usage?: string
- localeMatcher?: string
- numeric?: boolean
- caseFirst?: string
- sensitivity?: string
- ignorePunctuation?: boolean
- }
-
- interface ResolvedCollatorOptions {
- locale: string
- usage: string
- sensitivity: string
- ignorePunctuation: boolean
- collation: string
- caseFirst: string
- numeric: boolean
- }
-
- interface Collator {
- compare(x: string, y: string): number
- resolvedOptions(): ResolvedCollatorOptions
- }
- var Collator: {
- new (locales?: string | string[], options?: CollatorOptions): Collator
- (locales?: string | string[], options?: CollatorOptions): Collator
- supportedLocalesOf(
- locales: string | string[],
- options?: CollatorOptions
- ): string[]
- }
-
- interface NumberFormatOptions {
- localeMatcher?: string
- style?: string
- currency?: string
- currencyDisplay?: string
- currencySign?: string
- useGrouping?: boolean
- minimumIntegerDigits?: number
- minimumFractionDigits?: number
- maximumFractionDigits?: number
- minimumSignificantDigits?: number
- maximumSignificantDigits?: number
- }
-
- interface ResolvedNumberFormatOptions {
- locale: string
- numberingSystem: string
- style: string
- currency?: string
- currencyDisplay?: string
- minimumIntegerDigits: number
- minimumFractionDigits: number
- maximumFractionDigits: number
- minimumSignificantDigits?: number
- maximumSignificantDigits?: number
- useGrouping: boolean
- }
-
- interface NumberFormat {
- format(value: number): string
- resolvedOptions(): ResolvedNumberFormatOptions
- }
- var NumberFormat: {
- new (
- locales?: string | string[],
- options?: NumberFormatOptions
- ): NumberFormat
- (locales?: string | string[], options?: NumberFormatOptions): NumberFormat
- supportedLocalesOf(
- locales: string | string[],
- options?: NumberFormatOptions
- ): string[]
- }
-
- interface DateTimeFormatOptions {
- localeMatcher?: 'best fit' | 'lookup'
- weekday?: 'long' | 'short' | 'narrow'
- era?: 'long' | 'short' | 'narrow'
- year?: 'numeric' | '2-digit'
- month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow'
- day?: 'numeric' | '2-digit'
- hour?: 'numeric' | '2-digit'
- minute?: 'numeric' | '2-digit'
- second?: 'numeric' | '2-digit'
- timeZoneName?: 'long' | 'short'
- formatMatcher?: 'best fit' | 'basic'
- hour12?: boolean
- timeZone?: string
- }
-
- interface ResolvedDateTimeFormatOptions {
- locale: string
- calendar: string
- numberingSystem: string
- timeZone: string
- hour12?: boolean
- weekday?: string
- era?: string
- year?: string
- month?: string
- day?: string
- hour?: string
- minute?: string
- second?: string
- timeZoneName?: string
- }
-
- interface DateTimeFormat {
- format(date?: Date | number): string
- resolvedOptions(): ResolvedDateTimeFormatOptions
- }
- var DateTimeFormat: {
- new (
- locales?: string | string[],
- options?: DateTimeFormatOptions
- ): DateTimeFormat
- (
- locales?: string | string[],
- options?: DateTimeFormatOptions
- ): DateTimeFormat
- supportedLocalesOf(
- locales: string | string[],
- options?: DateTimeFormatOptions
- ): string[]
- }
-}
-
-interface String {
- /**
- * Determines whether two strings are equivalent in the current or specified locale.
- * @param that String to compare to target string
- * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details.
- * @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
- */
- localeCompare(
- that: string,
- locales?: string | string[],
- options?: Intl.CollatorOptions
- ): number
-}
-
-interface Number {
- /**
- * Converts a number to a string by using the current or specified locale.
- * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
- * @param options An object that contains one or more properties that specify comparison options.
- */
- toLocaleString(
- locales?: string | string[],
- options?: Intl.NumberFormatOptions
- ): string
-}
-
-interface Date {
- /**
- * Converts a date and time to a string by using the current or specified locale.
- * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
- * @param options An object that contains one or more properties that specify comparison options.
- */
- toLocaleString(
- locales?: string | string[],
- options?: Intl.DateTimeFormatOptions
- ): string
- /**
- * Converts a date to a string by using the current or specified locale.
- * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
- * @param options An object that contains one or more properties that specify comparison options.
- */
- toLocaleDateString(
- locales?: string | string[],
- options?: Intl.DateTimeFormatOptions
- ): string
-
- /**
- * Converts a time to a string by using the current or specified locale.
- * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
- * @param options An object that contains one or more properties that specify comparison options.
- */
- toLocaleTimeString(
- locales?: string | string[],
- options?: Intl.DateTimeFormatOptions
- ): string
-}
-`,
-}
diff --git a/components/code-panel/types-import.ts b/components/code-panel/types-import.ts
deleted file mode 100644
index 63d7eb7e1..000000000
--- a/components/code-panel/types-import.ts
+++ /dev/null
@@ -1,3469 +0,0 @@
-/* eslint-disable */
-
-// HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
-// ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/type-gen.js
-// ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
-
-export default {
- name: 'types.ts',
- content: `
-
-type DeepPartial = {
- [P in keyof T]?: DeepPartial;
-};
-
-
-
-enum ShapeType {
- Dot = 'dot',
- Ellipse = 'ellipse',
- Line = 'line',
- Ray = 'ray',
- Polyline = 'polyline',
- Rectangle = 'rectangle',
- Draw = 'draw',
- Arrow = 'arrow',
- Text = 'text',
- Group = 'group',
-}
-
-enum ColorStyle {
- White = 'White',
- LightGray = 'LightGray',
- Gray = 'Gray',
- Black = 'Black',
- Green = 'Green',
- Cyan = 'Cyan',
- Blue = 'Blue',
- Indigo = 'Indigo',
- Violet = 'Violet',
- Red = 'Red',
- Orange = 'Orange',
- Yellow = 'Yellow',
-}
-
-enum SizeStyle {
- Small = 'Small',
- Medium = 'Medium',
- Large = 'Large',
-}
-
-enum DashStyle {
- Draw = 'Draw',
- Solid = 'Solid',
- Dashed = 'Dashed',
- Dotted = 'Dotted',
-}
-
-enum FontSize {
- Small = 'Small',
- Medium = 'Medium',
- Large = 'Large',
- ExtraLarge = 'ExtraLarge',
-}
-
-type Theme = 'dark' | 'light'
-
-type ShapeStyles = {
- color: ColorStyle
- size: SizeStyle
- dash: DashStyle
- isFilled: boolean
-}
-
-interface BaseShape {
- id: string
- type: ShapeType
- parentId: string
- childIndex: number
- name: string
- point: number[]
- style: ShapeStyles
- rotation: number
- children?: string[]
- bindings?: Record
- handles?: Record
- isLocked?: boolean
- isHidden?: boolean
- isEditing?: boolean
- isGenerated?: boolean
- isAspectRatioLocked?: boolean
-}
-
-interface DotShape extends BaseShape {
- type: ShapeType.Dot
-}
-
-interface EllipseShape extends BaseShape {
- type: ShapeType.Ellipse
- radiusX: number
- radiusY: number
-}
-
-interface LineShape extends BaseShape {
- type: ShapeType.Line
- direction: number[]
-}
-
-interface RayShape extends BaseShape {
- type: ShapeType.Ray
- direction: number[]
-}
-
-interface PolylineShape extends BaseShape {
- type: ShapeType.Polyline
- points: number[][]
-}
-
-interface RectangleShape extends BaseShape {
- type: ShapeType.Rectangle
- size: number[]
- radius: number
-}
-
-interface DrawShape extends BaseShape {
- type: ShapeType.Draw
- points: number[][]
-}
-
-interface ArrowShape extends BaseShape {
- type: ShapeType.Arrow
- handles: Record
- bend: number
- decorations?: {
- start: Decoration
- end: Decoration
- middle: Decoration
- }
-}
-
-interface TextShape extends BaseShape {
- type: ShapeType.Text
- text: string
- scale: number
-}
-
-interface GroupShape extends BaseShape {
- type: ShapeType.Group
- children: string[]
- size: number[]
-}
-
-type ShapeProps = {
- [P in keyof T]?: P extends 'style' ? Partial : T[P]
-}
-
-interface MutableShapes {
- [ShapeType.Dot]: DotShape
- [ShapeType.Ellipse]: EllipseShape
- [ShapeType.Line]: LineShape
- [ShapeType.Ray]: RayShape
- [ShapeType.Polyline]: PolylineShape
- [ShapeType.Draw]: DrawShape
- [ShapeType.Rectangle]: RectangleShape
- [ShapeType.Arrow]: ArrowShape
- [ShapeType.Text]: TextShape
- [ShapeType.Group]: GroupShape
-}
-
-type MutableShape = MutableShapes[keyof MutableShapes]
-
-type Shapes = { [K in keyof MutableShapes]: Readonly }
-
-type Shape = Readonly
-
-type ShapeByType = Shapes[T]
-
-type IsParent = 'children' extends RequiredKeys ? T : never
-
-type ParentShape = {
- [K in keyof MutableShapes]: IsParent
-}[keyof MutableShapes]
-
-type ParentTypes = ParentShape['type'] & 'page'
-
-enum Decoration {
- Arrow = 'Arrow',
-}
-
-interface ShapeBinding {
- id: string
- index: number
- point: number[]
-}
-
-interface ShapeHandle {
- id: string
- index: number
- point: number[]
-}
-
-interface CodeFile {
- id: string
- name: string
- code: string
-}
-
-interface CodeError {
- message: string
- line: number
- column: number
-}
-
-interface CodeResult {
- shapes: Shape[]
- controls: CodeControl[]
- error: CodeError
-}
-
-interface ShapeTreeNode {
- shape: Shape
- children: ShapeTreeNode[]
- isEditing: boolean
- isHovered: boolean
- isSelected: boolean
- isDarkMode: boolean
- isCurrentParent: boolean
-}
-
-/* -------------------------------------------------- */
-/* Editor UI */
-/* -------------------------------------------------- */
-
-interface PointerInfo {
- target: string
- pointerId: number
- origin: number[]
- point: number[]
- pressure: number
- shiftKey: boolean
- ctrlKey: boolean
- metaKey: boolean
- altKey: boolean
-}
-
-interface KeyboardInfo {
- key: string
- keys: string[]
- shiftKey: boolean
- ctrlKey: boolean
- metaKey: boolean
- altKey: boolean
-}
-
-enum Edge {
- Top = 'top_edge',
- Right = 'right_edge',
- Bottom = 'bottom_edge',
- Left = 'left_edge',
-}
-
-enum Corner {
- TopLeft = 'top_left_corner',
- TopRight = 'top_right_corner',
- BottomRight = 'bottom_right_corner',
- BottomLeft = 'bottom_left_corner',
-}
-
-interface Bounds {
- minX: number
- minY: number
- maxX: number
- maxY: number
- width: number
- height: number
- rotation?: number
-}
-
-interface RotatedBounds extends Bounds {
- rotation: number
-}
-
-interface ShapeBounds extends Bounds {
- id: string
-}
-
-interface PointSnapshot extends Bounds {
- nx: number
- nmx: number
- ny: number
- nmy: number
-}
-
-interface BoundsSnapshot extends PointSnapshot {
- nw: number
- nh: number
-}
-
-type ShapeSpecificProps = Pick<
- T,
- Difference
->
-
-type ShapeIndicatorProps = ShapeSpecificProps
-
-type ShapeUtil = {
- create(props: Partial): K
- getBounds(shape: K): Bounds
- hitTest(shape: K, test: number[]): boolean
- hitTestBounds(shape: K, bounds: Bounds): boolean
- rotate(shape: K): K
- translate(shape: K, delta: number[]): K
- scale(shape: K, scale: number): K
- stretch(shape: K, scaleX: number, scaleY: number): K
- render(shape: K): JSX.Element
-}
-
-enum MoveType {
- Backward,
- Forward,
- ToFront,
- ToBack,
-}
-
-enum AlignType {
- Top,
- CenterVertical,
- Bottom,
- Left,
- CenterHorizontal,
- Right,
-}
-
-enum StretchType {
- Horizontal,
- Vertical,
-}
-
-enum DistributeType {
- Horizontal,
- Vertical,
-}
-
-interface BezierCurveSegment {
- start: number[]
- tangentStart: number[]
- normalStart: number[]
- pressureStart: number
- end: number[]
- tangentEnd: number[]
- normalEnd: number[]
- pressureEnd: number
-}
-
-/* -------------------------------------------------- */
-/* Code Editor */
-/* -------------------------------------------------- */
-
-enum ControlType {
- Number = 'number',
- Vector = 'vector',
- Text = 'text',
- Select = 'select',
-}
-
-interface BaseCodeControl {
- id: string
- type: ControlType
- label: string
-}
-
-interface NumberCodeControl extends BaseCodeControl {
- type: ControlType.Number
- value: number
- min?: number
- max?: number
- step?: number
- format?: (value: number) => number
-}
-
-interface VectorCodeControl extends BaseCodeControl {
- type: ControlType.Vector
- value: number[]
- min?: number
- max?: number
- step?: number
- isNormalized?: boolean
- format?: (value: number[]) => number[]
-}
-
-interface TextCodeControl extends BaseCodeControl {
- type: ControlType.Text
- value: string
- format?: (value: string) => string
-}
-
-interface SelectCodeControl
- extends BaseCodeControl {
- type: ControlType.Select
- value: T
- options: T[]
- format?: (string: T) => string
-}
-
-type CodeControl =
- | NumberCodeControl
- | VectorCodeControl
- | TextCodeControl
-
-type PropsOfType> = {
- [K in keyof T]: T[K] extends boolean ? K : never
-}[keyof T]
-
-type Mutable = { -readonly [K in keyof T]: T[K] }
-
-interface ShapeUtility {
- // Default properties when creating a new shape
- defaultProps: K
-
- // A cache for the computed bounds of this kind of shape.
- boundsCache: WeakMap
-
- // Whether to show transform controls when this shape is selected.
- canTransform: boolean
-
- // Whether the shape's aspect ratio can change.
- canChangeAspectRatio: boolean
-
- // Whether the shape's style can be filled.
- canStyleFill: boolean
-
- // Whether the shape may be edited in an editing mode
- canEdit: boolean
-
- // Whether the shape is a foreign object.
- isForeignObject: boolean
-
- // Whether the shape can contain other shapes.
- isParent: boolean
-
- // Whether the shape is only shown when on hovered.
- isShy: boolean
-
- // Create a new shape.
- create(this: ShapeUtility, props: Partial): K
-
- // Update a shape's styles
- applyStyles(
- this: ShapeUtility,
- shape: Mutable,
- style: Partial
- ): ShapeUtility
-
- translateBy(
- this: ShapeUtility,
- shape: Mutable,
- point: number[]
- ): ShapeUtility
-
- translateTo(
- this: ShapeUtility,
- shape: Mutable,
- point: number[]
- ): ShapeUtility
-
- rotateBy(
- this: ShapeUtility,
- shape: Mutable,
- rotation: number
- ): ShapeUtility
-
- rotateTo(
- this: ShapeUtility,
- shape: Mutable,
- rotation: number,
- delta: number
- ): ShapeUtility
-
- // Transform to fit a new bounding box when more than one shape is selected.
- transform(
- this: ShapeUtility,
- shape: Mutable,
- bounds: Bounds,
- info: {
- type: Edge | Corner
- initialShape: K
- scaleX: number
- scaleY: number
- transformOrigin: number[]
- }
- ): ShapeUtility
-
- // Transform a single shape to fit a new bounding box.
- transformSingle(
- this: ShapeUtility,
- shape: Mutable,
- bounds: Bounds,
- info: {
- type: Edge | Corner
- initialShape: K
- scaleX: number
- scaleY: number
- transformOrigin: number[]
- }
- ): ShapeUtility
-
- setProperty(
- this: ShapeUtility,
- shape: Mutable,
- prop: P,
- value: K[P]
- ): ShapeUtility
-
- // Respond when any child of this shape changes.
- onChildrenChange(
- this: ShapeUtility,
- shape: Mutable