Steve Ruiz 3 роки тому
джерело
коміт
0d564c1501
41 змінених файлів з 15684 додано та 36054 видалено
  1. 3
    10
      package.json
  2. 0
    21
      packages/intersect/LICENSE
  3. 0
    3
      packages/intersect/README.md
  4. 0
    51
      packages/intersect/package.json
  5. 0
    65
      packages/intersect/scripts/build.js
  6. 0
    31
      packages/intersect/scripts/dev.js
  7. 0
    28
      packages/intersect/scripts/pre-dev.js
  8. 0
    1147
      packages/intersect/src/index.ts
  9. 0
    24
      packages/intersect/tsconfig.build.json
  10. 0
    18
      packages/intersect/tsconfig.json
  11. 0
    21
      packages/svg/LICENSE
  12. 0
    3
      packages/svg/README.md
  13. 0
    48
      packages/svg/package.json
  14. 0
    65
      packages/svg/scripts/build.js
  15. 0
    31
      packages/svg/scripts/dev.js
  16. 0
    28
      packages/svg/scripts/pre-dev.js
  17. 0
    63
      packages/svg/src/index.ts
  18. 0
    24
      packages/svg/tsconfig.build.json
  19. 0
    18
      packages/svg/tsconfig.json
  20. 5
    23
      packages/tldraw/package.json
  21. 1
    1
      packages/tldraw/src/state/session/sessions/arrow/arrow.session.ts
  22. 3
    3
      packages/tldraw/src/test/migration.spec.ts
  23. 0
    31877
      packages/tldraw/src/test/old-doc.json
  24. 15572
    0
      packages/tldraw/src/test/old-doc.ts
  25. 1
    2
      packages/tldraw/tsconfig.build.json
  26. 3
    5
      packages/tldraw/tsconfig.json
  27. 0
    21
      packages/vec/LICENSE
  28. 0
    3
      packages/vec/README.md
  29. 0
    48
      packages/vec/package.json
  30. 0
    67
      packages/vec/scripts/build.js
  31. 0
    28
      packages/vec/scripts/dev.js
  32. 0
    27
      packages/vec/scripts/pre-dev.js
  33. 0
    520
      packages/vec/src/index.ts
  34. 0
    19
      packages/vec/tsconfig.build.json
  35. 0
    15
      packages/vec/tsconfig.json
  36. 1
    1
      packages/www/public/sw.js
  37. 1
    1
      packages/www/public/sw.js.map
  38. 0
    0
      packages/www/public/worker-7ryd46WBzPy7BjiSHTKb0.js
  39. 21
    7
      packages/www/tsconfig.json
  40. 1
    7
      tsconfig.json
  41. 72
    1680
      yarn.lock

+ 3
- 10
package.json Переглянути файл

@@ -11,9 +11,6 @@
11 11
   "workspaces": [
12 12
     "packages/tldraw",
13 13
     "packages/dev",
14
-    "packages/vec",
15
-    "packages/svg",
16
-    "packages/intersect",
17 14
     "packages/www"
18 15
   ],
19 16
   "scripts": {
@@ -23,7 +20,7 @@
23 20
     "start": "lerna run start:pre && lerna run start --stream --parallel",
24 21
     "start:www": "yarn build:packages && lerna run start --parallel & cd packages/www && yarn dev",
25 22
     "build": "yarn build:packages && cd packages/www && yarn build",
26
-    "build:packages": "cd packages/vec && yarn build && cd ../intersect && yarn build && cd ../tldraw && yarn build",
23
+    "build:packages": "cd packages/tldraw && yarn build",
27 24
     "publish:patch": "yarn build:packages && lerna publish patch",
28 25
     "docs": "lerna run docs",
29 26
     "docs:watch": "lerna run docs:watch"
@@ -32,7 +29,7 @@
32 29
     "@swc-node/jest": "^1.3.3",
33 30
     "@testing-library/jest-dom": "^5.14.1",
34 31
     "@testing-library/react": "^12.0.0",
35
-    "@types/jest": "^27.0.1",
32
+    "@types/jest": "^27.0.2",
36 33
     "@types/node": "^15.0.1",
37 34
     "@types/react": "^17.0.33",
38 35
     "@types/react-dom": "^17.0.10",
@@ -41,7 +38,7 @@
41 38
     "eslint": "^7.32.0",
42 39
     "fake-indexeddb": "^3.1.3",
43 40
     "init-package-json": "^2.0.4",
44
-    "jest": "^27.1.0",
41
+    "jest": "^27.3.1",
45 42
     "lerna": "^3.22.1",
46 43
     "resize-observer-polyfill": "^1.5.1",
47 44
     "tslib": "^2.3.0",
@@ -73,14 +70,10 @@
73 70
     ],
74 71
     "testEnvironment": "jsdom",
75 72
     "modulePathIgnorePatterns": [
76
-      "<rootDir>/packages/vec/dist/",
77
-      "<rootDir>/packages/intersect/dist/",
78 73
       "<rootDir>/packages/tldraw/dist/",
79 74
       "<rootDir>/packages/tldraw/test-utils/"
80 75
     ],
81 76
     "moduleNameMapper": {
82
-      "@tldraw/vec": "<rootDir>/packages/vec/src",
83
-      "@tldraw/intersect": "<rootDir>/packages/intersect/src",
84 77
       "@tldraw/tldraw": "<rootDir>/packages/tldraw/src",
85 78
       "\\~(.*)": "<rootDir>/packages/tldraw/src/$1"
86 79
     }

+ 0
- 21
packages/intersect/LICENSE Переглянути файл

@@ -1,21 +0,0 @@
1
-MIT License
2
-
3
-Copyright (c) 2021 Stephen Ruiz Ltd
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.

+ 0
- 3
packages/intersect/README.md Переглянути файл

@@ -1,3 +0,0 @@
1
-# @tldraw/intersect
2
-
3
-Intersection utilities.

+ 0
- 51
packages/intersect/package.json Переглянути файл

@@ -1,51 +0,0 @@
1
-{
2
-  "name": "@tldraw/intersect",
3
-  "version": "0.0.132",
4
-  "private": false,
5
-  "description": "Intersection utilities for tldraw.",
6
-  "author": "@steveruizok",
7
-  "repository": {
8
-    "type": "git",
9
-    "url": "git+https://github.com/tldraw/tldraw.git",
10
-    "directory": "packages/intersect"
11
-  },
12
-  "license": "MIT",
13
-  "keywords": [],
14
-  "files": [
15
-    "dist/**/*"
16
-  ],
17
-  "sideEffects": false,
18
-  "main": "./dist/cjs/index.js",
19
-  "module": "./dist/esm/index.js",
20
-  "types": "./dist/types/index.d.ts",
21
-  "typings": "./dist/types/index.d.ts",
22
-  "scripts": {
23
-    "start:pre": "node scripts/pre-dev && yarn types:pre",
24
-    "start:utils": "node scripts/dev & yarn types:dev",
25
-    "build": "node scripts/build && yarn types:build",
26
-    "types:pre": "tsc",
27
-    "types:dev": "tsc --watch",
28
-    "types:build": "tsc --project tsconfig.build.json",
29
-    "lint": "eslint src/ --ext .ts,.tsx",
30
-    "clean": "rm -rf dist",
31
-    "ts-node": "ts-node",
32
-    "docs": "typedoc",
33
-    "docs:watch": "typedoc --watch"
34
-  },
35
-  "devDependencies": {
36
-    "@types/jest": "^27.0.1",
37
-    "@types/node": "^16.7.10",
38
-    "@typescript-eslint/eslint-plugin": "^4.30.0",
39
-    "@typescript-eslint/parser": "^4.30.0",
40
-    "esbuild": "^0.13.8",
41
-    "eslint": "^7.32.0",
42
-    "lerna": "^4.0.0",
43
-    "tslib": "^2.3.1",
44
-    "typedoc": "^0.22.3",
45
-    "typescript": "^4.4.2"
46
-  },
47
-  "dependencies": {
48
-    "@tldraw/vec": "^0.0.132"
49
-  },
50
-  "gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
51
-}

+ 0
- 65
packages/intersect/scripts/build.js Переглянути файл

@@ -1,65 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-const { gzip } = require('zlib')
5
-
6
-const name = process.env.npm_package_name || ''
7
-
8
-async function main() {
9
-  if (fs.existsSync('./dist')) {
10
-    fs.rmSync('./dist', { recursive: true }, (e) => {
11
-      if (e) {
12
-        throw e
13
-      }
14
-    })
15
-  }
16
-
17
-  try {
18
-    esbuild.buildSync({
19
-      entryPoints: ['./src/index.ts'],
20
-      outdir: 'dist/cjs',
21
-      minify: true,
22
-      bundle: true,
23
-      format: 'cjs',
24
-      target: 'es6',
25
-      jsxFactory: 'React.createElement',
26
-      jsxFragment: 'React.Fragment',
27
-      tsconfig: './tsconfig.build.json',
28
-      external: ['react', 'react-dom'],
29
-    })
30
-
31
-    const esmResult = esbuild.buildSync({
32
-      entryPoints: ['./src/index.ts'],
33
-      outdir: 'dist/esm',
34
-      minify: true,
35
-      bundle: true,
36
-      format: 'esm',
37
-      target: 'es6',
38
-      tsconfig: './tsconfig.build.json',
39
-      jsxFactory: 'React.createElement',
40
-      jsxFragment: 'React.Fragment',
41
-      external: ['react', 'react-dom'],
42
-      metafile: true,
43
-    })
44
-
45
-    let esmSize = 0
46
-    Object.values(esmResult.metafile.outputs).forEach((output) => {
47
-      esmSize += output.bytes
48
-    })
49
-
50
-    fs.readFile('./dist/esm/index.js', (_err, data) => {
51
-      gzip(data, (_err, result) => {
52
-        console.log(
53
-          `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
54
-            result.length / 1000
55
-          ).toFixed(2)}kb minified)`
56
-        )
57
-      })
58
-    })
59
-  } catch (e) {
60
-    console.log(`× ${name}: Build failed due to an error.`)
61
-    console.log(e)
62
-  }
63
-}
64
-
65
-main()

+ 0
- 31
packages/intersect/scripts/dev.js Переглянути файл

@@ -1,31 +0,0 @@
1
-/* eslint-disable */
2
-const esbuild = require('esbuild')
3
-
4
-const name = process.env.npm_package_name || ''
5
-
6
-async function main() {
7
-  esbuild.build({
8
-    entryPoints: ['./src/index.ts'],
9
-    outdir: 'dist/cjs',
10
-    minify: false,
11
-    bundle: true,
12
-    format: 'cjs',
13
-    target: 'es6',
14
-    jsxFactory: 'React.createElement',
15
-    jsxFragment: 'React.Fragment',
16
-    tsconfig: './tsconfig.json',
17
-    external: ['react', 'react-dom'],
18
-    incremental: true,
19
-    watch: {
20
-      onRebuild(error) {
21
-        if (error) {
22
-          console.log(`× ${name}: An error in prevented the rebuild.`)
23
-          return
24
-        }
25
-        console.log(`✔ ${name}: Rebuilt.`)
26
-      },
27
-    },
28
-  })
29
-}
30
-
31
-main()

+ 0
- 28
packages/intersect/scripts/pre-dev.js Переглянути файл

@@ -1,28 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-
5
-async function main() {
6
-  if (fs.existsSync('./dist')) {
7
-    fs.rmSync('./dist', { recursive: true }, (e) => {
8
-      if (e) {
9
-        throw e
10
-      }
11
-    })
12
-  }
13
-
14
-  esbuild.build({
15
-    entryPoints: ['./src/index.ts'],
16
-    outdir: 'dist/cjs',
17
-    minify: false,
18
-    bundle: true,
19
-    format: 'cjs',
20
-    target: 'es6',
21
-    jsxFactory: 'React.createElement',
22
-    jsxFragment: 'React.Fragment',
23
-    tsconfig: './tsconfig.json',
24
-    external: ['react', 'react-dom'],
25
-  })
26
-}
27
-
28
-main()

+ 0
- 1147
packages/intersect/src/index.ts
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 0
- 24
packages/intersect/tsconfig.build.json Переглянути файл

@@ -1,24 +0,0 @@
1
-{
2
-  "extends": "./tsconfig.json",
3
-  "exclude": [
4
-    "node_modules",
5
-    "**/*.test.tsx",
6
-    "**/*.test.ts",
7
-    "**/*.spec.tsx",
8
-    "**/*.spec.ts",
9
-    "src/test",
10
-    "dist",
11
-    "docs"
12
-  ],
13
-  "compilerOptions": {
14
-    "composite": false,
15
-    "incremental": false,
16
-    "declarationMap": false,
17
-    "sourceMap": false,
18
-    "emitDeclarationOnly": true,
19
-    "paths": {
20
-      "@tldraw/vec": ["../vec"]
21
-    }
22
-  },
23
-  "references": [{ "path": "../vec" }]
24
-}

+ 0
- 18
packages/intersect/tsconfig.json Переглянути файл

@@ -1,18 +0,0 @@
1
-{
2
-  "extends": "../../tsconfig.base.json",
3
-  "include": ["src"],
4
-  "exclude": ["node_modules", "dist", "docs"],
5
-  "compilerOptions": {
6
-    "outDir": "./dist/types",
7
-    "rootDir": "src",
8
-    "baseUrl": "src",
9
-    "paths": {
10
-      "@tldraw/vec": ["../vec"]
11
-    }
12
-  },
13
-  "references": [{ "path": "../vec" }],
14
-  "typedocOptions": {
15
-    "entryPoints": ["src/index.ts"],
16
-    "out": "docs"
17
-  }
18
-}

+ 0
- 21
packages/svg/LICENSE Переглянути файл

@@ -1,21 +0,0 @@
1
-MIT License
2
-
3
-Copyright (c) 2021 Stephen Ruiz Ltd
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.

+ 0
- 3
packages/svg/README.md Переглянути файл

@@ -1,3 +0,0 @@
1
-# @tldraw/svg
2
-
3
-SVG utilities.

+ 0
- 48
packages/svg/package.json Переглянути файл

@@ -1,48 +0,0 @@
1
-{
2
-  "name": "@tldraw/svg",
3
-  "version": "0.0.132",
4
-  "private": false,
5
-  "description": "SVG utilities for tldraw.",
6
-  "author": "@steveruizok",
7
-  "repository": {
8
-    "type": "git",
9
-    "url": "git+https://github.com/tldraw/tldraw.git",
10
-    "directory": "packages/vec"
11
-  },
12
-  "license": "MIT",
13
-  "keywords": [],
14
-  "files": [
15
-    "dist/**/*"
16
-  ],
17
-  "sideEffects": false,
18
-  "main": "./dist/cjs/index.js",
19
-  "module": "./dist/esm/index.js",
20
-  "types": "./dist/types/index.d.ts",
21
-  "typings": "./dist/types/index.d.ts",
22
-  "scripts": {
23
-    "start:pre": "node scripts/pre-dev && yarn types:pre",
24
-    "start:utils": "node scripts/dev & yarn types:dev",
25
-    "build": "node scripts/build && yarn types:build",
26
-    "types:pre": "tsc",
27
-    "types:dev": "tsc --watch",
28
-    "types:build": "tsc --project tsconfig.build.json",
29
-    "lint": "eslint src/ --ext .ts,.tsx",
30
-    "clean": "rm -rf dist",
31
-    "ts-node": "ts-node",
32
-    "docs": "typedoc",
33
-    "docs:watch": "typedoc --watch"
34
-  },
35
-  "devDependencies": {
36
-    "@types/jest": "^27.0.1",
37
-    "@types/node": "^16.7.10",
38
-    "@typescript-eslint/eslint-plugin": "^4.30.0",
39
-    "@typescript-eslint/parser": "^4.30.0",
40
-    "esbuild": "^0.13.8",
41
-    "eslint": "^7.32.0",
42
-    "lerna": "^4.0.0",
43
-    "tslib": "^2.3.1",
44
-    "typedoc": "^0.22.3",
45
-    "typescript": "^4.4.2"
46
-  },
47
-  "gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
48
-}

+ 0
- 65
packages/svg/scripts/build.js Переглянути файл

@@ -1,65 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-const { gzip } = require('zlib')
5
-
6
-const name = process.env.npm_package_name || ''
7
-
8
-async function main() {
9
-  if (fs.existsSync('./dist')) {
10
-    fs.rmSync('./dist', { recursive: true }, (e) => {
11
-      if (e) {
12
-        throw e
13
-      }
14
-    })
15
-  }
16
-
17
-  try {
18
-    esbuild.buildSync({
19
-      entryPoints: ['./src/index.ts'],
20
-      outdir: 'dist/cjs',
21
-      minify: true,
22
-      bundle: true,
23
-      format: 'cjs',
24
-      target: 'es6',
25
-      jsxFactory: 'React.createElement',
26
-      jsxFragment: 'React.Fragment',
27
-      tsconfig: './tsconfig.build.json',
28
-      external: ['react', 'react-dom'],
29
-    })
30
-
31
-    const esmResult = esbuild.buildSync({
32
-      entryPoints: ['./src/index.ts'],
33
-      outdir: 'dist/esm',
34
-      minify: true,
35
-      bundle: true,
36
-      format: 'esm',
37
-      target: 'es6',
38
-      tsconfig: './tsconfig.build.json',
39
-      jsxFactory: 'React.createElement',
40
-      jsxFragment: 'React.Fragment',
41
-      external: ['react', 'react-dom'],
42
-      metafile: true,
43
-    })
44
-
45
-    let esmSize = 0
46
-    Object.values(esmResult.metafile.outputs).forEach((output) => {
47
-      esmSize += output.bytes
48
-    })
49
-
50
-    fs.readFile('./dist/esm/index.js', (_err, data) => {
51
-      gzip(data, (_err, result) => {
52
-        console.log(
53
-          `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
54
-            result.length / 1000
55
-          ).toFixed(2)}kb minified)`
56
-        )
57
-      })
58
-    })
59
-  } catch (e) {
60
-    console.log(`× ${name}: Build failed due to an error.`)
61
-    console.log(e)
62
-  }
63
-}
64
-
65
-main()

+ 0
- 31
packages/svg/scripts/dev.js Переглянути файл

@@ -1,31 +0,0 @@
1
-/* eslint-disable */
2
-const esbuild = require('esbuild')
3
-
4
-const name = process.env.npm_package_name || ''
5
-
6
-async function main() {
7
-  esbuild.build({
8
-    entryPoints: ['./src/index.ts'],
9
-    outdir: 'dist/cjs',
10
-    minify: false,
11
-    bundle: true,
12
-    format: 'cjs',
13
-    target: 'es6',
14
-    jsxFactory: 'React.createElement',
15
-    jsxFragment: 'React.Fragment',
16
-    tsconfig: './tsconfig.json',
17
-    external: ['react', 'react-dom'],
18
-    incremental: true,
19
-    watch: {
20
-      onRebuild(error) {
21
-        if (error) {
22
-          console.log(`× ${name}: An error in prevented the rebuild.`)
23
-          return
24
-        }
25
-        console.log(`✔ ${name}: Rebuilt.`)
26
-      },
27
-    },
28
-  })
29
-}
30
-
31
-main()

+ 0
- 28
packages/svg/scripts/pre-dev.js Переглянути файл

@@ -1,28 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-
5
-async function main() {
6
-  if (fs.existsSync('./dist')) {
7
-    fs.rmSync('./dist', { recursive: true }, (e) => {
8
-      if (e) {
9
-        throw e
10
-      }
11
-    })
12
-  }
13
-
14
-  esbuild.build({
15
-    entryPoints: ['./src/index.ts'],
16
-    outdir: 'dist/cjs',
17
-    minify: false,
18
-    bundle: true,
19
-    format: 'cjs',
20
-    target: 'es6',
21
-    jsxFactory: 'React.createElement',
22
-    jsxFragment: 'React.Fragment',
23
-    tsconfig: './tsconfig.json',
24
-    external: ['react', 'react-dom'],
25
-  })
26
-}
27
-
28
-main()

+ 0
- 63
packages/svg/src/index.ts Переглянути файл

@@ -1,63 +0,0 @@
1
-// General
2
-function angle(A: number[], B: number[]): number {
3
-  return Math.atan2(B[1] - A[1], B[0] - A[0])
4
-}
5
-
6
-function shortAngleDist(A: number, B: number) {
7
-  const max = Math.PI * 2
8
-  const da = (B - A) % max
9
-  return ((2 * da) % max) - da
10
-}
11
-
12
-function getArcLength(C: number[], r: number, A: number[], B: number[]): number {
13
-  return r * (2 * Math.PI) * (shortAngleDist(angle(C, A), angle(C, B)) / (2 * Math.PI))
14
-}
15
-
16
-export const moveTo = (v: number[]): string => {
17
-  return `M ${v} `
18
-}
19
-
20
-export const lineTo = (...v: number[][]): string => {
21
-  return `L ${v.join(' ')} `
22
-}
23
-
24
-export const hLineTo = (v: number[]): string => {
25
-  return `H ${v} `
26
-}
27
-
28
-export const vLineTo = (v: number[]): string => {
29
-  return `V ${v} `
30
-}
31
-
32
-export const bezierTo = (A: number[], B: number[], C: number[]): string => {
33
-  return `C ${A} ${B} ${C} `
34
-}
35
-
36
-export const arcTo = (C: number[], r: number, A: number[], B: number[]): string => {
37
-  return [moveTo(A), 'A', r, r, 0, 0, getArcLength(C, r, A, B) > 0 ? '1' : '0', B[0], B[1]].join(
38
-    ' '
39
-  )
40
-}
41
-
42
-export const rectTo = (A: number[]): string => {
43
-  return `R ${A}`
44
-}
45
-
46
-export const ellipse = (A: number[], r: number): string => {
47
-  return `M ${A[0] - r},${A[1]}
48
-      a ${r},${r} 0 1,0 ${r * 2},0
49
-      a ${r},${r} 0 1,0 -${r * 2},0 `
50
-}
51
-
52
-export const line = (a: number[], ...pts: number[][]): string => {
53
-  return moveTo(a) + lineTo(...pts)
54
-}
55
-
56
-export const closePath = (): string => {
57
-  return 'Z'
58
-}
59
-
60
-export const getPointAtLength = (path: SVGPathElement, length: number): number[] => {
61
-  const point = path.getPointAtLength(length)
62
-  return [point.x, point.y]
63
-}

+ 0
- 24
packages/svg/tsconfig.build.json Переглянути файл

@@ -1,24 +0,0 @@
1
-{
2
-  "extends": "./tsconfig.json",
3
-  "exclude": [
4
-    "node_modules",
5
-    "**/*.test.tsx",
6
-    "**/*.test.ts",
7
-    "**/*.spec.tsx",
8
-    "**/*.spec.ts",
9
-    "src/test",
10
-    "dist",
11
-    "docs"
12
-  ],
13
-  "compilerOptions": {
14
-    "composite": false,
15
-    "incremental": false,
16
-    "declarationMap": false,
17
-    "sourceMap": false,
18
-    "emitDeclarationOnly": true,
19
-    "paths": {
20
-      "@tldraw/vec": ["../vec"]
21
-    }
22
-  },
23
-  "references": [{ "path": "../vec" }]
24
-}

+ 0
- 18
packages/svg/tsconfig.json Переглянути файл

@@ -1,18 +0,0 @@
1
-{
2
-  "extends": "../../tsconfig.base.json",
3
-  "include": ["src"],
4
-  "exclude": ["node_modules", "dist", "docs"],
5
-  "compilerOptions": {
6
-    "outDir": "./dist/types",
7
-    "rootDir": "src",
8
-    "baseUrl": "src",
9
-    "paths": {
10
-      "@tldraw/vec": ["../vec"]
11
-    }
12
-  },
13
-  "references": [{ "path": "../vec" }],
14
-  "typedocOptions": {
15
-    "entryPoints": ["src/index.ts"],
16
-    "out": "docs"
17
-  }
18
-}

+ 5
- 23
packages/tldraw/package.json Переглянути файл

@@ -19,7 +19,6 @@
19 19
   "types": "./dist/types/index.d.ts",
20 20
   "typings": "./dist/types/index.d.ts",
21 21
   "scripts": {
22
-    "start:pre": "node scripts/pre-dev && yarn types:pre",
23 22
     "start": "node scripts/dev & yarn types:dev",
24 23
     "build": "node scripts/build && yarn types:build",
25 24
     "types:pre": "tsc",
@@ -32,24 +31,7 @@
32 31
     "docs:watch": "typedoc --watch"
33 32
   },
34 33
   "devDependencies": {
35
-    "@babel/core": "^7.15.5",
36
-    "@babel/preset-env": "^7.15.4",
37
-    "@types/jest": "^27.0.1",
38
-    "@types/node": "^16.7.10",
39
-    "@types/react": "^17.0.33",
40
-    "@types/react-dom": "^17.0.10",
41
-    "@typescript-eslint/eslint-plugin": "^4.30.0",
42
-    "@typescript-eslint/parser": "^4.30.0",
43
-    "esbuild": "^0.13.8",
44
-    "eslint": "^7.32.0",
45
-    "lerna": "^4.0.0",
46
-    "react": ">=16.8",
47
-    "react-dom": "^16.8 || ^17.0",
48
-    "ts-node": "^10.2.1",
49
-    "tsconfig-replace-paths": "^0.0.5",
50
-    "tslib": "^2.3.1",
51
-    "typedoc": "^0.22.3",
52
-    "typescript": "^4.4.2"
34
+    "tsconfig-replace-paths": "^0.0.5"
53 35
   },
54 36
   "peerDependencies": {
55 37
     "react": ">=16.8",
@@ -66,12 +48,12 @@
66 48
     "@radix-ui/react-tooltip": "^0.1.1",
67 49
     "@stitches/core": "^1.2.5",
68 50
     "@stitches/react": "^1.0.0",
69
-    "@tldraw/core": "^0.1.10",
70
-    "@tldraw/intersect": "^0.0.132",
71
-    "@tldraw/vec": "^0.0.132",
51
+    "@tldraw/core": "^0.1.13",
52
+    "@tldraw/intersect": "^0.1.3",
53
+    "@tldraw/vec": "^0.1.3",
72 54
     "perfect-freehand": "^1.0.16",
73 55
     "react-hotkeys-hook": "^3.4.0",
74 56
     "rko": "^0.5.25"
75 57
   },
76 58
   "gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
77
-}
59
+}

+ 1
- 1
packages/tldraw/src/state/session/sessions/arrow/arrow.session.ts Переглянути файл

@@ -68,7 +68,7 @@ export class ArrowSession extends Session {
68 68
 
69 69
       this.startBindingShapeId = this.bindableShapeIds
70 70
         .map((id) => page.shapes[id])
71
-        .find((shape) => TLDR.getShapeUtils(shape).hitTest(shape, point))?.id
71
+        .find((shape) => Utils.pointInBounds(point, TLDR.getShapeUtils(shape).getBounds(shape)))?.id
72 72
     } else {
73 73
       // If we're editing an existing line, is there a binding already
74 74
       // for the dragging handle?

packages/tldraw/src/state/migration.spec.ts → packages/tldraw/src/test/migration.spec.ts Переглянути файл

@@ -1,11 +1,11 @@
1 1
 /* eslint-disable @typescript-eslint/ban-ts-comment */
2 2
 import { TLDrawState } from '~state'
3 3
 import type { TLDrawDocument } from '~types'
4
-import oldDoc from '../test/old-doc.json'
4
+import oldDoc from './old-doc'
5 5
 
6 6
 describe('When migrating bindings', () => {
7 7
   it('migrates', () => {
8
-    Object.values((oldDoc as TLDrawDocument).pages).forEach((page) => {
8
+    Object.values((oldDoc as unknown as TLDrawDocument).pages).forEach((page) => {
9 9
       Object.values(page.bindings).forEach((binding) => {
10 10
         if ('meta' in binding) {
11 11
           // @ts-ignore
@@ -14,6 +14,6 @@ describe('When migrating bindings', () => {
14 14
       })
15 15
     })
16 16
 
17
-    new TLDrawState().loadDocument(oldDoc)
17
+    new TLDrawState().loadDocument(oldDoc as unknown as TLDrawDocument)
18 18
   })
19 19
 })

+ 0
- 31877
packages/tldraw/src/test/old-doc.json
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 15572
- 0
packages/tldraw/src/test/old-doc.ts
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 1
- 2
packages/tldraw/tsconfig.build.json Переглянути файл

@@ -18,6 +18,5 @@
18 18
     "declarationMap": false,
19 19
     "sourceMap": false,
20 20
     "emitDeclarationOnly": true
21
-  },
22
-  "references": [{ "path": "../vec" }, { "path": "../intersect" }]
21
+  }
23 22
 }

+ 3
- 5
packages/tldraw/tsconfig.json Переглянути файл

@@ -1,18 +1,16 @@
1 1
 {
2 2
   "extends": "../../tsconfig.base.json",
3
-  "include": ["src"],
3
+  "include": ["src", "src/test/old-doc.json"],
4 4
   "exclude": ["node_modules", "dist", "docs"],
5 5
   "compilerOptions": {
6
+    "resolveJsonModule": true,
6 7
     "outDir": "./dist/types",
7 8
     "rootDir": "src",
8 9
     "baseUrl": "src",
9 10
     "paths": {
10
-      "~*": ["./*"],
11
-      "@tldraw/vec": ["../vec"],
12
-      "@tldraw/intersect": ["../intersect"]
11
+      "~*": ["./*"]
13 12
     }
14 13
   },
15
-  "references": [{ "path": "../vec" }, { "path": "../intersect" }],
16 14
   "typedocOptions": {
17 15
     "entryPoints": ["src/index.ts"],
18 16
     "out": "docs"

+ 0
- 21
packages/vec/LICENSE Переглянути файл

@@ -1,21 +0,0 @@
1
-MIT License
2
-
3
-Copyright (c) 2021 Stephen Ruiz Ltd
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.

+ 0
- 3
packages/vec/README.md Переглянути файл

@@ -1,3 +0,0 @@
1
-# @tldraw/vec
2
-
3
-Vector utilities.

+ 0
- 48
packages/vec/package.json Переглянути файл

@@ -1,48 +0,0 @@
1
-{
2
-  "name": "@tldraw/vec",
3
-  "version": "0.0.132",
4
-  "private": false,
5
-  "description": "Vector utilities for tldraw.",
6
-  "author": "@steveruizok",
7
-  "repository": {
8
-    "type": "git",
9
-    "url": "git+https://github.com/tldraw/tldraw.git",
10
-    "directory": "packages/vec"
11
-  },
12
-  "license": "MIT",
13
-  "keywords": [],
14
-  "files": [
15
-    "dist/**/*"
16
-  ],
17
-  "sideEffects": false,
18
-  "main": "./dist/cjs/index.js",
19
-  "module": "./dist/esm/index.js",
20
-  "types": "./dist/types/index.d.ts",
21
-  "typings": "./dist/types/index.d.ts",
22
-  "scripts": {
23
-    "start:pre": "node scripts/pre-dev && yarn types:pre",
24
-    "start:utils": "node scripts/dev & yarn types:dev",
25
-    "build": "node scripts/build && yarn types:build",
26
-    "types:pre": "tsc",
27
-    "types:dev": "tsc --watch",
28
-    "types:build": "tsc --project tsconfig.build.json",
29
-    "lint": "eslint src/ --ext .ts,.tsx",
30
-    "clean": "rm -rf dist",
31
-    "ts-node": "ts-node",
32
-    "docs": "typedoc",
33
-    "docs:watch": "typedoc --watch"
34
-  },
35
-  "devDependencies": {
36
-    "@types/jest": "^27.0.1",
37
-    "@types/node": "^16.7.10",
38
-    "@typescript-eslint/eslint-plugin": "^4.30.0",
39
-    "@typescript-eslint/parser": "^4.30.0",
40
-    "esbuild": "^0.13.8",
41
-    "eslint": "^7.32.0",
42
-    "lerna": "^4.0.0",
43
-    "tslib": "^2.3.1",
44
-    "typedoc": "^0.22.3",
45
-    "typescript": "^4.4.2"
46
-  },
47
-  "gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
48
-}

+ 0
- 67
packages/vec/scripts/build.js Переглянути файл

@@ -1,67 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-const { gzip } = require('zlib')
5
-
6
-const name = process.env.npm_package_name || ''
7
-
8
-async function main() {
9
-  if (fs.existsSync('./dist')) {
10
-    fs.rmSync('./dist', { recursive: true }, (e) => {
11
-      if (e) {
12
-        throw e
13
-      }
14
-    })
15
-  }
16
-
17
-  try {
18
-    esbuild.buildSync({
19
-      entryPoints: ['./src/index.ts'],
20
-      outdir: 'dist/cjs',
21
-      minify: true,
22
-      bundle: true,
23
-      sourcemap: true,
24
-      format: 'cjs',
25
-      target: 'es6',
26
-      jsxFactory: 'React.createElement',
27
-      jsxFragment: 'React.Fragment',
28
-      tsconfig: './tsconfig.build.json',
29
-      external: ['react', 'react-dom'],
30
-    })
31
-
32
-    const esmResult = esbuild.buildSync({
33
-      entryPoints: ['./src/index.ts'],
34
-      outdir: 'dist/esm',
35
-      minify: true,
36
-      bundle: true,
37
-      sourcemap: true,
38
-      format: 'esm',
39
-      target: 'es6',
40
-      tsconfig: './tsconfig.build.json',
41
-      jsxFactory: 'React.createElement',
42
-      jsxFragment: 'React.Fragment',
43
-      external: ['react', 'react-dom'],
44
-      metafile: true,
45
-    })
46
-
47
-    let esmSize = 0
48
-    Object.values(esmResult.metafile.outputs).forEach((output) => {
49
-      esmSize += output.bytes
50
-    })
51
-
52
-    fs.readFile('./dist/esm/index.js', (_err, data) => {
53
-      gzip(data, (_err, result) => {
54
-        console.log(
55
-          `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
56
-            result.length / 1000
57
-          ).toFixed(2)}kb minified)`
58
-        )
59
-      })
60
-    })
61
-  } catch (e) {
62
-    console.log(`× ${name}: Build failed due to an error.`)
63
-    console.log(e)
64
-  }
65
-}
66
-
67
-main()

+ 0
- 28
packages/vec/scripts/dev.js Переглянути файл

@@ -1,28 +0,0 @@
1
-/* eslint-disable */
2
-const esbuild = require('esbuild')
3
-
4
-const name = process.env.npm_package_name || ''
5
-
6
-async function main() {
7
-  esbuild.build({
8
-    entryPoints: ['./src/index.ts'],
9
-    outdir: 'dist/cjs',
10
-    minify: false,
11
-    bundle: true,
12
-    format: 'cjs',
13
-    target: 'es6',
14
-    tsconfig: './tsconfig.json',
15
-    incremental: true,
16
-    watch: {
17
-      onRebuild(error) {
18
-        if (error) {
19
-          console.log(`× ${name}: An error in prevented the rebuild.`)
20
-          return
21
-        }
22
-        console.log(`✔ ${name}: Rebuilt.`)
23
-      },
24
-    },
25
-  })
26
-}
27
-
28
-main()

+ 0
- 27
packages/vec/scripts/pre-dev.js Переглянути файл

@@ -1,27 +0,0 @@
1
-/* eslint-disable */
2
-const fs = require('fs')
3
-const esbuild = require('esbuild')
4
-
5
-async function main() {
6
-  if (fs.existsSync('./dist')) {
7
-    fs.rmSync('./dist', { recursive: true }, (e) => {
8
-      if (e) {
9
-        throw e
10
-      }
11
-    })
12
-  }
13
-
14
-  esbuild.build({
15
-    entryPoints: ['./src/index.ts'],
16
-    outdir: 'dist/cjs',
17
-    minify: true,
18
-    bundle: true,
19
-    sourcemap: true,
20
-    format: 'cjs',
21
-    target: 'es6',
22
-    tsconfig: './tsconfig.json',
23
-    external: ['react', 'react-dom'],
24
-  })
25
-}
26
-
27
-main()

+ 0
- 520
packages/vec/src/index.ts Переглянути файл

@@ -1,520 +0,0 @@
1
-// A big collection of vector utilities. Collected into a class to improve logging / packaging.
2
-
3
-/* ----------------- Start Copy Here ---------------- */
4
-
5
-export class Vec {
6
-  /**
7
-   * Clamp a value into a range.
8
-   * @param n
9
-   * @param min
10
-   */
11
-  static clamp(n: number, min: number): number
12
-  static clamp(n: number, min: number, max: number): number
13
-  static clamp(n: number, min: number, max?: number): number {
14
-    return Math.max(min, typeof max !== 'undefined' ? Math.min(n, max) : n)
15
-  }
16
-
17
-  /**
18
-   * Clamp a value into a range.
19
-   * @param n
20
-   * @param min
21
-   */
22
-  static clampV(A: number[], min: number): number[]
23
-  static clampV(A: number[], min: number, max: number): number[]
24
-  static clampV(A: number[], min: number, max?: number): number[] {
25
-    return A.map((n) => (max ? Vec.clamp(n, min, max) : Vec.clamp(n, min)))
26
-  }
27
-
28
-  /**
29
-   * Negate a vector.
30
-   * @param A
31
-   */
32
-  static neg = (A: number[]): number[] => {
33
-    return [-A[0], -A[1]]
34
-  }
35
-
36
-  /**
37
-   * Add vectors.
38
-   * @param A
39
-   * @param B
40
-   */
41
-  static add = (A: number[], B: number[]): number[] => {
42
-    return [A[0] + B[0], A[1] + B[1]]
43
-  }
44
-
45
-  /**
46
-   * Add scalar to vector.
47
-   * @param A
48
-   * @param B
49
-   */
50
-  static addScalar = (A: number[], n: number): number[] => {
51
-    return [A[0] + n, A[1] + n]
52
-  }
53
-
54
-  /**
55
-   * Subtract vectors.
56
-   * @param A
57
-   * @param B
58
-   */
59
-  static sub = (A: number[], B: number[]): number[] => {
60
-    return [A[0] - B[0], A[1] - B[1]]
61
-  }
62
-
63
-  /**
64
-   * Subtract scalar from vector.
65
-   * @param A
66
-   * @param B
67
-   */
68
-  static subScalar = (A: number[], n: number): number[] => {
69
-    return [A[0] - n, A[1] - n]
70
-  }
71
-
72
-  /**
73
-   * Get the vector from vectors A to B.
74
-   * @param A
75
-   * @param B
76
-   */
77
-  static vec = (A: number[], B: number[]): number[] => {
78
-    // A, B as vectors get the vector from A to B
79
-    return [B[0] - A[0], B[1] - A[1]]
80
-  }
81
-
82
-  /**
83
-   * Vector multiplication by scalar
84
-   * @param A
85
-   * @param n
86
-   */
87
-  static mul = (A: number[], n: number): number[] => {
88
-    return [A[0] * n, A[1] * n]
89
-  }
90
-
91
-  /**
92
-   * Multiple two vectors.
93
-   * @param A
94
-   * @param B
95
-   */
96
-  static mulV = (A: number[], B: number[]): number[] => {
97
-    return [A[0] * B[0], A[1] * B[1]]
98
-  }
99
-
100
-  /**
101
-   * Vector division by scalar.
102
-   * @param A
103
-   * @param n
104
-   */
105
-  static div = (A: number[], n: number): number[] => {
106
-    return [A[0] / n, A[1] / n]
107
-  }
108
-
109
-  /**
110
-   * Vector division by vector.
111
-   * @param A
112
-   * @param n
113
-   */
114
-  static divV = (A: number[], B: number[]): number[] => {
115
-    return [A[0] / B[0], A[1] / B[1]]
116
-  }
117
-
118
-  /**
119
-   * Perpendicular rotation of a vector A
120
-   * @param A
121
-   */
122
-  static per = (A: number[]): number[] => {
123
-    return [A[1], -A[0]]
124
-  }
125
-
126
-  /**
127
-   * Dot product
128
-   * @param A
129
-   * @param B
130
-   */
131
-  static dpr = (A: number[], B: number[]): number => {
132
-    return A[0] * B[0] + A[1] * B[1]
133
-  }
134
-
135
-  /**
136
-   * Cross product (outer product) | A X B |
137
-   * @param A
138
-   * @param B
139
-   */
140
-  static cpr = (A: number[], B: number[]): number => {
141
-    return A[0] * B[1] - B[0] * A[1]
142
-  }
143
-
144
-  /**
145
-   * Cross (for point in polygon)
146
-   *
147
-   */
148
-  static cross(x: number[], y: number[], z: number[]): number {
149
-    return (y[0] - x[0]) * (z[1] - x[1]) - (z[0] - x[0]) * (y[1] - x[1])
150
-  }
151
-
152
-  /**
153
-   * Length of the vector squared
154
-   * @param A
155
-   */
156
-  static len2 = (A: number[]): number => {
157
-    return A[0] * A[0] + A[1] * A[1]
158
-  }
159
-
160
-  /**
161
-   * Length of the vector
162
-   * @param A
163
-   */
164
-  static len = (A: number[]): number => {
165
-    return Math.hypot(A[0], A[1])
166
-  }
167
-
168
-  /**
169
-   * Project A over B
170
-   * @param A
171
-   * @param B
172
-   */
173
-  static pry = (A: number[], B: number[]): number => {
174
-    return Vec.dpr(A, B) / Vec.len(B)
175
-  }
176
-
177
-  /**
178
-   * Get normalized / unit vector.
179
-   * @param A
180
-   */
181
-  static uni = (A: number[]): number[] => {
182
-    return Vec.div(A, Vec.len(A))
183
-  }
184
-
185
-  /**
186
-   * Get normalized / unit vector.
187
-   * @param A
188
-   */
189
-  static normalize = (A: number[]): number[] => {
190
-    return Vec.uni(A)
191
-  }
192
-
193
-  /**
194
-   * Get the tangent between two vectors.
195
-   * @param A
196
-   * @param B
197
-   * @returns
198
-   */
199
-  static tangent = (A: number[], B: number[]): number[] => {
200
-    return Vec.uni(Vec.sub(A, B))
201
-  }
202
-
203
-  /**
204
-   * Dist length from A to B squared.
205
-   * @param A
206
-   * @param B
207
-   */
208
-  static dist2 = (A: number[], B: number[]): number => {
209
-    return Vec.len2(Vec.sub(A, B))
210
-  }
211
-
212
-  /**
213
-   * Dist length from A to B
214
-   * @param A
215
-   * @param B
216
-   */
217
-  static dist = (A: number[], B: number[]): number => {
218
-    return Math.hypot(A[1] - B[1], A[0] - B[0])
219
-  }
220
-
221
-  /**
222
-   * A faster, though less accurate method for testing distances. Maybe faster?
223
-   * @param A
224
-   * @param B
225
-   * @returns
226
-   */
227
-  static fastDist = (A: number[], B: number[]): number[] => {
228
-    const V = [B[0] - A[0], B[1] - A[1]]
229
-    const aV = [Math.abs(V[0]), Math.abs(V[1])]
230
-    let r = 1 / Math.max(aV[0], aV[1])
231
-    r = r * (1.29289 - (aV[0] + aV[1]) * r * 0.29289)
232
-    return [V[0] * r, V[1] * r]
233
-  }
234
-
235
-  /**
236
-   * Angle between vector A and vector B in radians
237
-   * @param A
238
-   * @param B
239
-   */
240
-  static ang = (A: number[], B: number[]): number => {
241
-    return Math.atan2(Vec.cpr(A, B), Vec.dpr(A, B))
242
-  }
243
-
244
-  /**
245
-   * Angle between vector A and vector B in radians
246
-   * @param A
247
-   * @param B
248
-   */
249
-  static angle = (A: number[], B: number[]): number => {
250
-    return Math.atan2(B[1] - A[1], B[0] - A[0])
251
-  }
252
-
253
-  /**
254
-   * Mean between two vectors or mid vector between two vectors
255
-   * @param A
256
-   * @param B
257
-   */
258
-  static med = (A: number[], B: number[]): number[] => {
259
-    return Vec.mul(Vec.add(A, B), 0.5)
260
-  }
261
-
262
-  /**
263
-   * Vector rotation by r (radians)
264
-   * @param A
265
-   * @param r rotation in radians
266
-   */
267
-  static rot = (A: number[], r = 0): number[] => {
268
-    return [A[0] * Math.cos(r) - A[1] * Math.sin(r), A[0] * Math.sin(r) + A[1] * Math.cos(r)]
269
-  }
270
-
271
-  /**
272
-   * Rotate a vector around another vector by r (radians)
273
-   * @param A vector
274
-   * @param C center
275
-   * @param r rotation in radians
276
-   */
277
-  static rotWith = (A: number[], C: number[], r = 0): number[] => {
278
-    if (r === 0) return A
279
-
280
-    const s = Math.sin(r)
281
-    const c = Math.cos(r)
282
-
283
-    const px = A[0] - C[0]
284
-    const py = A[1] - C[1]
285
-
286
-    const nx = px * c - py * s
287
-    const ny = px * s + py * c
288
-
289
-    return [nx + C[0], ny + C[1]]
290
-  }
291
-
292
-  /**
293
-   * Check of two vectors are identical.
294
-   * @param A
295
-   * @param B
296
-   */
297
-  static isEqual = (A: number[], B: number[]): boolean => {
298
-    return A[0] === B[0] && A[1] === B[1]
299
-  }
300
-
301
-  /**
302
-   * Interpolate vector A to B with a scalar t
303
-   * @param A
304
-   * @param B
305
-   * @param t scalar
306
-   */
307
-  static lrp = (A: number[], B: number[], t: number): number[] => {
308
-    return Vec.add(A, Vec.mul(Vec.sub(B, A), t))
309
-  }
310
-
311
-  /**
312
-   * Interpolate from A to B when curVAL goes fromVAL: number[] => to
313
-   * @param A
314
-   * @param B
315
-   * @param from Starting value
316
-   * @param to Ending value
317
-   * @param s Strength
318
-   */
319
-  static int = (A: number[], B: number[], from: number, to: number, s = 1): number[] => {
320
-    const t = (Vec.clamp(from, to) - from) / (to - from)
321
-    return Vec.add(Vec.mul(A, 1 - t), Vec.mul(B, s))
322
-  }
323
-
324
-  /**
325
-   * Get the angle between the three vectors A, B, and C.
326
-   * @param p1
327
-   * @param pc
328
-   * @param p2
329
-   */
330
-  static ang3 = (p1: number[], pc: number[], p2: number[]): number => {
331
-    // this,
332
-    const v1 = Vec.vec(pc, p1)
333
-    const v2 = Vec.vec(pc, p2)
334
-    return Vec.ang(v1, v2)
335
-  }
336
-
337
-  /**
338
-   * Absolute value of a vector.
339
-   * @param A
340
-   * @returns
341
-   */
342
-  static abs = (A: number[]): number[] => {
343
-    return [Math.abs(A[0]), Math.abs(A[1])]
344
-  }
345
-
346
-  static rescale = (a: number[], n: number): number[] => {
347
-    const l = Vec.len(a)
348
-    return [(n * a[0]) / l, (n * a[1]) / l]
349
-  }
350
-
351
-  /**
352
-   * Get whether p1 is left of p2, relative to pc.
353
-   * @param p1
354
-   * @param pc
355
-   * @param p2
356
-   */
357
-  static isLeft = (p1: number[], pc: number[], p2: number[]): number => {
358
-    //  isLeft: >0 for counterclockwise
359
-    //          =0 for none (degenerate)
360
-    //          <0 for clockwise
361
-    return (pc[0] - p1[0]) * (p2[1] - p1[1]) - (p2[0] - p1[0]) * (pc[1] - p1[1])
362
-  }
363
-
364
-  static clockwise = (p1: number[], pc: number[], p2: number[]): boolean => {
365
-    return Vec.isLeft(p1, pc, p2) > 0
366
-  }
367
-
368
-  static round = (a: number[], d = 2): number[] => {
369
-    return a.map((v) => +v.toFixed(d))
370
-  }
371
-
372
-  /**
373
-   * Get the minimum distance from a point P to a line with a segment AB.
374
-   * @param A The start of the line.
375
-   * @param B The end of the line.
376
-   * @param P A point.
377
-   * @returns
378
-   */
379
-  // static distanceToLine(A: number[], B: number[], P: number[]) {
380
-  //   const delta = sub(B, A)
381
-  //   const angle = Math.atan2(delta[1], delta[0])
382
-  //   const dir = rot(sub(P, A), -angle)
383
-  //   return dir[1]
384
-  // }
385
-
386
-  /**
387
-   * Get the nearest point on a line segment AB.
388
-   * @param A The start of the line.
389
-   * @param B The end of the line.
390
-   * @param P A point.
391
-   * @param clamp Whether to clamp the resulting point to the segment.
392
-   * @returns
393
-   */
394
-  // static nearestPointOnLine(
395
-  //   A: number[],
396
-  //   B: number[],
397
-  //   P: number[],
398
-  //   clamp = true
399
-  // ) {
400
-  //   const delta = sub(B, A)
401
-  //   const length = len(delta)
402
-  //   const angle = Math.atan2(delta[1], delta[0])
403
-  //   const dir = rot(sub(P, A), -angle)
404
-
405
-  //   if (clamp) {
406
-  //     if (dir[0] < 0) return A
407
-  //     if (dir[0] > length) return B
408
-  //   }
409
-
410
-  //   return add(A, div(mul(delta, dir[0]), length))
411
-  // }
412
-
413
-  /**
414
-   * Get the nearest point on a line with a known unit vector that passes through point A
415
-   * @param A Any point on the line
416
-   * @param u The unit vector for the line.
417
-   * @param P A point not on the line to test.
418
-   * @returns
419
-   */
420
-  static nearestPointOnLineThroughPoint = (A: number[], u: number[], P: number[]): number[] => {
421
-    return Vec.add(A, Vec.mul(u, Vec.pry(Vec.sub(P, A), u)))
422
-  }
423
-
424
-  /**
425
-   * Distance between a point and a line with a known unit vector that passes through a point.
426
-   * @param A Any point on the line
427
-   * @param u The unit vector for the line.
428
-   * @param P A point not on the line to test.
429
-   * @returns
430
-   */
431
-  static distanceToLineThroughPoint = (A: number[], u: number[], P: number[]): number => {
432
-    return Vec.dist(P, Vec.nearestPointOnLineThroughPoint(A, u, P))
433
-  }
434
-
435
-  /**
436
-   * Get the nearest point on a line segment between A and B
437
-   * @param A The start of the line segment
438
-   * @param B The end of the line segment
439
-   * @param P The off-line point
440
-   * @param clamp Whether to clamp the point between A and B.
441
-   * @returns
442
-   */
443
-  static nearestPointOnLineSegment = (
444
-    A: number[],
445
-    B: number[],
446
-    P: number[],
447
-    clamp = true
448
-  ): number[] => {
449
-    const u = Vec.uni(Vec.sub(B, A))
450
-    const C = Vec.add(A, Vec.mul(u, Vec.pry(Vec.sub(P, A), u)))
451
-
452
-    if (clamp) {
453
-      if (C[0] < Math.min(A[0], B[0])) return A[0] < B[0] ? A : B
454
-      if (C[0] > Math.max(A[0], B[0])) return A[0] > B[0] ? A : B
455
-      if (C[1] < Math.min(A[1], B[1])) return A[1] < B[1] ? A : B
456
-      if (C[1] > Math.max(A[1], B[1])) return A[1] > B[1] ? A : B
457
-    }
458
-
459
-    return C
460
-  }
461
-
462
-  /**
463
-   * Distance between a point and the nearest point on a line segment between A and B
464
-   * @param A The start of the line segment
465
-   * @param B The end of the line segment
466
-   * @param P The off-line point
467
-   * @param clamp Whether to clamp the point between A and B.
468
-   * @returns
469
-   */
470
-  static distanceToLineSegment = (A: number[], B: number[], P: number[], clamp = true): number => {
471
-    return Vec.dist(P, Vec.nearestPointOnLineSegment(A, B, P, clamp))
472
-  }
473
-
474
-  /**
475
-   * Push a point A towards point B by a given distance.
476
-   * @param A
477
-   * @param B
478
-   * @param d
479
-   * @returns
480
-   */
481
-  static nudge = (A: number[], B: number[], d: number): number[] => {
482
-    return Vec.add(A, Vec.mul(Vec.uni(Vec.sub(B, A)), d))
483
-  }
484
-
485
-  /**
486
-   * Push a point in a given angle by a given distance.
487
-   * @param A
488
-   * @param B
489
-   * @param d
490
-   */
491
-  static nudgeAtAngle = (A: number[], a: number, d: number): number[] => {
492
-    return [Math.cos(a) * d + A[0], Math.sin(a) * d + A[1]]
493
-  }
494
-
495
-  /**
496
-   * Round a vector to a precision length.
497
-   * @param a
498
-   * @param n
499
-   */
500
-  static toPrecision = (a: number[], n = 4): number[] => {
501
-    return [+a[0].toPrecision(n), +a[1].toPrecision(n)]
502
-  }
503
-
504
-  /**
505
-   * Get an array of points (with simulated pressure) between two points.
506
-   * @param A The first point.
507
-   * @param B The second point.
508
-   * @param steps The number of points to return.
509
-   * @param ease An easing function to apply to the simulated pressure.
510
-   */
511
-  static pointsBetween = (A: number[], B: number[], steps = 6): number[][] => {
512
-    return Array.from(Array(steps)).map((_, i) => {
513
-      const t = i / (steps - 1)
514
-      const k = Math.min(1, 0.5 + Math.abs(0.5 - t))
515
-      return [...Vec.lrp(A, B, t), k]
516
-    })
517
-  }
518
-}
519
-
520
-export default Vec

+ 0
- 19
packages/vec/tsconfig.build.json Переглянути файл

@@ -1,19 +0,0 @@
1
-{
2
-  "extends": "./tsconfig.json",
3
-  "exclude": [
4
-    "node_modules",
5
-    "**/*.test.tsx",
6
-    "**/*.test.ts",
7
-    "**/*.spec.tsx",
8
-    "**/*.spec.ts",
9
-    "src/test",
10
-    "dist",
11
-    "docs"
12
-  ],
13
-  "compilerOptions": {
14
-    "composite": false,
15
-    "incremental": false,
16
-    "declarationMap": false,
17
-    "sourceMap": false
18
-  }
19
-}

+ 0
- 15
packages/vec/tsconfig.json Переглянути файл

@@ -1,15 +0,0 @@
1
-{
2
-  "extends": "../../tsconfig.base.json",
3
-  "include": ["src"],
4
-  "exclude": ["node_modules", "dist", "docs"],
5
-  "compilerOptions": {
6
-    "outDir": "./dist/types",
7
-    "rootDir": "src",
8
-    "baseUrl": "src",
9
-    "emitDeclarationOnly": false
10
-  },
11
-  "typedocOptions": {
12
-    "entryPoints": ["src/index.ts"],
13
-    "out": "docs"
14
-  }
15
-}

+ 1
- 1
packages/www/public/sw.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 1
- 1
packages/www/public/sw.js.map
Різницю між файлами не показано, бо вона завелика
Переглянути файл


packages/www/public/worker-HKFtmQufnTIV6sQ0dJS4-.js → packages/www/public/worker-7ryd46WBzPy7BjiSHTKb0.js Переглянути файл


+ 21
- 7
packages/www/tsconfig.json Переглянути файл

@@ -2,7 +2,11 @@
2 2
   "compilerOptions": {
3 3
     "composite": true,
4 4
     "target": "es5",
5
-    "lib": ["dom", "dom.iterable", "esnext"],
5
+    "lib": [
6
+      "dom",
7
+      "dom.iterable",
8
+      "esnext"
9
+    ],
6 10
     "allowJs": true,
7 11
     "skipLibCheck": true,
8 12
     "strict": false,
@@ -11,19 +15,29 @@
11 15
     "esModuleInterop": true,
12 16
     "module": "esnext",
13 17
     "moduleResolution": "node",
14
-    "resolveJsonModule": true,
15 18
     "isolatedModules": true,
16 19
     "jsx": "preserve",
17 20
     "baseUrl": ".",
18 21
     "rootDir": ".",
19 22
     "paths": {
20
-      "-*": ["./*"],
21
-      "@tldraw/tldraw": ["../tldraw"]
23
+      "-*": [
24
+        "./*"
25
+      ],
26
+      "@tldraw/tldraw": [
27
+        "../tldraw"
28
+      ]
22 29
     },
23
-    "incremental": true
30
+    "incremental": true,
31
+    "resolveJsonModule": true
24 32
   },
25
-  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
26
-  "exclude": ["node_modules"],
33
+  "include": [
34
+    "next-env.d.ts",
35
+    "**/*.ts",
36
+    "**/*.tsx"
37
+  ],
38
+  "exclude": [
39
+    "node_modules"
40
+  ],
27 41
   "references": [
28 42
     {
29 43
       "path": "../tldraw"

+ 1
- 7
tsconfig.json Переглянути файл

@@ -3,17 +3,11 @@
3 3
   "extends": "./tsconfig.base.json",
4 4
   "exclude": ["node_modules", "**/*.test.ts", "**/*.spec.ts"],
5 5
   "files": [],
6
-  "references": [
7
-    { "path": "./packages/vec" },
8
-    { "path": "./packages/intersect" },
9
-    { "path": "./packages/tldraw" }
10
-  ],
6
+  "references": [{ "path": "./packages/tldraw" }],
11 7
   "compilerOptions": {
12 8
     "baseUrl": ".",
13 9
     "paths": {
14 10
       "@tldraw/tldraw": ["./packages/tldraw"],
15
-      "@tldraw/vec": ["./packages/vec"],
16
-      "@tldraw/intersect": ["./packages/intersect"],
17 11
       "~*": ["./packages/tldraw/src/*"]
18 12
     }
19 13
   }

+ 72
- 1680
yarn.lock
Різницю між файлами не показано, бо вона завелика
Переглянути файл


Завантаження…
Відмінити
Зберегти