UNPKG

tldraw

Version:

A tiny little drawing editor.

61 lines (60 loc) 2.36 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var crop_helpers_exports = {}; __export(crop_helpers_exports, { getTranslateCroppedImageChange: () => getTranslateCroppedImageChange }); module.exports = __toCommonJS(crop_helpers_exports); var import_editor = require("@tldraw/editor"); var import_crop = require("../../../../../shapes/shared/crop"); function getTranslateCroppedImageChange(editor, shape, delta) { if (!shape) { throw Error("Needs to translate a cropped shape!"); } const { crop: oldCrop } = shape.props; if (!oldCrop) { return; } const flatten = editor.inputs.getShiftKey() ? Math.abs(delta.x) < Math.abs(delta.y) ? "x" : "y" : null; if (flatten === "x") { delta.x = 0; } else if (flatten === "y") { delta.y = 0; } delta.rot(-shape.rotation); const { w, h } = (0, import_crop.getUncroppedSize)(shape.props, oldCrop); const xCropSize = oldCrop.bottomRight.x - oldCrop.topLeft.x; const yCropSize = oldCrop.bottomRight.y - oldCrop.topLeft.y; const newCrop = (0, import_editor.structuredClone)(oldCrop); const xMinWithCrop = 1 - xCropSize; const yMinWithCrop = 1 - yCropSize; newCrop.topLeft.x = (0, import_editor.clamp)(newCrop.topLeft.x - delta.x / w, 0, xMinWithCrop); newCrop.topLeft.y = (0, import_editor.clamp)(newCrop.topLeft.y - delta.y / h, 0, yMinWithCrop); newCrop.bottomRight.x = newCrop.topLeft.x + xCropSize; newCrop.bottomRight.y = newCrop.topLeft.y + yCropSize; const partial = { id: shape.id, type: shape.type, props: { crop: newCrop } }; return partial; } //# sourceMappingURL=crop_helpers.js.map