This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import merge from 'deepmerge' | |
| import * as idb from 'idb-keyval' | |
| import createReact, { UseStore } from 'zustand' | |
| import createVanilla, { StoreApi } from 'zustand/vanilla' | |
| // Types | |
| export type Patch<T> = Partial<{ [P in keyof T]: Patch<T[P]> }> | |
| export type Command<T> = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get the relative bounds (usually a child) within a transformed bounding box. | |
| */ | |
| function getRelativeTransformedBoundingBox( | |
| bounds: TLBounds, | |
| initialBounds: TLBounds, | |
| initialShapeBounds: TLBounds, | |
| isFlippedX: boolean, | |
| isFlippedY: boolean, | |
| ): TLBounds { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // pages/api/auth/[...nextAuth].ts | |
| import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next' | |
| import NextAuth from 'next-auth' | |
| import Providers from 'next-auth/providers' | |
| export default function Auth( | |
| req: NextApiRequest, | |
| res: NextApiResponse | |
| ): ReturnType<NextApiHandler> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A big collection of vector utilities. Collected into a class to improve logging / packaging. | |
| /* ----------------- Start Copy Here ---------------- */ | |
| export default class Vec { | |
| /** | |
| * Clamp a value into a range. | |
| * @param n | |
| * @param min | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { FC } from 'react' | |
| import { useCodeMirror } from './useCodeMirror' | |
| interface Props { | |
| content: string | |
| classNames?: string | |
| onContentChange: (content: string) => void | |
| } | |
| export const CodeMirror: FC<Props> = ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Run this code on tldraw.com | |
| // By @steveruizok | |
| // Based on an awesome image by @cacheflowe: https://twitter.com/cacheflowe/status/1408902719130288130 | |
| new NumberControl({ | |
| label: 'radius', | |
| value: 200, | |
| min: 50, | |
| max: 500, | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fillRectangleWithLines( | |
| shape: Rectangle, | |
| gap: number, | |
| messiness = 0.5 | |
| ) { | |
| const { size } = shape | |
| const rng = Utils.rng(shape.shape.id) | |
| const gapX = size[0] / (Math.floor((size[0] - gap) / gap) / 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get the intersection of two rays, with origin points p0 and p1, and direction vectors n0 and n1. | |
| * @param p0 The origin point of the first ray | |
| * @param n0 The direction vector of the first ray | |
| * @param p1 The origin point of the second ray | |
| * @param n1 The direction vector of the second ray | |
| * @returns | |
| */ | |
| export function getRaysIntersection( | |
| p0: number[], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Find the closest point on a SVG path to an off-path point. | |
| * @param pathNode | |
| * @param point | |
| * @returns | |
| */ | |
| export function getClosestPointOnSVGPath( | |
| pathNode: SVGPathElement, | |
| point: number[] | |
| ): { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copy a string to the clipboard. | |
| * @param string | |
| */ | |
| export function copyToClipboard(string: string): boolean { | |
| let textarea: HTMLTextAreaElement | |
| let result: boolean | |
| try { |