Download frontend/src/lib/editor/text-transform.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/editor/text-transform.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/lib/editor/text-transform.ts
-
curl -L -o text-transform.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/lib/editor/text-transform.ts
1.15 kB
| import { clamp, type TextTransform } from "./document"; | |
| import type { TextBounds } from "./render"; | |
| export type TextCorner = "nw" | "ne" | "sw" | "se"; | |
| export const TEXT_CORNERS: TextCorner[] = ["nw", "ne", "sw", "se"]; | |
| export function keepTextInFrame(transform: TextTransform, bounds: TextBounds, width: number, height: number): TextTransform { | |
| const shift = (start: number, length: number, limit: number) => length > limit - 16 | |
| ? (limit - length) / 2 - start | |
| : clamp(start, 8, limit - length - 8) - start; | |
| return { ...transform, x: clamp(transform.x + shift(bounds.x, bounds.width, width) / width, -1, 1), y: clamp(transform.y + shift(bounds.y, bounds.height, height) / height, -1, 1) }; | |
| } | |
| /** Uniform corner resize about the opposite corner, using both pointer axes. */ | |
| export function resizeTextScale(bounds: TextBounds, corner: TextCorner, dx: number, dy: number, initial: number) { | |
| const x = corner.endsWith("e") ? bounds.width : -bounds.width; | |
| const y = corner.startsWith("s") ? bounds.height : -bounds.height; | |
| const ratio = 1 + (dx * x + dy * y) / Math.max(1, x * x + y * y); | |
| return clamp(initial * ratio, 0.25, 4); | |
| } | |