Remove libraries

This commit is contained in:
Steve Ruiz 2021-11-01 15:26:44 +00:00
parent 12e425ddc4
commit 0d564c1501
41 changed files with 15678 additions and 36048 deletions

View file

@ -11,9 +11,6 @@
"workspaces": [
"packages/tldraw",
"packages/dev",
"packages/vec",
"packages/svg",
"packages/intersect",
"packages/www"
],
"scripts": {
@ -23,7 +20,7 @@
"start": "lerna run start:pre && lerna run start --stream --parallel",
"start:www": "yarn build:packages && lerna run start --parallel & cd packages/www && yarn dev",
"build": "yarn build:packages && cd packages/www && yarn build",
"build:packages": "cd packages/vec && yarn build && cd ../intersect && yarn build && cd ../tldraw && yarn build",
"build:packages": "cd packages/tldraw && yarn build",
"publish:patch": "yarn build:packages && lerna publish patch",
"docs": "lerna run docs",
"docs:watch": "lerna run docs:watch"
@ -32,7 +29,7 @@
"@swc-node/jest": "^1.3.3",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@types/jest": "^27.0.1",
"@types/jest": "^27.0.2",
"@types/node": "^15.0.1",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
@ -41,7 +38,7 @@
"eslint": "^7.32.0",
"fake-indexeddb": "^3.1.3",
"init-package-json": "^2.0.4",
"jest": "^27.1.0",
"jest": "^27.3.1",
"lerna": "^3.22.1",
"resize-observer-polyfill": "^1.5.1",
"tslib": "^2.3.0",
@ -73,14 +70,10 @@
],
"testEnvironment": "jsdom",
"modulePathIgnorePatterns": [
"<rootDir>/packages/vec/dist/",
"<rootDir>/packages/intersect/dist/",
"<rootDir>/packages/tldraw/dist/",
"<rootDir>/packages/tldraw/test-utils/"
],
"moduleNameMapper": {
"@tldraw/vec": "<rootDir>/packages/vec/src",
"@tldraw/intersect": "<rootDir>/packages/intersect/src",
"@tldraw/tldraw": "<rootDir>/packages/tldraw/src",
"\\~(.*)": "<rootDir>/packages/tldraw/src/$1"
}

View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2021 Stephen Ruiz Ltd
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.

View file

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

View file

@ -1,51 +0,0 @@
{
"name": "@tldraw/intersect",
"version": "0.0.132",
"private": false,
"description": "Intersection utilities for tldraw.",
"author": "@steveruizok",
"repository": {
"type": "git",
"url": "git+https://github.com/tldraw/tldraw.git",
"directory": "packages/intersect"
},
"license": "MIT",
"keywords": [],
"files": [
"dist/**/*"
],
"sideEffects": false,
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"scripts": {
"start:pre": "node scripts/pre-dev && yarn types:pre",
"start:utils": "node scripts/dev & yarn types:dev",
"build": "node scripts/build && yarn types:build",
"types:pre": "tsc",
"types:dev": "tsc --watch",
"types:build": "tsc --project tsconfig.build.json",
"lint": "eslint src/ --ext .ts,.tsx",
"clean": "rm -rf dist",
"ts-node": "ts-node",
"docs": "typedoc",
"docs:watch": "typedoc --watch"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"esbuild": "^0.13.8",
"eslint": "^7.32.0",
"lerna": "^4.0.0",
"tslib": "^2.3.1",
"typedoc": "^0.22.3",
"typescript": "^4.4.2"
},
"dependencies": {
"@tldraw/vec": "^0.0.132"
},
"gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
}

View file

@ -1,65 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
const { gzip } = require('zlib')
const name = process.env.npm_package_name || ''
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: true,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.build.json',
external: ['react', 'react-dom'],
})
const esmResult = esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/esm',
minify: true,
bundle: true,
format: 'esm',
target: 'es6',
tsconfig: './tsconfig.build.json',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
external: ['react', 'react-dom'],
metafile: true,
})
let esmSize = 0
Object.values(esmResult.metafile.outputs).forEach((output) => {
esmSize += output.bytes
})
fs.readFile('./dist/esm/index.js', (_err, data) => {
gzip(data, (_err, result) => {
console.log(
`${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
result.length / 1000
).toFixed(2)}kb minified)`
)
})
})
} catch (e) {
console.log(`× ${name}: Build failed due to an error.`)
console.log(e)
}
}
main()

View file

@ -1,31 +0,0 @@
/* eslint-disable */
const esbuild = require('esbuild')
const name = process.env.npm_package_name || ''
async function main() {
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.json',
external: ['react', 'react-dom'],
incremental: true,
watch: {
onRebuild(error) {
if (error) {
console.log(`× ${name}: An error in prevented the rebuild.`)
return
}
console.log(`${name}: Rebuilt.`)
},
},
})
}
main()

View file

@ -1,28 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.json',
external: ['react', 'react-dom'],
})
}
main()

File diff suppressed because it is too large Load diff

View file

@ -1,24 +0,0 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"**/*.test.tsx",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.spec.ts",
"src/test",
"dist",
"docs"
],
"compilerOptions": {
"composite": false,
"incremental": false,
"declarationMap": false,
"sourceMap": false,
"emitDeclarationOnly": true,
"paths": {
"@tldraw/vec": ["../vec"]
}
},
"references": [{ "path": "../vec" }]
}

View file

@ -1,18 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "dist", "docs"],
"compilerOptions": {
"outDir": "./dist/types",
"rootDir": "src",
"baseUrl": "src",
"paths": {
"@tldraw/vec": ["../vec"]
}
},
"references": [{ "path": "../vec" }],
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs"
}
}

View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2021 Stephen Ruiz Ltd
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.

View file

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

View file

@ -1,48 +0,0 @@
{
"name": "@tldraw/svg",
"version": "0.0.132",
"private": false,
"description": "SVG utilities for tldraw.",
"author": "@steveruizok",
"repository": {
"type": "git",
"url": "git+https://github.com/tldraw/tldraw.git",
"directory": "packages/vec"
},
"license": "MIT",
"keywords": [],
"files": [
"dist/**/*"
],
"sideEffects": false,
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"scripts": {
"start:pre": "node scripts/pre-dev && yarn types:pre",
"start:utils": "node scripts/dev & yarn types:dev",
"build": "node scripts/build && yarn types:build",
"types:pre": "tsc",
"types:dev": "tsc --watch",
"types:build": "tsc --project tsconfig.build.json",
"lint": "eslint src/ --ext .ts,.tsx",
"clean": "rm -rf dist",
"ts-node": "ts-node",
"docs": "typedoc",
"docs:watch": "typedoc --watch"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"esbuild": "^0.13.8",
"eslint": "^7.32.0",
"lerna": "^4.0.0",
"tslib": "^2.3.1",
"typedoc": "^0.22.3",
"typescript": "^4.4.2"
},
"gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
}

View file

@ -1,65 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
const { gzip } = require('zlib')
const name = process.env.npm_package_name || ''
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: true,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.build.json',
external: ['react', 'react-dom'],
})
const esmResult = esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/esm',
minify: true,
bundle: true,
format: 'esm',
target: 'es6',
tsconfig: './tsconfig.build.json',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
external: ['react', 'react-dom'],
metafile: true,
})
let esmSize = 0
Object.values(esmResult.metafile.outputs).forEach((output) => {
esmSize += output.bytes
})
fs.readFile('./dist/esm/index.js', (_err, data) => {
gzip(data, (_err, result) => {
console.log(
`${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
result.length / 1000
).toFixed(2)}kb minified)`
)
})
})
} catch (e) {
console.log(`× ${name}: Build failed due to an error.`)
console.log(e)
}
}
main()

View file

@ -1,31 +0,0 @@
/* eslint-disable */
const esbuild = require('esbuild')
const name = process.env.npm_package_name || ''
async function main() {
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.json',
external: ['react', 'react-dom'],
incremental: true,
watch: {
onRebuild(error) {
if (error) {
console.log(`× ${name}: An error in prevented the rebuild.`)
return
}
console.log(`${name}: Rebuilt.`)
},
},
})
}
main()

View file

@ -1,28 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.json',
external: ['react', 'react-dom'],
})
}
main()

View file

@ -1,63 +0,0 @@
// General
function angle(A: number[], B: number[]): number {
return Math.atan2(B[1] - A[1], B[0] - A[0])
}
function shortAngleDist(A: number, B: number) {
const max = Math.PI * 2
const da = (B - A) % max
return ((2 * da) % max) - da
}
function getArcLength(C: number[], r: number, A: number[], B: number[]): number {
return r * (2 * Math.PI) * (shortAngleDist(angle(C, A), angle(C, B)) / (2 * Math.PI))
}
export const moveTo = (v: number[]): string => {
return `M ${v} `
}
export const lineTo = (...v: number[][]): string => {
return `L ${v.join(' ')} `
}
export const hLineTo = (v: number[]): string => {
return `H ${v} `
}
export const vLineTo = (v: number[]): string => {
return `V ${v} `
}
export const bezierTo = (A: number[], B: number[], C: number[]): string => {
return `C ${A} ${B} ${C} `
}
export const arcTo = (C: number[], r: number, A: number[], B: number[]): string => {
return [moveTo(A), 'A', r, r, 0, 0, getArcLength(C, r, A, B) > 0 ? '1' : '0', B[0], B[1]].join(
' '
)
}
export const rectTo = (A: number[]): string => {
return `R ${A}`
}
export const ellipse = (A: number[], r: number): string => {
return `M ${A[0] - r},${A[1]}
a ${r},${r} 0 1,0 ${r * 2},0
a ${r},${r} 0 1,0 -${r * 2},0 `
}
export const line = (a: number[], ...pts: number[][]): string => {
return moveTo(a) + lineTo(...pts)
}
export const closePath = (): string => {
return 'Z'
}
export const getPointAtLength = (path: SVGPathElement, length: number): number[] => {
const point = path.getPointAtLength(length)
return [point.x, point.y]
}

View file

@ -1,24 +0,0 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"**/*.test.tsx",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.spec.ts",
"src/test",
"dist",
"docs"
],
"compilerOptions": {
"composite": false,
"incremental": false,
"declarationMap": false,
"sourceMap": false,
"emitDeclarationOnly": true,
"paths": {
"@tldraw/vec": ["../vec"]
}
},
"references": [{ "path": "../vec" }]
}

View file

@ -1,18 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "dist", "docs"],
"compilerOptions": {
"outDir": "./dist/types",
"rootDir": "src",
"baseUrl": "src",
"paths": {
"@tldraw/vec": ["../vec"]
}
},
"references": [{ "path": "../vec" }],
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs"
}
}

View file

@ -19,7 +19,6 @@
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"scripts": {
"start:pre": "node scripts/pre-dev && yarn types:pre",
"start": "node scripts/dev & yarn types:dev",
"build": "node scripts/build && yarn types:build",
"types:pre": "tsc",
@ -32,24 +31,7 @@
"docs:watch": "typedoc --watch"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.4",
"@types/jest": "^27.0.1",
"@types/node": "^16.7.10",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"esbuild": "^0.13.8",
"eslint": "^7.32.0",
"lerna": "^4.0.0",
"react": ">=16.8",
"react-dom": "^16.8 || ^17.0",
"ts-node": "^10.2.1",
"tsconfig-replace-paths": "^0.0.5",
"tslib": "^2.3.1",
"typedoc": "^0.22.3",
"typescript": "^4.4.2"
"tsconfig-replace-paths": "^0.0.5"
},
"peerDependencies": {
"react": ">=16.8",
@ -66,12 +48,12 @@
"@radix-ui/react-tooltip": "^0.1.1",
"@stitches/core": "^1.2.5",
"@stitches/react": "^1.0.0",
"@tldraw/core": "^0.1.10",
"@tldraw/intersect": "^0.0.132",
"@tldraw/vec": "^0.0.132",
"@tldraw/core": "^0.1.13",
"@tldraw/intersect": "^0.1.3",
"@tldraw/vec": "^0.1.3",
"perfect-freehand": "^1.0.16",
"react-hotkeys-hook": "^3.4.0",
"rko": "^0.5.25"
},
"gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
}
}

View file

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

View file

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

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,18 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"include": ["src", "src/test/old-doc.json"],
"exclude": ["node_modules", "dist", "docs"],
"compilerOptions": {
"resolveJsonModule": true,
"outDir": "./dist/types",
"rootDir": "src",
"baseUrl": "src",
"paths": {
"~*": ["./*"],
"@tldraw/vec": ["../vec"],
"@tldraw/intersect": ["../intersect"]
"~*": ["./*"]
}
},
"references": [{ "path": "../vec" }, { "path": "../intersect" }],
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs"

View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2021 Stephen Ruiz Ltd
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.

View file

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

View file

@ -1,48 +0,0 @@
{
"name": "@tldraw/vec",
"version": "0.0.132",
"private": false,
"description": "Vector utilities for tldraw.",
"author": "@steveruizok",
"repository": {
"type": "git",
"url": "git+https://github.com/tldraw/tldraw.git",
"directory": "packages/vec"
},
"license": "MIT",
"keywords": [],
"files": [
"dist/**/*"
],
"sideEffects": false,
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"scripts": {
"start:pre": "node scripts/pre-dev && yarn types:pre",
"start:utils": "node scripts/dev & yarn types:dev",
"build": "node scripts/build && yarn types:build",
"types:pre": "tsc",
"types:dev": "tsc --watch",
"types:build": "tsc --project tsconfig.build.json",
"lint": "eslint src/ --ext .ts,.tsx",
"clean": "rm -rf dist",
"ts-node": "ts-node",
"docs": "typedoc",
"docs:watch": "typedoc --watch"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"esbuild": "^0.13.8",
"eslint": "^7.32.0",
"lerna": "^4.0.0",
"tslib": "^2.3.1",
"typedoc": "^0.22.3",
"typescript": "^4.4.2"
},
"gitHead": "083b36e167b6911927a6b58cbbb830b11b33f00a"
}

View file

@ -1,67 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
const { gzip } = require('zlib')
const name = process.env.npm_package_name || ''
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: true,
bundle: true,
sourcemap: true,
format: 'cjs',
target: 'es6',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: './tsconfig.build.json',
external: ['react', 'react-dom'],
})
const esmResult = esbuild.buildSync({
entryPoints: ['./src/index.ts'],
outdir: 'dist/esm',
minify: true,
bundle: true,
sourcemap: true,
format: 'esm',
target: 'es6',
tsconfig: './tsconfig.build.json',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
external: ['react', 'react-dom'],
metafile: true,
})
let esmSize = 0
Object.values(esmResult.metafile.outputs).forEach((output) => {
esmSize += output.bytes
})
fs.readFile('./dist/esm/index.js', (_err, data) => {
gzip(data, (_err, result) => {
console.log(
`${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
result.length / 1000
).toFixed(2)}kb minified)`
)
})
})
} catch (e) {
console.log(`× ${name}: Build failed due to an error.`)
console.log(e)
}
}
main()

View file

@ -1,28 +0,0 @@
/* eslint-disable */
const esbuild = require('esbuild')
const name = process.env.npm_package_name || ''
async function main() {
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
tsconfig: './tsconfig.json',
incremental: true,
watch: {
onRebuild(error) {
if (error) {
console.log(`× ${name}: An error in prevented the rebuild.`)
return
}
console.log(`${name}: Rebuilt.`)
},
},
})
}
main()

View file

@ -1,27 +0,0 @@
/* eslint-disable */
const fs = require('fs')
const esbuild = require('esbuild')
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
esbuild.build({
entryPoints: ['./src/index.ts'],
outdir: 'dist/cjs',
minify: true,
bundle: true,
sourcemap: true,
format: 'cjs',
target: 'es6',
tsconfig: './tsconfig.json',
external: ['react', 'react-dom'],
})
}
main()

View file

@ -1,520 +0,0 @@
// A big collection of vector utilities. Collected into a class to improve logging / packaging.
/* ----------------- Start Copy Here ---------------- */
export class Vec {
/**
* Clamp a value into a range.
* @param n
* @param min
*/
static clamp(n: number, min: number): number
static clamp(n: number, min: number, max: number): number
static clamp(n: number, min: number, max?: number): number {
return Math.max(min, typeof max !== 'undefined' ? Math.min(n, max) : n)
}
/**
* Clamp a value into a range.
* @param n
* @param min
*/
static clampV(A: number[], min: number): number[]
static clampV(A: number[], min: number, max: number): number[]
static clampV(A: number[], min: number, max?: number): number[] {
return A.map((n) => (max ? Vec.clamp(n, min, max) : Vec.clamp(n, min)))
}
/**
* Negate a vector.
* @param A
*/
static neg = (A: number[]): number[] => {
return [-A[0], -A[1]]
}
/**
* Add vectors.
* @param A
* @param B
*/
static add = (A: number[], B: number[]): number[] => {
return [A[0] + B[0], A[1] + B[1]]
}
/**
* Add scalar to vector.
* @param A
* @param B
*/
static addScalar = (A: number[], n: number): number[] => {
return [A[0] + n, A[1] + n]
}
/**
* Subtract vectors.
* @param A
* @param B
*/
static sub = (A: number[], B: number[]): number[] => {
return [A[0] - B[0], A[1] - B[1]]
}
/**
* Subtract scalar from vector.
* @param A
* @param B
*/
static subScalar = (A: number[], n: number): number[] => {
return [A[0] - n, A[1] - n]
}
/**
* Get the vector from vectors A to B.
* @param A
* @param B
*/
static vec = (A: number[], B: number[]): number[] => {
// A, B as vectors get the vector from A to B
return [B[0] - A[0], B[1] - A[1]]
}
/**
* Vector multiplication by scalar
* @param A
* @param n
*/
static mul = (A: number[], n: number): number[] => {
return [A[0] * n, A[1] * n]
}
/**
* Multiple two vectors.
* @param A
* @param B
*/
static mulV = (A: number[], B: number[]): number[] => {
return [A[0] * B[0], A[1] * B[1]]
}
/**
* Vector division by scalar.
* @param A
* @param n
*/
static div = (A: number[], n: number): number[] => {
return [A[0] / n, A[1] / n]
}
/**
* Vector division by vector.
* @param A
* @param n
*/
static divV = (A: number[], B: number[]): number[] => {
return [A[0] / B[0], A[1] / B[1]]
}
/**
* Perpendicular rotation of a vector A
* @param A
*/
static per = (A: number[]): number[] => {
return [A[1], -A[0]]
}
/**
* Dot product
* @param A
* @param B
*/
static dpr = (A: number[], B: number[]): number => {
return A[0] * B[0] + A[1] * B[1]
}
/**
* Cross product (outer product) | A X B |
* @param A
* @param B
*/
static cpr = (A: number[], B: number[]): number => {
return A[0] * B[1] - B[0] * A[1]
}
/**
* Cross (for point in polygon)
*
*/
static cross(x: number[], y: number[], z: number[]): number {
return (y[0] - x[0]) * (z[1] - x[1]) - (z[0] - x[0]) * (y[1] - x[1])
}
/**
* Length of the vector squared
* @param A
*/
static len2 = (A: number[]): number => {
return A[0] * A[0] + A[1] * A[1]
}
/**
* Length of the vector
* @param A
*/
static len = (A: number[]): number => {
return Math.hypot(A[0], A[1])
}
/**
* Project A over B
* @param A
* @param B
*/
static pry = (A: number[], B: number[]): number => {
return Vec.dpr(A, B) / Vec.len(B)
}
/**
* Get normalized / unit vector.
* @param A
*/
static uni = (A: number[]): number[] => {
return Vec.div(A, Vec.len(A))
}
/**
* Get normalized / unit vector.
* @param A
*/
static normalize = (A: number[]): number[] => {
return Vec.uni(A)
}
/**
* Get the tangent between two vectors.
* @param A
* @param B
* @returns
*/
static tangent = (A: number[], B: number[]): number[] => {
return Vec.uni(Vec.sub(A, B))
}
/**
* Dist length from A to B squared.
* @param A
* @param B
*/
static dist2 = (A: number[], B: number[]): number => {
return Vec.len2(Vec.sub(A, B))
}
/**
* Dist length from A to B
* @param A
* @param B
*/
static dist = (A: number[], B: number[]): number => {
return Math.hypot(A[1] - B[1], A[0] - B[0])
}
/**
* A faster, though less accurate method for testing distances. Maybe faster?
* @param A
* @param B
* @returns
*/
static fastDist = (A: number[], B: number[]): number[] => {
const V = [B[0] - A[0], B[1] - A[1]]
const aV = [Math.abs(V[0]), Math.abs(V[1])]
let r = 1 / Math.max(aV[0], aV[1])
r = r * (1.29289 - (aV[0] + aV[1]) * r * 0.29289)
return [V[0] * r, V[1] * r]
}
/**
* Angle between vector A and vector B in radians
* @param A
* @param B
*/
static ang = (A: number[], B: number[]): number => {
return Math.atan2(Vec.cpr(A, B), Vec.dpr(A, B))
}
/**
* Angle between vector A and vector B in radians
* @param A
* @param B
*/
static angle = (A: number[], B: number[]): number => {
return Math.atan2(B[1] - A[1], B[0] - A[0])
}
/**
* Mean between two vectors or mid vector between two vectors
* @param A
* @param B
*/
static med = (A: number[], B: number[]): number[] => {
return Vec.mul(Vec.add(A, B), 0.5)
}
/**
* Vector rotation by r (radians)
* @param A
* @param r rotation in radians
*/
static rot = (A: number[], r = 0): number[] => {
return [A[0] * Math.cos(r) - A[1] * Math.sin(r), A[0] * Math.sin(r) + A[1] * Math.cos(r)]
}
/**
* Rotate a vector around another vector by r (radians)
* @param A vector
* @param C center
* @param r rotation in radians
*/
static rotWith = (A: number[], C: number[], r = 0): number[] => {
if (r === 0) return A
const s = Math.sin(r)
const c = Math.cos(r)
const px = A[0] - C[0]
const py = A[1] - C[1]
const nx = px * c - py * s
const ny = px * s + py * c
return [nx + C[0], ny + C[1]]
}
/**
* Check of two vectors are identical.
* @param A
* @param B
*/
static isEqual = (A: number[], B: number[]): boolean => {
return A[0] === B[0] && A[1] === B[1]
}
/**
* Interpolate vector A to B with a scalar t
* @param A
* @param B
* @param t scalar
*/
static lrp = (A: number[], B: number[], t: number): number[] => {
return Vec.add(A, Vec.mul(Vec.sub(B, A), t))
}
/**
* Interpolate from A to B when curVAL goes fromVAL: number[] => to
* @param A
* @param B
* @param from Starting value
* @param to Ending value
* @param s Strength
*/
static int = (A: number[], B: number[], from: number, to: number, s = 1): number[] => {
const t = (Vec.clamp(from, to) - from) / (to - from)
return Vec.add(Vec.mul(A, 1 - t), Vec.mul(B, s))
}
/**
* Get the angle between the three vectors A, B, and C.
* @param p1
* @param pc
* @param p2
*/
static ang3 = (p1: number[], pc: number[], p2: number[]): number => {
// this,
const v1 = Vec.vec(pc, p1)
const v2 = Vec.vec(pc, p2)
return Vec.ang(v1, v2)
}
/**
* Absolute value of a vector.
* @param A
* @returns
*/
static abs = (A: number[]): number[] => {
return [Math.abs(A[0]), Math.abs(A[1])]
}
static rescale = (a: number[], n: number): number[] => {
const l = Vec.len(a)
return [(n * a[0]) / l, (n * a[1]) / l]
}
/**
* Get whether p1 is left of p2, relative to pc.
* @param p1
* @param pc
* @param p2
*/
static isLeft = (p1: number[], pc: number[], p2: number[]): number => {
// isLeft: >0 for counterclockwise
// =0 for none (degenerate)
// <0 for clockwise
return (pc[0] - p1[0]) * (p2[1] - p1[1]) - (p2[0] - p1[0]) * (pc[1] - p1[1])
}
static clockwise = (p1: number[], pc: number[], p2: number[]): boolean => {
return Vec.isLeft(p1, pc, p2) > 0
}
static round = (a: number[], d = 2): number[] => {
return a.map((v) => +v.toFixed(d))
}
/**
* Get the minimum distance from a point P to a line with a segment AB.
* @param A The start of the line.
* @param B The end of the line.
* @param P A point.
* @returns
*/
// static distanceToLine(A: number[], B: number[], P: number[]) {
// const delta = sub(B, A)
// const angle = Math.atan2(delta[1], delta[0])
// const dir = rot(sub(P, A), -angle)
// return dir[1]
// }
/**
* Get the nearest point on a line segment AB.
* @param A The start of the line.
* @param B The end of the line.
* @param P A point.
* @param clamp Whether to clamp the resulting point to the segment.
* @returns
*/
// static nearestPointOnLine(
// A: number[],
// B: number[],
// P: number[],
// clamp = true
// ) {
// const delta = sub(B, A)
// const length = len(delta)
// const angle = Math.atan2(delta[1], delta[0])
// const dir = rot(sub(P, A), -angle)
// if (clamp) {
// if (dir[0] < 0) return A
// if (dir[0] > length) return B
// }
// return add(A, div(mul(delta, dir[0]), length))
// }
/**
* Get the nearest point on a line with a known unit vector that passes through point A
* @param A Any point on the line
* @param u The unit vector for the line.
* @param P A point not on the line to test.
* @returns
*/
static nearestPointOnLineThroughPoint = (A: number[], u: number[], P: number[]): number[] => {
return Vec.add(A, Vec.mul(u, Vec.pry(Vec.sub(P, A), u)))
}
/**
* Distance between a point and a line with a known unit vector that passes through a point.
* @param A Any point on the line
* @param u The unit vector for the line.
* @param P A point not on the line to test.
* @returns
*/
static distanceToLineThroughPoint = (A: number[], u: number[], P: number[]): number => {
return Vec.dist(P, Vec.nearestPointOnLineThroughPoint(A, u, P))
}
/**
* Get the nearest point on a line segment between A and B
* @param A The start of the line segment
* @param B The end of the line segment
* @param P The off-line point
* @param clamp Whether to clamp the point between A and B.
* @returns
*/
static nearestPointOnLineSegment = (
A: number[],
B: number[],
P: number[],
clamp = true
): number[] => {
const u = Vec.uni(Vec.sub(B, A))
const C = Vec.add(A, Vec.mul(u, Vec.pry(Vec.sub(P, A), u)))
if (clamp) {
if (C[0] < Math.min(A[0], B[0])) return A[0] < B[0] ? A : B
if (C[0] > Math.max(A[0], B[0])) return A[0] > B[0] ? A : B
if (C[1] < Math.min(A[1], B[1])) return A[1] < B[1] ? A : B
if (C[1] > Math.max(A[1], B[1])) return A[1] > B[1] ? A : B
}
return C
}
/**
* Distance between a point and the nearest point on a line segment between A and B
* @param A The start of the line segment
* @param B The end of the line segment
* @param P The off-line point
* @param clamp Whether to clamp the point between A and B.
* @returns
*/
static distanceToLineSegment = (A: number[], B: number[], P: number[], clamp = true): number => {
return Vec.dist(P, Vec.nearestPointOnLineSegment(A, B, P, clamp))
}
/**
* Push a point A towards point B by a given distance.
* @param A
* @param B
* @param d
* @returns
*/
static nudge = (A: number[], B: number[], d: number): number[] => {
return Vec.add(A, Vec.mul(Vec.uni(Vec.sub(B, A)), d))
}
/**
* Push a point in a given angle by a given distance.
* @param A
* @param B
* @param d
*/
static nudgeAtAngle = (A: number[], a: number, d: number): number[] => {
return [Math.cos(a) * d + A[0], Math.sin(a) * d + A[1]]
}
/**
* Round a vector to a precision length.
* @param a
* @param n
*/
static toPrecision = (a: number[], n = 4): number[] => {
return [+a[0].toPrecision(n), +a[1].toPrecision(n)]
}
/**
* Get an array of points (with simulated pressure) between two points.
* @param A The first point.
* @param B The second point.
* @param steps The number of points to return.
* @param ease An easing function to apply to the simulated pressure.
*/
static pointsBetween = (A: number[], B: number[], steps = 6): number[][] => {
return Array.from(Array(steps)).map((_, i) => {
const t = i / (steps - 1)
const k = Math.min(1, 0.5 + Math.abs(0.5 - t))
return [...Vec.lrp(A, B, t), k]
})
}
}
export default Vec

View file

@ -1,19 +0,0 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"**/*.test.tsx",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.spec.ts",
"src/test",
"dist",
"docs"
],
"compilerOptions": {
"composite": false,
"incremental": false,
"declarationMap": false,
"sourceMap": false
}
}

View file

@ -1,15 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["node_modules", "dist", "docs"],
"compilerOptions": {
"outDir": "./dist/types",
"rootDir": "src",
"baseUrl": "src",
"emitDeclarationOnly": false
},
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,11 @@
"compilerOptions": {
"composite": true,
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
@ -11,19 +15,29 @@
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
"rootDir": ".",
"paths": {
"-*": ["./*"],
"@tldraw/tldraw": ["../tldraw"]
"-*": [
"./*"
],
"@tldraw/tldraw": [
"../tldraw"
]
},
"incremental": true
"incremental": true,
"resolveJsonModule": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
],
"references": [
{
"path": "../tldraw"

View file

@ -3,17 +3,11 @@
"extends": "./tsconfig.base.json",
"exclude": ["node_modules", "**/*.test.ts", "**/*.spec.ts"],
"files": [],
"references": [
{ "path": "./packages/vec" },
{ "path": "./packages/intersect" },
{ "path": "./packages/tldraw" }
],
"references": [{ "path": "./packages/tldraw" }],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@tldraw/tldraw": ["./packages/tldraw"],
"@tldraw/vec": ["./packages/vec"],
"@tldraw/intersect": ["./packages/intersect"],
"~*": ["./packages/tldraw/src/*"]
}
}

1740
yarn.lock

File diff suppressed because it is too large Load diff