UNPKG

react-mosaic-component2

Version:
103 lines (101 loc) 3.38 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); // src/util/BoundingBox.ts var BoundingBox_exports = {}; __export(BoundingBox_exports, { BoundingBox: () => BoundingBox }); module.exports = __toCommonJS(BoundingBox_exports); var import_assertNever = require("./assertNever.cjs"); var BoundingBox; ((BoundingBox2) => { function empty() { return { top: 0, right: 0, bottom: 0, left: 0 }; } BoundingBox2.empty = empty; function split(boundingBox, relativeSplitPercentage, direction) { const absolutePercentage = getAbsoluteSplitPercentage(boundingBox, relativeSplitPercentage, direction); if (direction === "column") { return { first: { ...boundingBox, bottom: 100 - absolutePercentage }, second: { ...boundingBox, top: absolutePercentage } }; } else if (direction === "row") { return { first: { ...boundingBox, right: 100 - absolutePercentage }, second: { ...boundingBox, left: absolutePercentage } }; } else { return (0, import_assertNever.assertNever)(direction); } } BoundingBox2.split = split; function getAbsoluteSplitPercentage(boundingBox, relativeSplitPercentage, direction) { const { top, right, bottom, left } = boundingBox; if (direction === "column") { const height = 100 - top - bottom; return height * relativeSplitPercentage / 100 + top; } else if (direction === "row") { const width = 100 - right - left; return width * relativeSplitPercentage / 100 + left; } else { return (0, import_assertNever.assertNever)(direction); } } BoundingBox2.getAbsoluteSplitPercentage = getAbsoluteSplitPercentage; function getRelativeSplitPercentage(boundingBox, absoluteSplitPercentage, direction) { const { top, right, bottom, left } = boundingBox; if (direction === "column") { const height = 100 - top - bottom; return (absoluteSplitPercentage - top) / height * 100; } else if (direction === "row") { const width = 100 - right - left; return (absoluteSplitPercentage - left) / width * 100; } else { return (0, import_assertNever.assertNever)(direction); } } BoundingBox2.getRelativeSplitPercentage = getRelativeSplitPercentage; function asStyles({ top, right, bottom, left }) { return { top: `${top}%`, right: `${right}%`, bottom: `${bottom}%`, left: `${left}%` }; } BoundingBox2.asStyles = asStyles; })(BoundingBox || (BoundingBox = {}));