@genome-spy/core 0.64.0 → 0.66.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 (285) hide show
  1. package/dist/bundle/{index-CCJIjehY.js → AbortablePromiseCache-CcuMrnn7.js} +22 -91
  2. package/dist/bundle/browser-BRemItdO.js +138 -0
  3. package/dist/bundle/index-BatuyGAI.js +271 -0
  4. package/dist/bundle/index-ByuE8dvu.js +332 -0
  5. package/dist/bundle/index-Cq3QFUxX.js +1781 -0
  6. package/dist/bundle/{index-C08YCM2T.js → index-D-w7Mmt9.js} +246 -126
  7. package/dist/bundle/index-D28m8tSW.js +1607 -0
  8. package/dist/bundle/index-D74H8TTz.js +508 -0
  9. package/dist/bundle/index-DbJ0oeYM.js +631 -0
  10. package/dist/bundle/index.es.js +15034 -13842
  11. package/dist/bundle/index.js +223 -237
  12. package/dist/bundle/inflate-GtwLkvSP.js +1048 -0
  13. package/dist/bundle/unzip-NywezaRR.js +1492 -0
  14. package/dist/schema.json +22 -4
  15. package/dist/src/config/scaleDefaults.d.ts +8 -0
  16. package/dist/src/config/scaleDefaults.d.ts.map +1 -0
  17. package/dist/src/config/scaleDefaults.js +45 -0
  18. package/dist/src/data/collector.d.ts +7 -2
  19. package/dist/src/data/collector.d.ts.map +1 -1
  20. package/dist/src/data/collector.js +13 -2
  21. package/dist/src/data/dataFlow.d.ts +20 -42
  22. package/dist/src/data/dataFlow.d.ts.map +1 -1
  23. package/dist/src/data/dataFlow.js +57 -80
  24. package/dist/src/data/flowHandle.d.ts +15 -0
  25. package/dist/src/data/flowHandle.d.ts.map +1 -0
  26. package/dist/src/data/flowHandle.js +13 -0
  27. package/dist/src/data/flowInit.d.ts +85 -0
  28. package/dist/src/data/flowInit.d.ts.map +1 -0
  29. package/dist/src/data/flowInit.js +238 -0
  30. package/dist/src/data/flowInit.test.d.ts +2 -0
  31. package/dist/src/data/flowInit.test.d.ts.map +1 -0
  32. package/dist/src/data/flowOptimizer.d.ts +6 -4
  33. package/dist/src/data/flowOptimizer.d.ts.map +1 -1
  34. package/dist/src/data/flowOptimizer.js +29 -14
  35. package/dist/src/data/sources/lazy/axisTickSource.js +1 -1
  36. package/dist/src/data/sources/lazy/bamSource.js +1 -1
  37. package/dist/src/data/sources/lazy/bigBedSource.js +1 -1
  38. package/dist/src/data/sources/lazy/bigWigSource.js +1 -1
  39. package/dist/src/data/sources/lazy/gff3Source.d.ts +2 -6
  40. package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
  41. package/dist/src/data/sources/lazy/gff3Source.js +4 -8
  42. package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
  43. package/dist/src/data/sources/lazy/indexedFastaSource.js +17 -17
  44. package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts +1 -1
  45. package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
  46. package/dist/src/data/sources/lazy/singleAxisLazySource.js +10 -3
  47. package/dist/src/data/sources/lazy/singleAxisWindowedSource.d.ts.map +1 -1
  48. package/dist/src/data/sources/lazy/singleAxisWindowedSource.js +5 -1
  49. package/dist/src/data/sources/lazy/tabixSource.js +1 -1
  50. package/dist/src/data/transforms/filterScoredLabels.d.ts +1 -1
  51. package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
  52. package/dist/src/data/transforms/filterScoredLabels.js +1 -1
  53. package/dist/src/data/transforms/linearizeGenomicCoordinate.d.ts.map +1 -1
  54. package/dist/src/data/transforms/linearizeGenomicCoordinate.js +2 -1
  55. package/dist/src/encoder/encoder.d.ts +1 -1
  56. package/dist/src/encoder/encoder.d.ts.map +1 -1
  57. package/dist/src/encoder/encoder.js +1 -1
  58. package/dist/src/genome/scaleLocus.d.ts +39 -0
  59. package/dist/src/genome/scaleLocus.d.ts.map +1 -1
  60. package/dist/src/genome/scaleLocus.js +76 -0
  61. package/dist/src/genomeSpy/canvasExport.d.ts +19 -0
  62. package/dist/src/genomeSpy/canvasExport.d.ts.map +1 -0
  63. package/dist/src/genomeSpy/canvasExport.js +66 -0
  64. package/dist/src/genomeSpy/containerUi.d.ts +17 -0
  65. package/dist/src/genomeSpy/containerUi.d.ts.map +1 -0
  66. package/dist/src/genomeSpy/containerUi.js +78 -0
  67. package/dist/src/genomeSpy/eventListenerRegistry.d.ts +19 -0
  68. package/dist/src/genomeSpy/eventListenerRegistry.d.ts.map +1 -0
  69. package/dist/src/genomeSpy/eventListenerRegistry.js +38 -0
  70. package/dist/src/genomeSpy/inputBindingManager.d.ts +14 -0
  71. package/dist/src/genomeSpy/inputBindingManager.d.ts.map +1 -0
  72. package/dist/src/genomeSpy/inputBindingManager.js +63 -0
  73. package/dist/src/genomeSpy/interactionController.d.ts +40 -0
  74. package/dist/src/genomeSpy/interactionController.d.ts.map +1 -0
  75. package/dist/src/genomeSpy/interactionController.js +371 -0
  76. package/dist/src/genomeSpy/keyboardListenerManager.d.ts +10 -0
  77. package/dist/src/genomeSpy/keyboardListenerManager.d.ts.map +1 -0
  78. package/dist/src/genomeSpy/keyboardListenerManager.js +31 -0
  79. package/dist/src/genomeSpy/loadingIndicatorManager.d.ts +15 -0
  80. package/dist/src/genomeSpy/loadingIndicatorManager.d.ts.map +1 -0
  81. package/dist/src/genomeSpy/loadingIndicatorManager.js +92 -0
  82. package/dist/src/genomeSpy/renderCoordinator.d.ts +22 -0
  83. package/dist/src/genomeSpy/renderCoordinator.d.ts.map +1 -0
  84. package/dist/src/genomeSpy/renderCoordinator.js +118 -0
  85. package/dist/src/genomeSpy/viewContextFactory.d.ts +18 -0
  86. package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -0
  87. package/dist/src/genomeSpy/viewContextFactory.js +79 -0
  88. package/dist/src/genomeSpy/viewDataInit.d.ts +12 -0
  89. package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -0
  90. package/dist/src/genomeSpy/viewDataInit.js +41 -0
  91. package/dist/src/genomeSpy/viewHierarchyConfig.d.ts +14 -0
  92. package/dist/src/genomeSpy/viewHierarchyConfig.d.ts.map +1 -0
  93. package/dist/src/genomeSpy/viewHierarchyConfig.js +24 -0
  94. package/dist/src/genomeSpy/viewHighlight.d.ts +5 -0
  95. package/dist/src/genomeSpy/viewHighlight.d.ts.map +1 -0
  96. package/dist/src/genomeSpy/viewHighlight.js +30 -0
  97. package/dist/src/genomeSpy.d.ts +17 -72
  98. package/dist/src/genomeSpy.d.ts.map +1 -1
  99. package/dist/src/genomeSpy.js +180 -789
  100. package/dist/src/gl/glslScaleGenerator.d.ts +1 -1
  101. package/dist/src/gl/webGLHelper.d.ts +2 -2
  102. package/dist/src/gl/webGLHelper.d.ts.map +1 -1
  103. package/dist/src/gl/webGLHelper.js +4 -4
  104. package/dist/src/index.d.ts.map +1 -1
  105. package/dist/src/index.js +2 -12
  106. package/dist/src/marks/mark.d.ts +1 -0
  107. package/dist/src/marks/mark.d.ts.map +1 -1
  108. package/dist/src/marks/mark.js +26 -3
  109. package/dist/src/{view → scales}/axisResolution.d.ts +12 -14
  110. package/dist/src/scales/axisResolution.d.ts.map +1 -0
  111. package/dist/src/{view → scales}/axisResolution.js +38 -12
  112. package/dist/src/scales/axisResolution.test.d.ts.map +1 -0
  113. package/dist/src/scales/scaleDomainAggregator.d.ts +57 -0
  114. package/dist/src/scales/scaleDomainAggregator.d.ts.map +1 -0
  115. package/dist/src/scales/scaleDomainAggregator.js +162 -0
  116. package/dist/src/scales/scaleDomainAggregator.test.d.ts +2 -0
  117. package/dist/src/scales/scaleDomainAggregator.test.d.ts.map +1 -0
  118. package/dist/src/scales/scaleInstanceManager.d.ts +40 -0
  119. package/dist/src/scales/scaleInstanceManager.d.ts.map +1 -0
  120. package/dist/src/scales/scaleInstanceManager.js +313 -0
  121. package/dist/src/scales/scaleInstanceManager.test.d.ts +2 -0
  122. package/dist/src/scales/scaleInstanceManager.test.d.ts.map +1 -0
  123. package/dist/src/scales/scaleInteractionController.d.ts +73 -0
  124. package/dist/src/scales/scaleInteractionController.d.ts.map +1 -0
  125. package/dist/src/scales/scaleInteractionController.js +336 -0
  126. package/dist/src/scales/scaleInteractionController.test.d.ts +2 -0
  127. package/dist/src/scales/scaleInteractionController.test.d.ts.map +1 -0
  128. package/dist/src/scales/scalePropsResolver.d.ts +23 -0
  129. package/dist/src/scales/scalePropsResolver.d.ts.map +1 -0
  130. package/dist/src/scales/scalePropsResolver.js +74 -0
  131. package/dist/src/{view → scales}/scaleResolution.d.ts +53 -31
  132. package/dist/src/scales/scaleResolution.d.ts.map +1 -0
  133. package/dist/src/scales/scaleResolution.js +658 -0
  134. package/dist/src/scales/scaleResolution.test.d.ts.map +1 -0
  135. package/dist/src/scales/scaleResolutionConstants.d.ts +6 -0
  136. package/dist/src/scales/scaleResolutionConstants.d.ts.map +1 -0
  137. package/dist/src/scales/scaleResolutionConstants.js +5 -0
  138. package/dist/src/scales/scaleRules.d.ts +16 -0
  139. package/dist/src/scales/scaleRules.d.ts.map +1 -0
  140. package/dist/src/scales/scaleRules.js +103 -0
  141. package/dist/src/scales/scaleRules.test.d.ts +2 -0
  142. package/dist/src/scales/scaleRules.test.d.ts.map +1 -0
  143. package/dist/src/spec/channel.d.ts +13 -18
  144. package/dist/src/spec/sampleView.d.ts +3 -2
  145. package/dist/src/spec/scale.d.ts +6 -0
  146. package/dist/src/types/embedApi.d.ts +5 -0
  147. package/dist/src/types/scaleResolutionApi.d.ts +1 -1
  148. package/dist/src/types/viewContext.d.ts +1 -1
  149. package/dist/src/view/concatView.d.ts +18 -0
  150. package/dist/src/view/concatView.d.ts.map +1 -1
  151. package/dist/src/view/concatView.js +73 -0
  152. package/dist/src/view/concatView.test.d.ts +2 -0
  153. package/dist/src/view/concatView.test.d.ts.map +1 -0
  154. package/dist/src/view/containerMutationHelper.d.ts +74 -0
  155. package/dist/src/view/containerMutationHelper.d.ts.map +1 -0
  156. package/dist/src/view/containerMutationHelper.js +114 -0
  157. package/dist/src/view/containerView.d.ts +0 -7
  158. package/dist/src/view/containerView.d.ts.map +1 -1
  159. package/dist/src/view/containerView.js +0 -10
  160. package/dist/src/view/facetView.d.ts.map +1 -1
  161. package/dist/src/view/facetView.js +0 -14
  162. package/dist/src/view/flowBuilder.d.ts +2 -2
  163. package/dist/src/view/flowBuilder.d.ts.map +1 -1
  164. package/dist/src/view/flowBuilder.js +21 -4
  165. package/dist/src/view/gridView/gridChild.d.ts +11 -0
  166. package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
  167. package/dist/src/view/gridView/gridChild.js +32 -6
  168. package/dist/src/view/gridView/gridView.d.ts +39 -1
  169. package/dist/src/view/gridView/gridView.d.ts.map +1 -1
  170. package/dist/src/view/gridView/gridView.js +113 -42
  171. package/dist/src/view/gridView/gridView.test.d.ts +2 -0
  172. package/dist/src/view/gridView/gridView.test.d.ts.map +1 -0
  173. package/dist/src/view/gridView/scrollbar.d.ts +39 -8
  174. package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
  175. package/dist/src/view/gridView/scrollbar.js +184 -69
  176. package/dist/src/view/gridView/selectionRect.d.ts +8 -4
  177. package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
  178. package/dist/src/view/gridView/selectionRect.js +28 -3
  179. package/dist/src/view/gridView/selectionRect.test.d.ts +2 -0
  180. package/dist/src/view/gridView/selectionRect.test.d.ts.map +1 -0
  181. package/dist/src/view/layerView.d.ts +14 -0
  182. package/dist/src/view/layerView.d.ts.map +1 -1
  183. package/dist/src/view/layerView.js +66 -0
  184. package/dist/src/view/layerView.test.d.ts +2 -0
  185. package/dist/src/view/layerView.test.d.ts.map +1 -0
  186. package/dist/src/view/paramMediator.d.ts +2 -1
  187. package/dist/src/view/paramMediator.d.ts.map +1 -1
  188. package/dist/src/view/paramMediator.js +13 -1
  189. package/dist/src/view/testUtils.d.ts.map +1 -1
  190. package/dist/src/view/testUtils.js +18 -5
  191. package/dist/src/view/unitView.d.ts.map +1 -1
  192. package/dist/src/view/unitView.js +52 -12
  193. package/dist/src/view/view.d.ts +23 -7
  194. package/dist/src/view/view.d.ts.map +1 -1
  195. package/dist/src/view/view.js +61 -5
  196. package/dist/src/view/viewDispose.test.d.ts +2 -0
  197. package/dist/src/view/viewDispose.test.d.ts.map +1 -0
  198. package/dist/src/view/viewUtils.d.ts +4 -4
  199. package/dist/src/view/viewUtils.d.ts.map +1 -1
  200. package/dist/src/view/viewUtils.js +19 -15
  201. package/dist/src/view/viewUtils.test.d.ts +2 -0
  202. package/dist/src/view/viewUtils.test.d.ts.map +1 -0
  203. package/package.json +10 -10
  204. package/dist/bundle/__vite-browser-external-C--ziKoh.js +0 -8
  205. package/dist/bundle/_commonjsHelpers-DjF3Plf2.js +0 -26
  206. package/dist/bundle/index-5ajWdKly.js +0 -1319
  207. package/dist/bundle/index-B03-Om4z.js +0 -274
  208. package/dist/bundle/index-BftNdA0O.js +0 -27
  209. package/dist/bundle/index-Bg7C4Xat.js +0 -2750
  210. package/dist/bundle/index-C3QR8Lv6.js +0 -2131
  211. package/dist/bundle/index-DTcHjAHp.js +0 -505
  212. package/dist/bundle/index-DnIkxb0L.js +0 -1025
  213. package/dist/bundle/index-Ww3TAo6_.js +0 -71
  214. package/dist/bundle/index-g8iXgW0W.js +0 -651
  215. package/dist/bundle/long-B-FASCSo.js +0 -2387
  216. package/dist/bundle/remoteFile-BuaqFGWk.js +0 -94
  217. package/dist/src/data/collector.test.js +0 -138
  218. package/dist/src/data/dataFlow.test.js +0 -5
  219. package/dist/src/data/flow.test.js +0 -81
  220. package/dist/src/data/flowNode.test.js +0 -50
  221. package/dist/src/data/flowOptimizer.test.js +0 -204
  222. package/dist/src/data/formats/fasta.test.js +0 -27
  223. package/dist/src/data/sources/inlineSource.test.js +0 -63
  224. package/dist/src/data/sources/sequenceSource.test.js +0 -81
  225. package/dist/src/data/transforms/aggregate.test.js +0 -134
  226. package/dist/src/data/transforms/clone.test.js +0 -11
  227. package/dist/src/data/transforms/coverage.test.js +0 -238
  228. package/dist/src/data/transforms/filter.test.js +0 -20
  229. package/dist/src/data/transforms/flatten.test.js +0 -96
  230. package/dist/src/data/transforms/flattenDelimited.test.js +0 -90
  231. package/dist/src/data/transforms/flattenSequence.test.js +0 -34
  232. package/dist/src/data/transforms/formula.test.js +0 -25
  233. package/dist/src/data/transforms/identifier.test.js +0 -92
  234. package/dist/src/data/transforms/pileup.test.js +0 -70
  235. package/dist/src/data/transforms/project.test.js +0 -32
  236. package/dist/src/data/transforms/regexExtract.test.js +0 -70
  237. package/dist/src/data/transforms/regexFold.test.js +0 -201
  238. package/dist/src/data/transforms/sample.test.js +0 -38
  239. package/dist/src/data/transforms/stack.test.js +0 -91
  240. package/dist/src/encoder/accessor.test.js +0 -162
  241. package/dist/src/encoder/encoder.test.js +0 -105
  242. package/dist/src/genome/genome.test.js +0 -268
  243. package/dist/src/genome/genomes.test.js +0 -8
  244. package/dist/src/genome/scaleIndex.test.js +0 -78
  245. package/dist/src/genome/scaleLocus.test.js +0 -4
  246. package/dist/src/scale/scale.test.js +0 -326
  247. package/dist/src/scale/ticks.test.js +0 -46
  248. package/dist/src/selection/selection.test.js +0 -14
  249. package/dist/src/utils/addBaseUrl.test.js +0 -30
  250. package/dist/src/utils/binnedIndex.test.js +0 -201
  251. package/dist/src/utils/cloner.test.js +0 -35
  252. package/dist/src/utils/coalesce.test.js +0 -16
  253. package/dist/src/utils/concatIterables.test.js +0 -8
  254. package/dist/src/utils/domainArray.test.js +0 -130
  255. package/dist/src/utils/indexer.test.js +0 -49
  256. package/dist/src/utils/interactionEvent.test.js +0 -35
  257. package/dist/src/utils/iterateNestedMaps.test.js +0 -33
  258. package/dist/src/utils/kWayMerge.test.js +0 -30
  259. package/dist/src/utils/mergeObjects.test.js +0 -42
  260. package/dist/src/utils/numberExtractor.test.js +0 -6
  261. package/dist/src/utils/propertyCacher.test.js +0 -89
  262. package/dist/src/utils/propertyCoalescer.test.js +0 -25
  263. package/dist/src/utils/radixSort.test.js +0 -51
  264. package/dist/src/utils/reservationMap.test.js +0 -20
  265. package/dist/src/utils/ringBuffer.test.js +0 -39
  266. package/dist/src/utils/topK.test.js +0 -54
  267. package/dist/src/utils/trees.test.js +0 -135
  268. package/dist/src/utils/url.test.js +0 -28
  269. package/dist/src/utils/variableTools.test.js +0 -13
  270. package/dist/src/view/axisResolution.d.ts.map +0 -1
  271. package/dist/src/view/axisResolution.test.d.ts.map +0 -1
  272. package/dist/src/view/axisResolution.test.js +0 -206
  273. package/dist/src/view/flowBuilder.test.js +0 -125
  274. package/dist/src/view/layout/flexLayout.test.js +0 -323
  275. package/dist/src/view/layout/grid.test.js +0 -71
  276. package/dist/src/view/layout/rectangle.test.js +0 -192
  277. package/dist/src/view/paramMediator.test.js +0 -260
  278. package/dist/src/view/scaleResolution.d.ts.map +0 -1
  279. package/dist/src/view/scaleResolution.js +0 -1049
  280. package/dist/src/view/scaleResolution.test.d.ts.map +0 -1
  281. package/dist/src/view/scaleResolution.test.js +0 -645
  282. package/dist/src/view/view.test.js +0 -245
  283. package/dist/src/view/viewFactory.test.js +0 -25
  284. /package/dist/src/{view → scales}/axisResolution.test.d.ts +0 -0
  285. /package/dist/src/{view → scales}/scaleResolution.test.d.ts +0 -0
@@ -1,323 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import {
3
- mapToPixelCoords,
4
- getMinimumSize,
5
- getLargestSize,
6
- isStretching,
7
- parseSizeDef,
8
- sumSizeDefs,
9
- } from "./flexLayout.js";
10
-
11
- test("parseSize", () => {
12
- expect(parseSizeDef(10)).toEqual({ px: 10, grow: 0 });
13
- expect(parseSizeDef({ px: 20, grow: 2 })).toEqual({ px: 20, grow: 2 });
14
- expect(parseSizeDef(undefined)).toEqual({ px: 0, grow: 1 });
15
- expect(parseSizeDef(null)).toEqual({ px: 0, grow: 1 });
16
- expect(parseSizeDef("container")).toEqual({ px: 0, grow: 1 });
17
- expect(() => parseSizeDef({})).toThrow();
18
- });
19
-
20
- describe("Basic flex functionality", () => {
21
- test("Absolute sizes", () => {
22
- const items = [10, 30, 20].map((x) => ({ px: x }));
23
- const containerSize = 100;
24
-
25
- const mapped = mapToPixelCoords(items, containerSize);
26
-
27
- expect(mapped[0]).toEqual({ location: 0, size: 10 });
28
- expect(mapped[1]).toEqual({ location: 10, size: 30 });
29
- expect(mapped[2]).toEqual({ location: 40, size: 20 });
30
- });
31
-
32
- test("Absolute sizes with spacing", () => {
33
- const items = [10, 30, 20].map((x) => ({ px: x }));
34
- const containerSize = 100;
35
-
36
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
37
-
38
- expect(mapped[0]).toEqual({ location: 0, size: 10 });
39
- expect(mapped[1]).toEqual({ location: 20, size: 30 });
40
- expect(mapped[2]).toEqual({ location: 60, size: 20 });
41
- });
42
-
43
- test("Absolute sizes with spacing, reversed", () => {
44
- const items = [10, 30, 20].map((x) => ({ px: x }));
45
- const containerSize = 100;
46
-
47
- const mapped = mapToPixelCoords(items, containerSize, {
48
- spacing: 10,
49
- reverse: true,
50
- });
51
-
52
- expect(mapped[0]).toEqual({ location: 90, size: 10 });
53
- expect(mapped[1]).toEqual({ location: 50, size: 30 });
54
- expect(mapped[2]).toEqual({ location: 20, size: 20 });
55
- });
56
-
57
- test("Absolute sizes with spacing, reversed and insufficient containerSize", () => {
58
- const items = [10, 30, 20].map((x) => ({ px: x }));
59
- const containerSize = 0;
60
-
61
- const mapped = mapToPixelCoords(items, containerSize, {
62
- spacing: 10,
63
- reverse: true,
64
- });
65
-
66
- expect(mapped[0]).toEqual({ location: 70, size: 10 });
67
- expect(mapped[1]).toEqual({ location: 30, size: 30 });
68
- expect(mapped[2]).toEqual({ location: 0, size: 20 });
69
- });
70
-
71
- test("Growing sizes", () => {
72
- const items = [10, 20, 70].map((x) => ({ grow: x }));
73
- const containerSize = 200;
74
-
75
- const mapped = mapToPixelCoords(items, containerSize);
76
-
77
- expect(mapped[0]).toEqual({ location: 0, size: 20 });
78
- expect(mapped[1]).toEqual({ location: 20, size: 40 });
79
- expect(mapped[2]).toEqual({ location: 60, size: 140 });
80
- });
81
-
82
- test("Growing sizes with spacing", () => {
83
- const items = [10, 20, 70].map((x) => ({ grow: x }));
84
- const containerSize = 220;
85
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
86
-
87
- expect(mapped[0]).toEqual({ location: 0, size: 20 });
88
- expect(mapped[1]).toEqual({ location: 30, size: 40 });
89
- expect(mapped[2]).toEqual({ location: 80, size: 140 });
90
- });
91
-
92
- test("Mixed absolute and relative sizes", () => {
93
- const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
94
- const containerSize = 1100;
95
- const mapped = mapToPixelCoords(items, containerSize);
96
-
97
- expect(mapped[0]).toEqual({ location: 0, size: 100 });
98
- expect(mapped[1]).toEqual({ location: 100, size: 80 });
99
- expect(mapped[2]).toEqual({ location: 180, size: 720 });
100
- expect(mapped[3]).toEqual({ location: 900, size: 200 });
101
- });
102
-
103
- test("Sizes having both absolute and growing components", () => {
104
- const items = [
105
- { px: 1 },
106
- { px: 2 },
107
- { px: 3, grow: 2 },
108
- { px: 4, grow: 1 },
109
- ];
110
- const containerSize = 16;
111
- const mapped = mapToPixelCoords(items, containerSize);
112
-
113
- expect(mapped[0]).toEqual({ location: 0, size: 1 });
114
- expect(mapped[1]).toEqual({ location: 1, size: 2 });
115
- expect(mapped[2]).toEqual({ location: 3, size: 7 });
116
- expect(mapped[3]).toEqual({ location: 10, size: 6 });
117
- });
118
-
119
- test("Zero sizes return zero coords", () => {
120
- const items = [{ grow: 0 }, { grow: 0 }];
121
-
122
- const mapped = mapToPixelCoords(items, 0);
123
- expect(mapped[0]).toEqual({ location: 0, size: 0 });
124
- expect(mapped[1]).toEqual({ location: 0, size: 0 });
125
-
126
- const mapped2 = mapToPixelCoords(items, 1);
127
- expect(mapped2[0]).toEqual({ location: 0, size: 0 });
128
- expect(mapped2[1]).toEqual({ location: 0, size: 0 });
129
- });
130
-
131
- test("Offset is added", () => {
132
- const items = [10, 30, 20].map((x) => ({ px: x }));
133
- const containerSize = 100;
134
-
135
- const mapped = mapToPixelCoords(items, containerSize, { offset: 5 });
136
-
137
- expect(mapped[0]).toEqual({ location: 5, size: 10 });
138
- expect(mapped[1]).toEqual({ location: 15, size: 30 });
139
- expect(mapped[2]).toEqual({ location: 45, size: 20 });
140
- });
141
- });
142
-
143
- describe("Collapse gaps when items have zero px and grow", () => {
144
- test("Zero as first", () => {
145
- const items = [0, 30, 20].map((x) => ({ px: x }));
146
- const containerSize = 100;
147
-
148
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
149
-
150
- expect(mapped[0]).toEqual({ location: 0, size: 0 });
151
- expect(mapped[1]).toEqual({ location: 0, size: 30 });
152
- expect(mapped[2]).toEqual({ location: 40, size: 20 });
153
- });
154
-
155
- test("Zero in the middle", () => {
156
- const items = [10, 0, 20].map((x) => ({ px: x }));
157
- const containerSize = 100;
158
-
159
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
160
-
161
- expect(mapped[0]).toEqual({ location: 0, size: 10 });
162
- expect(mapped[1]).toEqual({ location: 15, size: 0 });
163
- expect(mapped[2]).toEqual({ location: 20, size: 20 });
164
- });
165
-
166
- test("Multiple zeroes in the middle", () => {
167
- const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
168
- const containerSize = 100;
169
-
170
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
171
-
172
- expect(mapped[0]).toEqual({ location: 0, size: 10 });
173
- expect(mapped[1]).toEqual({ location: 12.5, size: 0 });
174
- expect(mapped[2]).toEqual({ location: 15, size: 0 });
175
- expect(mapped[3]).toEqual({ location: 17.5, size: 0 });
176
- expect(mapped[4]).toEqual({ location: 20, size: 20 });
177
- });
178
-
179
- test("Zero as last", () => {
180
- const items = [10, 30, 0].map((x) => ({ px: x }));
181
- const containerSize = 100;
182
-
183
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
184
-
185
- expect(mapped[0]).toEqual({ location: 0, size: 10 });
186
- expect(mapped[1]).toEqual({ location: 20, size: 30 });
187
- expect(mapped[2]).toEqual({ location: 50, size: 0 });
188
- });
189
-
190
- test("Only a zero", () => {
191
- const items = [0].map((x) => ({ px: x }));
192
- const containerSize = 100;
193
-
194
- const mapped = mapToPixelCoords(items, containerSize, { spacing: 10 });
195
-
196
- expect(mapped[0]).toEqual({ location: 0, size: 0 });
197
- });
198
- });
199
-
200
- describe("Collapse gaps when items have zero px and grow, reversed", () => {
201
- test("Zero as first", () => {
202
- const items = [0, 30, 20].map((x) => ({ px: x }));
203
- const containerSize = 100;
204
-
205
- const mapped = mapToPixelCoords(items, containerSize, {
206
- spacing: 10,
207
- reverse: true,
208
- });
209
-
210
- expect(mapped[0]).toEqual({ location: 100, size: 0 });
211
- expect(mapped[1]).toEqual({ location: 70, size: 30 });
212
- expect(mapped[2]).toEqual({ location: 40, size: 20 });
213
- });
214
-
215
- test("Zero in the middle", () => {
216
- const items = [10, 0, 20].map((x) => ({ px: x }));
217
- const containerSize = 100;
218
-
219
- const mapped = mapToPixelCoords(items, containerSize, {
220
- spacing: 10,
221
- reverse: true,
222
- });
223
-
224
- expect(mapped[0]).toEqual({ location: 90, size: 10 });
225
- expect(mapped[1]).toEqual({ location: 85, size: 0 });
226
- expect(mapped[2]).toEqual({ location: 60, size: 20 });
227
- });
228
-
229
- test("Multiple zeroes in the middle", () => {
230
- const items = [10, 0, 0, 0, 20].map((x) => ({ px: x }));
231
- const containerSize = 100;
232
-
233
- const mapped = mapToPixelCoords(items, containerSize, {
234
- spacing: 10,
235
- reverse: true,
236
- });
237
-
238
- expect(mapped[0]).toEqual({ location: 90, size: 10 });
239
- expect(mapped[1]).toEqual({ location: 87.5, size: 0 });
240
- expect(mapped[2]).toEqual({ location: 85, size: 0 });
241
- expect(mapped[3]).toEqual({ location: 82.5, size: 0 });
242
- expect(mapped[4]).toEqual({ location: 60, size: 20 });
243
- });
244
-
245
- test("Zero as last", () => {
246
- const items = [10, 30, 0].map((x) => ({ px: x }));
247
- const containerSize = 100;
248
-
249
- const mapped = mapToPixelCoords(items, containerSize, {
250
- spacing: 10,
251
- reverse: true,
252
- });
253
-
254
- expect(mapped[0]).toEqual({ location: 90, size: 10 });
255
- expect(mapped[1]).toEqual({ location: 50, size: 30 });
256
- expect(mapped[2]).toEqual({ location: 50, size: 0 });
257
- });
258
-
259
- test("Only a zero", () => {
260
- const items = [0].map((x) => ({ px: x }));
261
- const containerSize = 100;
262
-
263
- const mapped = mapToPixelCoords(items, containerSize, {
264
- spacing: 10,
265
- reverse: true,
266
- });
267
-
268
- expect(mapped[0]).toEqual({ location: 100, size: 0 });
269
- });
270
- });
271
-
272
- describe("Utility fuctions", () => {
273
- test("sumSizeDefs", () => {
274
- const items = [
275
- { px: 100 },
276
- { px: 10, grow: 1 },
277
- { grow: 9 },
278
- { px: 200 },
279
- ];
280
-
281
- expect(sumSizeDefs(items)).toEqual({ px: 310, grow: 10 });
282
- });
283
-
284
- test("getMinimumSize", () => {
285
- const items = [{ px: 100 }, { grow: 1 }, { grow: 9 }, { px: 200 }];
286
-
287
- expect(getMinimumSize(items)).toEqual(300);
288
-
289
- expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
290
- });
291
-
292
- test("getMinimumSize, items include zeroes", () => {
293
- const items = [
294
- { px: 100 },
295
- { px: 0, grow: 0 },
296
- { grow: 1 },
297
- { grow: 9 },
298
- { px: 200 },
299
- ];
300
-
301
- expect(getMinimumSize(items)).toEqual(300);
302
-
303
- expect(getMinimumSize(items, { spacing: 10 })).toEqual(330);
304
- });
305
-
306
- test("getLargestSize", () => {
307
- const items = [
308
- { px: 100 },
309
- { px: 0, grow: 0 },
310
- { grow: 1 },
311
- { grow: 9 },
312
- { px: 200 },
313
- { px: 50 },
314
- ];
315
-
316
- expect(getLargestSize(items)).toEqual({ px: 200, grow: 9 });
317
- });
318
-
319
- test("isStretching", () => {
320
- expect(isStretching([{ grow: 1 }])).toBeTruthy();
321
- expect(isStretching([{ px: 1 }])).toBeFalsy();
322
- });
323
- });
@@ -1,71 +0,0 @@
1
- import { expect, test, describe } from "vitest";
2
-
3
- import Grid from "./grid.js";
4
-
5
- describe("Grid indexing", () => {
6
- test("Single row", () => {
7
- const g = new Grid(3);
8
-
9
- expect(g.maxCols).toEqual(Infinity);
10
- expect(g.nCols).toEqual(3);
11
- expect(g.nRows).toEqual(1);
12
- expect(g.colIndices).toEqual([[0], [1], [2]]);
13
- expect(g.rowIndices).toEqual([[0, 1, 2]]);
14
- expect(g.getCellIndex(1, 0)).toEqual(1);
15
- expect(g.getCellIndex(1, 1)).toBeUndefined();
16
- expect(g.getCellCoords(1)).toEqual([1, 0]);
17
- expect(g.getCellCoords(-1)).toBeUndefined();
18
- expect(g.getCellCoords(3)).toBeUndefined();
19
- });
20
-
21
- test("Single column", () => {
22
- const g = new Grid(3, 1);
23
-
24
- expect(g.maxCols).toEqual(1);
25
- expect(g.nCols).toEqual(1);
26
- expect(g.nRows).toEqual(3);
27
- expect(g.colIndices).toEqual([[0, 1, 2]]);
28
- expect(g.rowIndices).toEqual([[0], [1], [2]]);
29
- expect(g.getCellIndex(0, 1)).toEqual(1);
30
- expect(g.getCellIndex(1, 1)).toBeUndefined();
31
- expect(g.getCellCoords(1)).toEqual([0, 1]);
32
- });
33
-
34
- test("Two columns", () => {
35
- const g = new Grid(6, 2);
36
-
37
- expect(g.maxCols).toEqual(2);
38
- expect(g.nCols).toEqual(2);
39
- expect(g.nRows).toEqual(3);
40
- expect(g.colIndices).toEqual([
41
- [0, 2, 4],
42
- [1, 3, 5],
43
- ]);
44
- expect(g.rowIndices).toEqual([
45
- [0, 1],
46
- [2, 3],
47
- [4, 5],
48
- ]);
49
- expect(g.getCellIndex(1, 0)).toEqual(1);
50
- expect(g.getCellIndex(0, 1)).toEqual(2);
51
- expect(g.getCellIndex(1, 1)).toEqual(3);
52
- expect(g.getCellCoords(3)).toEqual([1, 1]);
53
- });
54
-
55
- test("Two columns, second is partial", () => {
56
- const g = new Grid(5, 2);
57
-
58
- expect(g.maxCols).toEqual(2);
59
- expect(g.nCols).toEqual(2);
60
- expect(g.nRows).toEqual(3);
61
- expect(g.colIndices).toEqual([
62
- [0, 2, 4],
63
- [1, 3],
64
- ]);
65
- expect(g.rowIndices).toEqual([[0, 1], [2, 3], [4]]);
66
- expect(g.getCellIndex(1, 0)).toEqual(1);
67
- expect(g.getCellIndex(0, 1)).toEqual(2);
68
- expect(g.getCellIndex(1, 2)).toBeUndefined();
69
- expect(g.getCellCoords(3)).toEqual([1, 1]);
70
- });
71
- });
@@ -1,192 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import Rectangle from "./rectangle.js";
3
- import Padding from "./padding.js";
4
-
5
- test("Rectangle creation", () => {
6
- const r = Rectangle.create(1, 2, 3, 4);
7
- expect(r.x).toEqual(1);
8
- expect(r.y).toEqual(2);
9
- expect(r.width).toEqual(3);
10
- expect(r.height).toEqual(4);
11
- });
12
-
13
- test("equals", () => {
14
- const r = Rectangle.create(1, 2, 3, 4);
15
- expect(r.equals(r)).toBeTruthy();
16
- expect(r.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
17
- expect(r.equals(undefined)).toBeFalsy();
18
- });
19
-
20
- test("x2 and y2 calculation", () => {
21
- const r = Rectangle.create(1, 2, 3, 4);
22
- expect(r.x2).toEqual(4);
23
- expect(r.y2).toEqual(6);
24
- });
25
-
26
- test("translate", () => {
27
- const r = Rectangle.create(1, 2, 3, 4).translate(2, 3);
28
- expect(r.x).toEqual(3);
29
- expect(r.y).toEqual(5);
30
- expect(r.width).toEqual(3);
31
- expect(r.height).toEqual(4);
32
- });
33
-
34
- test("Dynamic translate", () => {
35
- let tx = 0;
36
- let ty = 0;
37
-
38
- const r = Rectangle.create(1, 2, 3, 4)
39
- .translate(
40
- () => tx,
41
- () => ty
42
- )
43
- .translate(2, 3);
44
-
45
- expect(r.x).toEqual(3);
46
- expect(r.y).toEqual(5);
47
- expect(r.width).toEqual(3);
48
- expect(r.height).toEqual(4);
49
-
50
- tx = 1;
51
- ty = 2;
52
-
53
- expect(r.x).toEqual(4);
54
- expect(r.y).toEqual(7);
55
- expect(r.width).toEqual(3);
56
- expect(r.height).toEqual(4);
57
- });
58
-
59
- test("expand", () => {
60
- const r = Rectangle.create(1, 2, 3, 4).expand(
61
- Padding.createFromRecord({ top: 2, right: 3, bottom: 4, left: 5 })
62
- );
63
-
64
- expect(r.x).toEqual(-4);
65
- expect(r.width).toEqual(11);
66
- expect(r.y).toEqual(0);
67
- expect(r.height).toEqual(10);
68
- });
69
-
70
- test("shrink", () => {
71
- const r = Rectangle.create(1, 2, 3, 4).shrink(
72
- Padding.createUniformPadding(1)
73
- );
74
-
75
- expect(r.x).toEqual(2);
76
- expect(r.width).toEqual(1);
77
- expect(r.y).toEqual(3);
78
- expect(r.height).toEqual(2);
79
- });
80
-
81
- test("modify", () => {
82
- const r = Rectangle.create(1, 2, 3, 4);
83
- const m = r.modify({ x: 5 });
84
-
85
- expect(m.equals(r)).toBeFalsy();
86
- expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
87
- });
88
-
89
- test("Dynamic modify", () => {
90
- let x = 1;
91
- const r = Rectangle.create(1, 2, 3, 4);
92
- const m = r.modify({ x: () => x });
93
-
94
- expect(m.equals(r)).toBeTruthy();
95
- expect(m.equals(Rectangle.create(1, 2, 3, 4))).toBeTruthy();
96
-
97
- x = 5;
98
-
99
- expect(m.equals(r)).toBeFalsy();
100
- expect(m.equals(Rectangle.create(5, 2, 3, 4))).toBeTruthy();
101
- });
102
-
103
- test("intersect", () => {
104
- const a = Rectangle.create(1, 1, 6, 3);
105
- const b = Rectangle.create(5, 2, 3, 4);
106
- const c = Rectangle.create(5, 2, 2, 2);
107
-
108
- expect(a.intersect(b).equals(c)).toBeTruthy();
109
- expect(a.intersect(b).isDefined()).toBeTruthy();
110
-
111
- const x = Rectangle.create(1, 1, 1, 1);
112
- const y = Rectangle.create(3, 3, 1, 1);
113
-
114
- expect(x.intersect(y).isDefined()).toBeFalsy();
115
- });
116
-
117
- test("union", () => {
118
- const a = Rectangle.create(1, 1, 6, 3);
119
- const b = Rectangle.create(5, 2, 3, 4);
120
- const c = Rectangle.create(1, 1, 7, 5);
121
-
122
- expect(a.union(b).equals(c)).toBeTruthy();
123
- });
124
-
125
- test("isDefined", () => {
126
- expect(Rectangle.create(0, 0, 1, 1).isDefined()).toBeTruthy();
127
- expect(Rectangle.create(0, 0, 0, 0).isDefined()).toBeTruthy();
128
-
129
- expect(Rectangle.create(0, 0, -1, 0).isDefined()).toBeFalsy();
130
- expect(Rectangle.create(0, 0, 0, -1).isDefined()).toBeFalsy();
131
- });
132
-
133
- test("flatten", () => {
134
- let tx = 0;
135
- let ty = 0;
136
-
137
- const r = Rectangle.create(1, 2, 3, 4).translate(
138
- () => tx,
139
- () => ty
140
- );
141
-
142
- const flattened = r.flatten();
143
-
144
- tx = -1;
145
- ty = -2;
146
-
147
- expect(r.equals(Rectangle.create(0, 0, 3, 4)));
148
- expect(flattened.equals(Rectangle.create(1, 2, 3, 4)));
149
- });
150
-
151
- test("containsPoint", () => {
152
- const r = Rectangle.create(1, 2, 3, 4);
153
-
154
- expect(r.containsPoint(0, 0)).toBeFalsy();
155
- expect(r.containsPoint(0, 10)).toBeFalsy();
156
- expect(r.containsPoint(10, 0)).toBeFalsy();
157
- expect(r.containsPoint(10, 10)).toBeFalsy();
158
-
159
- expect(r.containsPoint(2, 0)).toBeFalsy();
160
- expect(r.containsPoint(2, 10)).toBeFalsy();
161
- expect(r.containsPoint(0, 3)).toBeFalsy();
162
- expect(r.containsPoint(10, 3)).toBeFalsy();
163
-
164
- // Inclusive corner
165
- expect(r.containsPoint(1, 2)).toBeTruthy();
166
-
167
- // Inside
168
- expect(r.containsPoint(2, 3)).toBeTruthy();
169
-
170
- // Exclusive corner
171
- expect(r.containsPoint(4, 6)).toBeFalsy();
172
- });
173
-
174
- test("normalizePoint", () => {
175
- const r = Rectangle.create(1, 2, 6, 4);
176
-
177
- expect(r.normalizePoint(1, 2)).toEqual({ x: 0, y: 0 });
178
- expect(r.normalizePoint(7, 2)).toEqual({ x: 1, y: 0 });
179
- expect(r.normalizePoint(4, 4)).toEqual({ x: 0.5, y: 0.5 });
180
-
181
- expect(r.normalizePoint(1, 6, true)).toEqual({ x: 0, y: 0 });
182
- });
183
-
184
- test("denormalizePoint", () => {
185
- const r = Rectangle.create(1, 2, 6, 4);
186
-
187
- expect(r.denormalizePoint(0, 0)).toEqual({ x: 1, y: 2 });
188
- expect(r.denormalizePoint(1, 0)).toEqual({ x: 7, y: 2 });
189
- expect(r.denormalizePoint(0.5, 0.5)).toEqual({ x: 4, y: 4 });
190
-
191
- expect(r.denormalizePoint(0, 0, true)).toEqual({ x: 1, y: 6 });
192
- });