react-msaview 5.1.1 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +41 -8
  2. package/bundle/index.js +17 -17
  3. package/bundle/index.js.LICENSE.txt +1 -1
  4. package/bundle/index.js.map +1 -1
  5. package/dist/calculateBlocks.d.ts +4 -10
  6. package/dist/calculateBlocks.js +12 -20
  7. package/dist/calculateBlocks.js.map +1 -1
  8. package/dist/components/ConservationTrack.js +20 -37
  9. package/dist/components/ConservationTrack.js.map +1 -1
  10. package/dist/components/MSAView.js +8 -1
  11. package/dist/components/MSAView.js.map +1 -1
  12. package/dist/components/ResizeHandles.d.ts +3 -0
  13. package/dist/components/ResizeHandles.js +60 -105
  14. package/dist/components/ResizeHandles.js.map +1 -1
  15. package/dist/components/TextTrack.js +25 -34
  16. package/dist/components/TextTrack.js.map +1 -1
  17. package/dist/components/Track.js +1 -1
  18. package/dist/components/Track.js.map +1 -1
  19. package/dist/components/VerticalScrollbar.js +2 -2
  20. package/dist/components/VerticalScrollbar.js.map +1 -1
  21. package/dist/components/dialogs/ExportSVGDialog.js +20 -20
  22. package/dist/components/dialogs/ExportSVGDialog.js.map +1 -1
  23. package/dist/components/dialogs/InterProScanDialog.js +6 -1
  24. package/dist/components/dialogs/InterProScanDialog.js.map +1 -1
  25. package/dist/components/dialogs/UserProvidedDomainsDialog.js +1 -2
  26. package/dist/components/dialogs/UserProvidedDomainsDialog.js.map +1 -1
  27. package/dist/components/header/ColorSchemeMenu.js +1 -1
  28. package/dist/components/header/ColorSchemeMenu.js.map +1 -1
  29. package/dist/components/header/FileMenu.js +3 -2
  30. package/dist/components/header/FileMenu.js.map +1 -1
  31. package/dist/components/header/Header.js +1 -1
  32. package/dist/components/header/HeaderInfoArea.js +28 -8
  33. package/dist/components/header/HeaderInfoArea.js.map +1 -1
  34. package/dist/components/header/MSASettingsMenu.js +1 -1
  35. package/dist/components/header/MSASettingsMenu.js.map +1 -1
  36. package/dist/components/header/TreeSettingsMenu.js +1 -1
  37. package/dist/components/header/TreeSettingsMenu.js.map +1 -1
  38. package/dist/components/header/ZoomControls.js +7 -2
  39. package/dist/components/header/ZoomControls.js.map +1 -1
  40. package/dist/components/header/ZoomMenu.js +9 -0
  41. package/dist/components/header/ZoomMenu.js.map +1 -1
  42. package/dist/components/header/settingsMenuItems.js +24 -8
  43. package/dist/components/header/settingsMenuItems.js.map +1 -1
  44. package/dist/components/minimap/Minimap.js +6 -17
  45. package/dist/components/minimap/Minimap.js.map +1 -1
  46. package/dist/components/minimap/MinimapSVG.js +7 -17
  47. package/dist/components/minimap/MinimapSVG.js.map +1 -1
  48. package/dist/components/minimap/minimapLayout.d.ts +9 -0
  49. package/dist/components/minimap/minimapLayout.js +15 -0
  50. package/dist/components/minimap/minimapLayout.js.map +1 -0
  51. package/dist/components/msa/MSACanvas.js +6 -1
  52. package/dist/components/msa/MSACanvas.js.map +1 -1
  53. package/dist/components/msa/MSACanvasBlock.js +5 -1
  54. package/dist/components/msa/MSACanvasBlock.js.map +1 -1
  55. package/dist/components/msa/MSAMouseoverCanvas.js +2 -2
  56. package/dist/components/msa/MSAMouseoverCanvas.js.map +1 -1
  57. package/dist/components/msa/getVisibleLeaves.d.ts +6 -0
  58. package/dist/components/msa/getVisibleLeaves.js +9 -0
  59. package/dist/components/msa/getVisibleLeaves.js.map +1 -0
  60. package/dist/components/msa/renderBoxFeatureCanvasBlock.d.ts +2 -1
  61. package/dist/components/msa/renderBoxFeatureCanvasBlock.js +5 -6
  62. package/dist/components/msa/renderBoxFeatureCanvasBlock.js.map +1 -1
  63. package/dist/components/msa/renderMSABlock.d.ts +2 -1
  64. package/dist/components/msa/renderMSABlock.js +100 -88
  65. package/dist/components/msa/renderMSABlock.js.map +1 -1
  66. package/dist/components/msa/renderMSAMouseover.js +5 -4
  67. package/dist/components/msa/renderMSAMouseover.js.map +1 -1
  68. package/dist/components/msa/visibleColRange.d.ts +8 -0
  69. package/dist/components/msa/visibleColRange.js +10 -0
  70. package/dist/components/msa/visibleColRange.js.map +1 -0
  71. package/dist/components/renderCtx.d.ts +7 -0
  72. package/dist/components/renderCtx.js +2 -0
  73. package/dist/components/renderCtx.js.map +1 -0
  74. package/dist/components/tracks/renderTracksSvg.d.ts +6 -5
  75. package/dist/components/tracks/renderTracksSvg.js +13 -5
  76. package/dist/components/tracks/renderTracksSvg.js.map +1 -1
  77. package/dist/components/tree/TreeCanvas.js.map +1 -1
  78. package/dist/components/tree/TreeCanvasBlock.js +2 -10
  79. package/dist/components/tree/TreeCanvasBlock.js.map +1 -1
  80. package/dist/components/tree/renderTreeCanvas.d.ts +5 -4
  81. package/dist/components/tree/renderTreeCanvas.js +18 -26
  82. package/dist/components/tree/renderTreeCanvas.js.map +1 -1
  83. package/dist/components/util.d.ts +0 -14
  84. package/dist/components/util.js +0 -58
  85. package/dist/components/util.js.map +1 -1
  86. package/dist/constants.d.ts +4 -0
  87. package/dist/constants.js +7 -0
  88. package/dist/constants.js.map +1 -1
  89. package/dist/flatToTree.js +6 -0
  90. package/dist/flatToTree.js.map +1 -1
  91. package/dist/hierarchy.d.ts +3 -1
  92. package/dist/hierarchy.js +142 -89
  93. package/dist/hierarchy.js.map +1 -1
  94. package/dist/index.d.ts +1 -0
  95. package/dist/index.js +8 -0
  96. package/dist/index.js.map +1 -1
  97. package/dist/launchInterProScan.js +22 -9
  98. package/dist/launchInterProScan.js.map +1 -1
  99. package/dist/measureTextCanvas.js +2 -1
  100. package/dist/measureTextCanvas.js.map +1 -1
  101. package/dist/model.d.ts +234 -176
  102. package/dist/model.js +285 -259
  103. package/dist/model.js.map +1 -1
  104. package/dist/parseAsn1.js +8 -2
  105. package/dist/parseAsn1.js.map +1 -1
  106. package/dist/renderToSvg.d.ts +1 -1
  107. package/dist/renderToSvg.js +43 -46
  108. package/dist/renderToSvg.js.map +1 -1
  109. package/dist/rowCoordinateCalculations.d.ts +0 -9
  110. package/dist/rowCoordinateCalculations.js +0 -20
  111. package/dist/rowCoordinateCalculations.js.map +1 -1
  112. package/dist/setFontSize.d.ts +3 -0
  113. package/dist/setFontSize.js +14 -0
  114. package/dist/setFontSize.js.map +1 -0
  115. package/dist/useDevicePixelRatio.d.ts +1 -0
  116. package/dist/useDevicePixelRatio.js +27 -0
  117. package/dist/useDevicePixelRatio.js.map +1 -0
  118. package/dist/useWheelScroll.d.ts +3 -1
  119. package/dist/useWheelScroll.js +64 -22
  120. package/dist/useWheelScroll.js.map +1 -1
  121. package/dist/util.d.ts +5 -0
  122. package/dist/util.js +59 -1
  123. package/dist/util.js.map +1 -1
  124. package/dist/version.d.ts +1 -1
  125. package/dist/version.js +1 -1
  126. package/dist/webpack.js +0 -1
  127. package/dist/webpack.js.map +1 -1
  128. package/dist/wheelZoom.d.ts +4 -0
  129. package/dist/wheelZoom.js +43 -0
  130. package/dist/wheelZoom.js.map +1 -0
  131. package/package.json +5 -5
  132. package/src/calculateBlocks.ts +18 -51
  133. package/src/components/ConservationTrack.tsx +20 -45
  134. package/src/components/MSAView.tsx +10 -1
  135. package/src/components/ResizeHandles.tsx +101 -113
  136. package/src/components/TextTrack.tsx +31 -38
  137. package/src/components/Track.tsx +1 -1
  138. package/src/components/VerticalScrollbar.tsx +2 -2
  139. package/src/components/dialogs/ExportSVGDialog.tsx +27 -17
  140. package/src/components/dialogs/InterProScanDialog.tsx +6 -1
  141. package/src/components/dialogs/UserProvidedDomainsDialog.tsx +1 -2
  142. package/src/components/header/ColorSchemeMenu.tsx +1 -0
  143. package/src/components/header/FileMenu.tsx +3 -1
  144. package/src/components/header/Header.tsx +1 -1
  145. package/src/components/header/HeaderInfoArea.tsx +32 -7
  146. package/src/components/header/MSASettingsMenu.tsx +1 -0
  147. package/src/components/header/TreeSettingsMenu.tsx +1 -0
  148. package/src/components/header/ZoomControls.tsx +14 -1
  149. package/src/components/header/ZoomMenu.tsx +10 -0
  150. package/src/components/header/settingsMenuItems.ts +24 -8
  151. package/src/components/minimap/Minimap.tsx +6 -20
  152. package/src/components/minimap/MinimapSVG.tsx +10 -27
  153. package/src/components/minimap/minimapLayout.ts +17 -0
  154. package/src/components/msa/MSACanvas.tsx +9 -0
  155. package/src/components/msa/MSACanvasBlock.tsx +7 -1
  156. package/src/components/msa/MSAMouseoverCanvas.tsx +4 -3
  157. package/src/components/msa/getVisibleLeaves.ts +21 -0
  158. package/src/components/msa/renderBoxFeatureCanvasBlock.ts +9 -9
  159. package/src/components/msa/renderMSABlock.ts +123 -125
  160. package/src/components/msa/renderMSAMouseover.ts +5 -4
  161. package/src/components/msa/visibleColRange.ts +17 -0
  162. package/src/components/renderCtx.ts +29 -0
  163. package/src/components/tracks/renderTracksSvg.ts +20 -10
  164. package/src/components/tree/TreeCanvas.tsx +3 -1
  165. package/src/components/tree/TreeCanvasBlock.tsx +2 -12
  166. package/src/components/tree/renderTreeCanvas.ts +27 -30
  167. package/src/components/util.ts +0 -81
  168. package/src/constants.ts +8 -0
  169. package/src/flatToTree.test.ts +30 -0
  170. package/src/flatToTree.ts +10 -1
  171. package/src/hierarchy.test.ts +53 -1
  172. package/src/hierarchy.ts +153 -100
  173. package/src/index.ts +8 -0
  174. package/src/launchInterProScan.ts +33 -11
  175. package/src/measureTextCanvas.ts +3 -1
  176. package/src/model.ts +359 -306
  177. package/src/parseAsn1.test.ts +6 -0
  178. package/src/parseAsn1.ts +11 -3
  179. package/src/renderToSvg.tsx +99 -95
  180. package/src/rowCoordinateCalculations.test.ts +0 -51
  181. package/src/rowCoordinateCalculations.ts +0 -23
  182. package/src/setFontSize.test.ts +33 -0
  183. package/src/setFontSize.ts +20 -0
  184. package/src/useDevicePixelRatio.ts +29 -0
  185. package/src/useWheelScroll.ts +79 -21
  186. package/src/util.ts +60 -1
  187. package/src/version.ts +1 -1
  188. package/src/webpack.ts +0 -1
  189. package/src/wheelZoom.test.ts +46 -0
  190. package/src/wheelZoom.ts +47 -0
package/src/util.ts CHANGED
@@ -1,9 +1,33 @@
1
1
  import { colord, extend } from 'colord'
2
+ import a11yPlugin from 'colord/plugins/a11y'
2
3
  import namesPlugin from 'colord/plugins/names'
3
4
 
4
5
  import type { Theme } from '@mui/material'
5
6
 
6
- extend([namesPlugin])
7
+ extend([namesPlugin, a11yPlugin])
8
+
9
+ const contrastAdjustCache = new Map<string, string>()
10
+
11
+ // Adjusts a background-tile color until it meets WCAG AA (4.5:1) contrast
12
+ // against `bg`, so it can be used as letter text in letter-color mode.
13
+ // Darkens on light backgrounds, lightens on dark backgrounds.
14
+ export function adjustColorForContrast(color: string, bg: string): string {
15
+ const cacheKey = `${color}|${bg}`
16
+ const cached = contrastAdjustCache.get(cacheKey)
17
+ if (cached !== undefined) {
18
+ return cached
19
+ }
20
+ let c = colord(color)
21
+ if (!c.isReadable(bg)) {
22
+ const bgIsDark = colord(bg).luminance() < 0.5
23
+ for (let i = 0; i < 40 && !c.isReadable(bg); i++) {
24
+ c = bgIsDark ? c.lighten(0.05) : c.darken(0.05)
25
+ }
26
+ }
27
+ const result = c.toHex()
28
+ contrastAdjustCache.set(cacheKey, result)
29
+ return result
30
+ }
7
31
 
8
32
  export function transform<T>(
9
33
  obj: Record<string, T>,
@@ -40,6 +64,41 @@ export function skipBlanks(blanks: number[], str: string) {
40
64
  return chunks.join('')
41
65
  }
42
66
 
67
+ export function computeRowInsertions(blanks: number[], seq: string) {
68
+ const insertions: { pos: number; letters: string }[] = []
69
+ const blanksLen = blanks.length
70
+ let displayPos = 0
71
+ let blankIdx = 0
72
+ let currentInsertPos = -1
73
+ let letterChars: string[] = []
74
+ for (let i = 0; i < seq.length; i++) {
75
+ if (blankIdx < blanksLen && blanks[blankIdx] === i) {
76
+ // bit trick: (code - 45) >>> 0 <= 1 checks for '-' (45) or '.' (46)
77
+ if (!((seq.charCodeAt(i) - 45) >>> 0 <= 1)) {
78
+ if (currentInsertPos === displayPos) {
79
+ letterChars.push(seq[i]!)
80
+ } else {
81
+ if (letterChars.length > 0) {
82
+ insertions.push({
83
+ pos: currentInsertPos,
84
+ letters: letterChars.join(''),
85
+ })
86
+ }
87
+ currentInsertPos = displayPos
88
+ letterChars = [seq[i]!]
89
+ }
90
+ }
91
+ blankIdx++
92
+ } else {
93
+ displayPos++
94
+ }
95
+ }
96
+ if (letterChars.length > 0) {
97
+ insertions.push({ pos: currentInsertPos, letters: letterChars.join('') })
98
+ }
99
+ return insertions
100
+ }
101
+
43
102
  export function len(a: { end: number; start: number }) {
44
103
  return a.end - a.start
45
104
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.1.1'
1
+ export const version = '5.2.1'
package/src/webpack.ts CHANGED
@@ -5,5 +5,4 @@ export { type MsaViewModel, default as MSAModelF } from './model.ts'
5
5
 
6
6
  export * from 'react-dom/client'
7
7
 
8
- // eslint-disable-next-line unicorn/prefer-export-from
9
8
  export { React }
@@ -0,0 +1,46 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ import {
4
+ getZoomNormalizer,
5
+ normalizeWheelDelta,
6
+ zoomFactorFromAccum,
7
+ } from './wheelZoom.ts'
8
+
9
+ describe('normalizeWheelDelta', () => {
10
+ test('pixel mode passes through', () => {
11
+ expect(normalizeWheelDelta(120, 0)).toBe(120)
12
+ })
13
+ test('line mode scales to pixels', () => {
14
+ expect(normalizeWheelDelta(3, 1)).toBe(48)
15
+ })
16
+ test('page mode scales to pixels', () => {
17
+ expect(normalizeWheelDelta(2, 2)).toBe(200)
18
+ })
19
+ })
20
+
21
+ describe('getZoomNormalizer', () => {
22
+ test('tiny pinch deltas get the smallest divisor (largest step)', () => {
23
+ expect(getZoomNormalizer(3)).toBe(25)
24
+ })
25
+ test('large mouse notches get the largest divisor (finest step)', () => {
26
+ expect(getZoomNormalizer(200)).toBe(500)
27
+ })
28
+ test('medium deltas land in between', () => {
29
+ expect(getZoomNormalizer(50)).toBe(150)
30
+ expect(getZoomNormalizer(20)).toBe(75)
31
+ })
32
+ })
33
+
34
+ describe('zoomFactorFromAccum', () => {
35
+ test('negative accum zooms in (factor > 1)', () => {
36
+ expect(zoomFactorFromAccum(-0.1, 16.67)).toBeCloseTo(1.1)
37
+ })
38
+ test('positive accum zooms out (factor < 1)', () => {
39
+ expect(zoomFactorFromAccum(0.1, 16.67)).toBeCloseTo(1 / 1.1)
40
+ })
41
+ test('rate-limits a big burst to ~0.2 per frame', () => {
42
+ // a huge accumulated delta cannot zoom more than the per-frame cap
43
+ expect(zoomFactorFromAccum(99, 16.67)).toBeCloseTo(1 / 1.2, 2)
44
+ expect(zoomFactorFromAccum(-99, 16.67)).toBeCloseTo(1.2, 2)
45
+ })
46
+ })
@@ -0,0 +1,47 @@
1
+ // Wheel / trackpad-pinch delta handling, adapted from @jbrowse/core's
2
+ // util/wheelZoom (not yet in our pinned @jbrowse/core). Turns raw wheel deltas
3
+ // into a per-frame zoom factor that feels consistent across fine trackpad
4
+ // pinches and coarse mouse notches.
5
+
6
+ // Fixed divisor for plain-wheel scroll-zoom mode, where deltas are big notches.
7
+ export const SCROLL_ZOOM_DIVISOR = 500
8
+
9
+ // Cap the zoom change per millisecond so a burst of momentum-scroll events
10
+ // coalesced into one frame can't jump the zoom level (0.2 per ~60fps frame).
11
+ const MAX_ZOOM_RATE_PER_MS = 0.2 / 16.67
12
+
13
+ // Convert a wheel delta to pixels regardless of the browser's deltaMode; some
14
+ // browsers/mice report lines or pages instead of pixels.
15
+ export function normalizeWheelDelta(delta: number, mode: number) {
16
+ if (mode === 1) {
17
+ return delta * 16 // DOM_DELTA_LINE
18
+ }
19
+ if (mode === 2) {
20
+ return delta * 100 // DOM_DELTA_PAGE
21
+ }
22
+ return delta // DOM_DELTA_PIXEL
23
+ }
24
+
25
+ // Adaptive divisor: tiny pinch deltas zoom in larger steps, big mouse notches
26
+ // in finer steps, so a trackpad pinch and a mouse wheel feel similar.
27
+ export function getZoomNormalizer(deltaY: number) {
28
+ const abs = Math.abs(deltaY)
29
+ if (abs < 6) {
30
+ return 25
31
+ }
32
+ if (abs > 150) {
33
+ return 500
34
+ }
35
+ if (abs > 30) {
36
+ return 150
37
+ }
38
+ return 75
39
+ }
40
+
41
+ // Turn accumulated, normalized zoom intent into a colWidth/rowHeight multiplier.
42
+ // Positive accum (wheel toward user) zooms out (factor < 1); negative zooms in.
43
+ export function zoomFactorFromAccum(zoomAccum: number, elapsedMs: number) {
44
+ const max = MAX_ZOOM_RATE_PER_MS * elapsedMs
45
+ const d = Math.max(-max, Math.min(max, zoomAccum))
46
+ return d > 0 ? 1 / (1 + d) : 1 - d
47
+ }