From 1df6d931d0b635bf2ba7ce981ec4e4ac87651089 Mon Sep 17 00:00:00 2001 From: Alexis Quintero Date: Sat, 3 Oct 2026 16:36:18 -0500 Subject: [PATCH] feat: fit FASTA lines to the panel width (v0.3.1) The viewer measures its width and shows whole blocks of ten bases per line (20-80), so it never scrolls sideways; copied and downloaded FASTA keep 70 columns. Co-Authored-By: Claude Opus 5.5 --- CITATION.cff | 2 +- package.json | 2 +- src/ui/FastaView.tsx | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 60f19a7..4ca2bcc 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ cff-version: 1.2.0 message: "Si usas este software, por favor cítalo así. / If you use this software, please cite it as below." title: "Vector editor: in-browser cloning simulator with REBASE enzymes" type: software -version: 0.3.0 +version: 0.3.1 authors: - family-names: "Quintero López" given-names: "Oscar Alexis" diff --git a/package.json b/package.json index 9796201..cbaa8a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oquinterol/vector-editor", - "version": "0.3.0", + "version": "0.3.1", "description": "In-browser cloning simulator: choose commercial or custom restriction enzymes, digest and ligate, and get a live FASTA and plasmid map.", "license": "MIT", "author": "Oscar Alexis Quintero López (https://oquinterol.com)", diff --git a/src/ui/FastaView.tsx b/src/ui/FastaView.tsx index b5da59f..978c4a2 100644 --- a/src/ui/FastaView.tsx +++ b/src/ui/FastaView.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useRef } from 'react' +import React, { useEffect, useMemo, useRef, useState } from 'react' import type { Site } from '../core' export interface Region { @@ -23,6 +23,7 @@ interface Props { range: SeqRange | null rangeSource: RangeSource | null onRange: (range: SeqRange) => void + /** Fixed bases per line; by default it fits the panel width (multiples of 10). */ width?: number label: string } @@ -34,8 +35,45 @@ export function inRange(range: SeqRange, i: number): boolean { } /** The FASTA of the plasmid with every base coloured by what it belongs to. */ -export function FastaView({ header, seq, regions, sites, range, rangeSource, onRange, width = 60, label }: Props) { +export function FastaView({ + header, + seq, + regions, + sites, + range, + rangeSource, + onRange, + width: fixedWidth, + label +}: Props) { const box = useRef(null) + const [fitWidth, setFitWidth] = useState(60) + const width = fixedWidth ?? fitWidth + + // Fit whole blocks of ten bases to the panel, so lines never scroll sideways. + useEffect(() => { + const element = box.current + if (!element || fixedWidth || typeof ResizeObserver === 'undefined') return + const probe = document.createElement('span') + probe.textContent = 'ACGTACGTAC' + probe.style.cssText = 'position:absolute;visibility:hidden;white-space:pre' + element.appendChild(probe) + const measure = () => { + const charWidth = probe.getBoundingClientRect().width / 10 + const style = getComputedStyle(element) + const inner = element.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight) + const gutter = charWidth * 8 // position column + gap + const blocks = Math.floor((inner - gutter) / (charWidth * 10)) + if (charWidth > 0) setFitWidth(Math.min(80, Math.max(20, blocks * 10))) + } + measure() + const observer = new ResizeObserver(measure) + observer.observe(element) + return () => { + observer.disconnect() + probe.remove() + } + }, [fixedWidth]) // Per-base region kind and recognition-site mask, recomputed only when the plasmid changes. const { kind, site } = useMemo(() => {