Skip to content

Commit 14fd977

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
fix(alignment): replace html2canvas with dom-to-image-more to support oklch colors
1 parent f0119c0 commit 14fd977

6 files changed

Lines changed: 38 additions & 38 deletions

File tree

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"@types/peerjs": "^0.0.30",
1515
"@types/qrcode": "^1.5.6",
1616
"clsx": "^2.1.1",
17+
"dom-to-image-more": "^3.7.2",
1718
"driver.js": "^1.4.0",
18-
"html2canvas": "^1.4.1",
1919
"jspdf": "^3.0.4",
2020
"jspdf-autotable": "^5.0.2",
2121
"lucide-react": "^0.562.0",

src/components/SequenceAlignmentModal.tsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useMemo, useState, useRef } from 'react';
22
import { X, GitCommitVertical, AlertTriangle, FileText, BarChart2, Hash, Percent, Download, Activity, Image, MessageSquare, ChevronDown } from 'lucide-react';
33
import type { ChainInfo, SuperposedStructure } from '../types';
44
import clsx from 'clsx';
5-
import html2canvas from 'html2canvas';
5+
import domtoimage from 'dom-to-image-more';
66

77
interface SequenceAlignmentModalProps {
88
isOpen: boolean;
@@ -282,31 +282,25 @@ export const SequenceAlignmentModal: React.FC<SequenceAlignmentModalProps> = ({
282282

283283
try {
284284
console.log('Starting PNG export...');
285-
const canvas = await html2canvas(modalRef.current, {
286-
backgroundColor: '#0D1117',
285+
const dataUrl = await domtoimage.toPng(modalRef.current, {
286+
quality: 1,
287+
bgcolor: '#0D1117',
287288
scale: 2,
288-
logging: false,
289-
useCORS: true,
290-
allowTaint: true
289+
style: {
290+
transform: 'scale(1)',
291+
transformOrigin: 'top left'
292+
}
291293
});
292294

293-
console.log('Canvas created successfully');
294-
295-
canvas.toBlob((blob) => {
296-
if (blob) {
297-
const url = URL.createObjectURL(blob);
298-
const a = document.createElement('a');
299-
a.href = url;
300-
a.download = `sequence_alignment_${Date.now()}.png`;
301-
document.body.appendChild(a);
302-
a.click();
303-
document.body.removeChild(a);
304-
URL.revokeObjectURL(url);
305-
console.log('PNG exported successfully');
306-
} else {
307-
alert('Failed to create image blob');
308-
}
309-
}, 'image/png');
295+
console.log('Image created successfully');
296+
297+
const link = document.createElement('a');
298+
link.download = `sequence_alignment_${Date.now()}.png`;
299+
link.href = dataUrl;
300+
document.body.appendChild(link);
301+
link.click();
302+
document.body.removeChild(link);
303+
console.log('PNG exported successfully');
310304
} catch (error) {
311305
console.error('Failed to export image:', error);
312306
alert(`Export failed: ${error instanceof Error ? error.message : 'Unknown error'}`);

src/dom-to-image-more.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'dom-to-image-more' {
2+
export function toPng(node: HTMLElement, options?: any): Promise<string>;
3+
export function toJpeg(node: HTMLElement, options?: any): Promise<string>;
4+
export function toBlob(node: HTMLElement, options?: any): Promise<Blob>;
5+
export function toPixelData(node: HTMLElement, options?: any): Promise<Uint8ClampedArray>;
6+
export function toSvg(node: HTMLElement, options?: any): Promise<string>;
7+
}

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export interface ChainInfo {
4747
atoms?: AtomInfo[]; // Added: For small chemicals, list atoms directly
4848
bFactors?: number[]; // Added: Per-residue B-factor for coloring sync
4949
coords?: { x: number; y: number; z: number }[]; // Added: C-alpha/P coordinates for RMSD
50-
secondaryStructure?: string[]; // Added: Secondary structure codes (H, E, C)
5150
}
5251

5352
export interface StructureInfo {

src/utils/pdbUtils.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ export const extractChainsFromComponent = (component: any, matrix?: number[]): {
152152
const resMap: number[] = [];
153153
const bFactors: number[] = [];
154154
const coords: { x: number, y: number, z: number }[] = [];
155-
const secStrucs: string[] = [];
156155

157156
try {
158157
c.eachResidue((r: any) => {
@@ -197,15 +196,6 @@ export const extractChainsFromComponent = (component: any, matrix?: number[]): {
197196
coords.push({ x: 0, y: 0, z: 0 }); // Should theoretically not happen
198197
}
199198

200-
// Secondary Structure Extraction
201-
let ssCode = 'C';
202-
if (r.sstruc) {
203-
const s = r.sstruc.toLowerCase();
204-
if (['h', 'g', 'i'].includes(s)) ssCode = 'H';
205-
else if (['e', 'b'].includes(s)) ssCode = 'E';
206-
}
207-
secStrucs.push(ssCode);
208-
209199
// Determine Type
210200
if (r.isNucleic()) nucleicCount++;
211201
else if (r.isProtein()) proteinCount++;
@@ -263,8 +253,7 @@ export const extractChainsFromComponent = (component: any, matrix?: number[]): {
263253
type: chainType,
264254
atoms: atomList.length > 0 ? atomList : undefined,
265255
bFactors: bFactors,
266-
coords: coords, // Added field
267-
secondaryStructure: secStrucs
256+
coords: coords // Added field
268257
});
269258
});
270259

0 commit comments

Comments
 (0)