@genome-spy/core 0.30.0 → 0.30.2

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 (234) hide show
  1. package/dist/index.es.js +16373 -0
  2. package/dist/index.js +43 -43
  3. package/package.json +10 -7
  4. package/src/data/collector.js +0 -183
  5. package/src/data/collector.test.js +0 -84
  6. package/src/data/dataFlow.js +0 -148
  7. package/src/data/dataFlow.test.js +0 -5
  8. package/src/data/facetNode.js +0 -17
  9. package/src/data/flow.test.js +0 -72
  10. package/src/data/flowBatch.d.ts +0 -40
  11. package/src/data/flowNode.js +0 -283
  12. package/src/data/flowNode.test.js +0 -50
  13. package/src/data/flowOptimizer.js +0 -123
  14. package/src/data/flowOptimizer.test.js +0 -193
  15. package/src/data/flowTestUtils.js +0 -63
  16. package/src/data/formats/fasta.js +0 -32
  17. package/src/data/formats/fasta.test.js +0 -27
  18. package/src/data/sources/dataSource.js +0 -22
  19. package/src/data/sources/dataSourceFactory.js +0 -24
  20. package/src/data/sources/dataUtils.js +0 -78
  21. package/src/data/sources/dynamicCallbackSource.js +0 -57
  22. package/src/data/sources/dynamicSource.js +0 -37
  23. package/src/data/sources/inlineSource.js +0 -67
  24. package/src/data/sources/inlineSource.test.js +0 -56
  25. package/src/data/sources/namedSource.js +0 -79
  26. package/src/data/sources/sequenceSource.js +0 -46
  27. package/src/data/sources/sequenceSource.test.js +0 -46
  28. package/src/data/sources/urlSource.js +0 -74
  29. package/src/data/transforms/aggregate.js +0 -70
  30. package/src/data/transforms/clone.js +0 -40
  31. package/src/data/transforms/clone.test.js +0 -11
  32. package/src/data/transforms/coverage.js +0 -187
  33. package/src/data/transforms/coverage.test.js +0 -123
  34. package/src/data/transforms/filter.js +0 -37
  35. package/src/data/transforms/filter.test.js +0 -18
  36. package/src/data/transforms/filterScoredLabels.js +0 -134
  37. package/src/data/transforms/flattenCompressedExons.js +0 -57
  38. package/src/data/transforms/flattenDelimited.js +0 -74
  39. package/src/data/transforms/flattenDelimited.test.js +0 -87
  40. package/src/data/transforms/flattenSequence.js +0 -39
  41. package/src/data/transforms/flattenSequence.test.js +0 -34
  42. package/src/data/transforms/formula.js +0 -39
  43. package/src/data/transforms/formula.test.js +0 -19
  44. package/src/data/transforms/identifier.js +0 -108
  45. package/src/data/transforms/identifier.test.js +0 -83
  46. package/src/data/transforms/linearizeGenomicCoordinate.js +0 -101
  47. package/src/data/transforms/measureText.js +0 -44
  48. package/src/data/transforms/pileup.js +0 -128
  49. package/src/data/transforms/pileup.test.js +0 -70
  50. package/src/data/transforms/project.js +0 -41
  51. package/src/data/transforms/project.test.js +0 -32
  52. package/src/data/transforms/regexExtract.js +0 -61
  53. package/src/data/transforms/regexExtract.test.js +0 -67
  54. package/src/data/transforms/regexFold.js +0 -141
  55. package/src/data/transforms/regexFold.test.js +0 -160
  56. package/src/data/transforms/sample.js +0 -101
  57. package/src/data/transforms/sample.test.js +0 -38
  58. package/src/data/transforms/stack.js +0 -137
  59. package/src/data/transforms/stack.test.js +0 -91
  60. package/src/data/transforms/transformFactory.js +0 -60
  61. package/src/embedApi.d.ts +0 -67
  62. package/src/encoder/accessor.js +0 -82
  63. package/src/encoder/accessor.test.js +0 -47
  64. package/src/encoder/encoder.js +0 -394
  65. package/src/encoder/encoder.test.js +0 -98
  66. package/src/fonts/Lato-Regular.json +0 -1267
  67. package/src/fonts/Lato-Regular.png +0 -0
  68. package/src/fonts/OFL.txt +0 -93
  69. package/src/fonts/README.md +0 -3
  70. package/src/fonts/bmFont.d.ts +0 -58
  71. package/src/fonts/bmFontManager.js +0 -357
  72. package/src/fonts/bmFontMetrics.js +0 -108
  73. package/src/genome/genome.js +0 -317
  74. package/src/genome/genome.test.js +0 -188
  75. package/src/genome/genomeStore.js +0 -54
  76. package/src/genome/locusFormat.js +0 -31
  77. package/src/genome/scaleIndex.d.ts +0 -38
  78. package/src/genome/scaleIndex.js +0 -166
  79. package/src/genome/scaleIndex.test.js +0 -78
  80. package/src/genome/scaleLocus.d.ts +0 -11
  81. package/src/genome/scaleLocus.js +0 -108
  82. package/src/genome/scaleLocus.test.js +0 -4
  83. package/src/genomeSpy.js +0 -785
  84. package/src/gl/arrayBuilder.js +0 -199
  85. package/src/gl/dataToVertices.js +0 -636
  86. package/src/gl/includes/common.glsl +0 -63
  87. package/src/gl/includes/picking.fragment.glsl +0 -1
  88. package/src/gl/includes/picking.vertex.glsl +0 -27
  89. package/src/gl/includes/sampleFacet.glsl +0 -107
  90. package/src/gl/includes/scales.glsl +0 -112
  91. package/src/gl/link.fragment.glsl +0 -18
  92. package/src/gl/link.vertex.glsl +0 -111
  93. package/src/gl/point.fragment.glsl +0 -123
  94. package/src/gl/point.vertex.glsl +0 -129
  95. package/src/gl/rect.fragment.glsl +0 -51
  96. package/src/gl/rect.vertex.glsl +0 -114
  97. package/src/gl/rule.fragment.glsl +0 -52
  98. package/src/gl/rule.vertex.glsl +0 -89
  99. package/src/gl/text.fragment.glsl +0 -31
  100. package/src/gl/text.vertex.glsl +0 -246
  101. package/src/gl/webGLHelper.js +0 -504
  102. package/src/img/bowtie.svg +0 -1
  103. package/src/img/genomespy-favicon.svg +0 -34
  104. package/src/index.html +0 -11
  105. package/src/index.js +0 -128
  106. package/src/marks/link.js +0 -175
  107. package/src/marks/mark.js +0 -975
  108. package/src/marks/markUtils.js +0 -125
  109. package/src/marks/pointMark.js +0 -251
  110. package/src/marks/rectMark.js +0 -241
  111. package/src/marks/rule.js +0 -250
  112. package/src/marks/text.js +0 -278
  113. package/src/node_modules/.vitest/results.json +0 -1
  114. package/src/scale/colorUtils.js +0 -184
  115. package/src/scale/glslScaleGenerator.js +0 -502
  116. package/src/scale/scale.js +0 -451
  117. package/src/scale/scale.test.js +0 -324
  118. package/src/scale/ticks.js +0 -203
  119. package/src/scale/ticks.test.js +0 -40
  120. package/src/singlePageApp.js +0 -13
  121. package/src/spec/axis.d.ts +0 -296
  122. package/src/spec/channel.d.ts +0 -430
  123. package/src/spec/data.d.ts +0 -196
  124. package/src/spec/font.d.ts +0 -15
  125. package/src/spec/genome.d.ts +0 -35
  126. package/src/spec/mark.d.ts +0 -429
  127. package/src/spec/root.d.ts +0 -17
  128. package/src/spec/sampleView.d.ts +0 -180
  129. package/src/spec/scale.d.ts +0 -273
  130. package/src/spec/title.d.ts +0 -102
  131. package/src/spec/tooltip.d.ts +0 -9
  132. package/src/spec/transform.d.ts +0 -479
  133. package/src/spec/view.d.ts +0 -201
  134. package/src/styles/genome-spy.scss +0 -153
  135. package/src/tooltip/dataTooltipHandler.js +0 -64
  136. package/src/tooltip/refseqGeneTooltipHandler.js +0 -78
  137. package/src/tooltip/tooltipHandler.ts +0 -12
  138. package/src/types/filetypes.d.ts +0 -14
  139. package/src/types/flatqueue.d.ts +0 -53
  140. package/src/types/glsl.d.ts +0 -4
  141. package/src/types/internmap.d.ts +0 -22
  142. package/src/types/object.d.ts +0 -21
  143. package/src/types/vega-loader.d.ts +0 -1
  144. package/src/types/vega-scale.d.ts +0 -60
  145. package/src/utils/addBaseUrl.js +0 -19
  146. package/src/utils/addBaseUrl.test.js +0 -22
  147. package/src/utils/animator.js +0 -83
  148. package/src/utils/arrayUtils.js +0 -61
  149. package/src/utils/binnedIndex.js +0 -167
  150. package/src/utils/binnedIndex.test.js +0 -155
  151. package/src/utils/clamp.js +0 -8
  152. package/src/utils/cloner.js +0 -34
  153. package/src/utils/cloner.test.js +0 -24
  154. package/src/utils/coalesce.js +0 -11
  155. package/src/utils/coalesce.test.js +0 -16
  156. package/src/utils/concatIterables.js +0 -26
  157. package/src/utils/concatIterables.test.js +0 -8
  158. package/src/utils/debounce.js +0 -37
  159. package/src/utils/domainArray.js +0 -216
  160. package/src/utils/domainArray.test.js +0 -130
  161. package/src/utils/eerp.js +0 -13
  162. package/src/utils/expression.js +0 -32
  163. package/src/utils/field.js +0 -28
  164. package/src/utils/formatObject.js +0 -31
  165. package/src/utils/indexer.js +0 -43
  166. package/src/utils/indexer.test.js +0 -47
  167. package/src/utils/inertia.js +0 -124
  168. package/src/utils/interactionEvent.js +0 -33
  169. package/src/utils/iterateNestedMaps.js +0 -21
  170. package/src/utils/iterateNestedMaps.test.js +0 -33
  171. package/src/utils/kWayMerge.js +0 -42
  172. package/src/utils/kWayMerge.test.js +0 -26
  173. package/src/utils/layout/flexLayout.js +0 -368
  174. package/src/utils/layout/flexLayout.test.js +0 -311
  175. package/src/utils/layout/grid.js +0 -95
  176. package/src/utils/layout/grid.test.js +0 -71
  177. package/src/utils/layout/padding.js +0 -120
  178. package/src/utils/layout/point.js +0 -23
  179. package/src/utils/layout/rectangle.js +0 -288
  180. package/src/utils/layout/rectangle.test.js +0 -172
  181. package/src/utils/mergeObjects.js +0 -99
  182. package/src/utils/mergeObjects.test.js +0 -42
  183. package/src/utils/numberExtractor.js +0 -24
  184. package/src/utils/numberExtractor.test.js +0 -6
  185. package/src/utils/point.js +0 -14
  186. package/src/utils/propertyCacher.js +0 -70
  187. package/src/utils/propertyCacher.test.js +0 -85
  188. package/src/utils/propertyCoalescer.js +0 -42
  189. package/src/utils/propertyCoalescer.test.js +0 -22
  190. package/src/utils/reservationMap.js +0 -103
  191. package/src/utils/reservationMap.test.js +0 -20
  192. package/src/utils/scaleNull.js +0 -19
  193. package/src/utils/setOperations.js +0 -75
  194. package/src/utils/smoothstep.js +0 -10
  195. package/src/utils/throttle.js +0 -34
  196. package/src/utils/topK.js +0 -76
  197. package/src/utils/topK.test.js +0 -64
  198. package/src/utils/transition.js +0 -74
  199. package/src/utils/ui/tooltip.js +0 -189
  200. package/src/utils/url.js +0 -22
  201. package/src/utils/variableTools.js +0 -24
  202. package/src/utils/variableTools.test.js +0 -13
  203. package/src/view/axisResolution.js +0 -140
  204. package/src/view/axisResolution.test.js +0 -201
  205. package/src/view/axisView.js +0 -747
  206. package/src/view/concatView.js +0 -45
  207. package/src/view/containerView.js +0 -159
  208. package/src/view/facetView.js +0 -491
  209. package/src/view/flowBuilder.js +0 -367
  210. package/src/view/flowBuilder.test.js +0 -125
  211. package/src/view/gridView.js +0 -786
  212. package/src/view/implicitRootView.js +0 -14
  213. package/src/view/importView.js +0 -19
  214. package/src/view/layerView.js +0 -74
  215. package/src/view/rendering.d.ts +0 -44
  216. package/src/view/renderingContext/compositeViewRenderingContext.js +0 -51
  217. package/src/view/renderingContext/deferredViewRenderingContext.js +0 -176
  218. package/src/view/renderingContext/layoutRecorderViewRenderingContext.js +0 -128
  219. package/src/view/renderingContext/simpleViewRenderingContext.js +0 -64
  220. package/src/view/renderingContext/svgViewRenderingContext.js +0 -125
  221. package/src/view/renderingContext/viewRenderingContext.js +0 -41
  222. package/src/view/scaleResolution.js +0 -797
  223. package/src/view/scaleResolution.test.js +0 -572
  224. package/src/view/scaleResolutionApi.d.ts +0 -40
  225. package/src/view/testUtils.js +0 -51
  226. package/src/view/title.js +0 -165
  227. package/src/view/unitView.js +0 -382
  228. package/src/view/view.js +0 -612
  229. package/src/view/view.test.js +0 -214
  230. package/src/view/viewContext.d.ts +0 -62
  231. package/src/view/viewFactory.js +0 -181
  232. package/src/view/viewFactory.test.js +0 -17
  233. package/src/view/viewUtils.js +0 -327
  234. package/src/view/zoom.js +0 -89
Binary file
package/src/fonts/OFL.txt DELETED
@@ -1,93 +0,0 @@
1
- Copyright (c) 2010-2014 by tyPoland Lukasz Dziedzic (team@latofonts.com) with Reserved Font Name "Lato"
2
-
3
- This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
- This license is copied below, and is also available with a FAQ at:
5
- http://scripts.sil.org/OFL
6
-
7
-
8
- -----------------------------------------------------------
9
- SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
- -----------------------------------------------------------
11
-
12
- PREAMBLE
13
- The goals of the Open Font License (OFL) are to stimulate worldwide
14
- development of collaborative font projects, to support the font creation
15
- efforts of academic and linguistic communities, and to provide a free and
16
- open framework in which fonts may be shared and improved in partnership
17
- with others.
18
-
19
- The OFL allows the licensed fonts to be used, studied, modified and
20
- redistributed freely as long as they are not sold by themselves. The
21
- fonts, including any derivative works, can be bundled, embedded,
22
- redistributed and/or sold with any software provided that any reserved
23
- names are not used by derivative works. The fonts and derivatives,
24
- however, cannot be released under any other type of license. The
25
- requirement for fonts to remain under this license does not apply
26
- to any document created using the fonts or their derivatives.
27
-
28
- DEFINITIONS
29
- "Font Software" refers to the set of files released by the Copyright
30
- Holder(s) under this license and clearly marked as such. This may
31
- include source files, build scripts and documentation.
32
-
33
- "Reserved Font Name" refers to any names specified as such after the
34
- copyright statement(s).
35
-
36
- "Original Version" refers to the collection of Font Software components as
37
- distributed by the Copyright Holder(s).
38
-
39
- "Modified Version" refers to any derivative made by adding to, deleting,
40
- or substituting -- in part or in whole -- any of the components of the
41
- Original Version, by changing formats or by porting the Font Software to a
42
- new environment.
43
-
44
- "Author" refers to any designer, engineer, programmer, technical
45
- writer or other person who contributed to the Font Software.
46
-
47
- PERMISSION & CONDITIONS
48
- Permission is hereby granted, free of charge, to any person obtaining
49
- a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
- redistribute, and sell modified and unmodified copies of the Font
51
- Software, subject to the following conditions:
52
-
53
- 1) Neither the Font Software nor any of its individual components,
54
- in Original or Modified Versions, may be sold by itself.
55
-
56
- 2) Original or Modified Versions of the Font Software may be bundled,
57
- redistributed and/or sold with any software, provided that each copy
58
- contains the above copyright notice and this license. These can be
59
- included either as stand-alone text files, human-readable headers or
60
- in the appropriate machine-readable metadata fields within text or
61
- binary files as long as those fields can be easily viewed by the user.
62
-
63
- 3) No Modified Version of the Font Software may use the Reserved Font
64
- Name(s) unless explicit written permission is granted by the corresponding
65
- Copyright Holder. This restriction only applies to the primary font name as
66
- presented to the users.
67
-
68
- 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
- Software shall not be used to promote, endorse or advertise any
70
- Modified Version, except to acknowledge the contribution(s) of the
71
- Copyright Holder(s) and the Author(s) or with their explicit written
72
- permission.
73
-
74
- 5) The Font Software, modified or unmodified, in part or in whole,
75
- must be distributed entirely under this license, and must not be
76
- distributed under any other license. The requirement for fonts to
77
- remain under this license does not apply to any document created
78
- using the Font Software.
79
-
80
- TERMINATION
81
- This license becomes null and void if any of the above conditions are
82
- not met.
83
-
84
- DISCLAIMER
85
- THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
- OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
- COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
- INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
- DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
- FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
- OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -1,3 +0,0 @@
1
- # SDF fonts
2
-
3
- The json metadata and SDFs were taken from https://github.com/etiennepinchon/aframe-fonts
@@ -1,58 +0,0 @@
1
- export interface Char {
2
- id: number;
3
- width: number;
4
- height: number;
5
- xoffset: number;
6
- yoffset: number;
7
- xadvance: number;
8
- chnl: number;
9
- x: number;
10
- y: number;
11
- page: number;
12
- }
13
-
14
- export interface Info {
15
- face: string;
16
- size: number;
17
- bold: number;
18
- italic: number;
19
- charset: string[];
20
- unicode: number;
21
- stretchH: number;
22
- smooth: number;
23
- aa: number;
24
- padding: number[];
25
- spacing: number[];
26
- }
27
-
28
- export interface Common {
29
- lineHeight: number;
30
- base: number;
31
- scaleW: number;
32
- scaleH: number;
33
- pages: number;
34
- packed: number;
35
- alphaChnl: number;
36
- redChnl: number;
37
- greenChnl: number;
38
- blueChnl: number;
39
- }
40
-
41
- export interface Kerning {
42
- first: number;
43
- second: number;
44
- amount: number;
45
- }
46
-
47
- /**
48
- * BMFont as JSON.
49
- *
50
- * See: https://github.com/mattdesl/bmfont2json
51
- */
52
- export interface BMFont {
53
- pages: string[];
54
- chars: Char[];
55
- info: Info;
56
- common: Common;
57
- kernings: Kerning[];
58
- }
@@ -1,357 +0,0 @@
1
- import { InternMap } from "internmap";
2
- import { createTexture } from "twgl.js";
3
- import { isString } from "vega-util";
4
- import latoRegular from "../fonts/Lato-Regular.json";
5
- import latoRegularBitmap from "../fonts/Lato-Regular.png";
6
- import getMetrics from "./bmFontMetrics";
7
-
8
- const WEIGHTS = {
9
- thin: 100,
10
- light: 300,
11
- regular: 400,
12
- normal: 400,
13
- medium: 500,
14
- bold: 700,
15
- black: 900,
16
- };
17
-
18
- /**
19
- * Loader for A-Frame fonts.
20
- *
21
- * See:
22
- * https://github.com/mattdesl/bmfont2json
23
- * https://github.com/etiennepinchon/aframe-fonts
24
- *
25
- *
26
- * @typedef {import("./bmFont").BMFont} BMFont
27
- * @typedef {import("./bmFontMetrics").BMFontMetrics} BMFontMetrics
28
- *
29
- * @typedef {"normal" | "italic"} FontStyle
30
- * @typedef {number} FontWeight
31
- *
32
- * @typedef {object} FontKey
33
- * @prop {string} family
34
- * @prop {FontStyle} style
35
- * @prop {FontWeight} weight
36
- *
37
- * @typedef {object} FontEntry
38
- * @prop {BMFontMetrics} metrics
39
- * @prop {WebGLTexture} texture
40
- */
41
- export default class BmFontManager {
42
- /**
43
- * @param {import("../gl/webGLHelper").default} webGLHelper
44
- */
45
- constructor(webGLHelper) {
46
- this._webGLHelper = webGLHelper;
47
-
48
- this.fontRepository =
49
- "https://raw.githubusercontent.com/etiennepinchon/aframe-fonts/master/fonts/";
50
-
51
- /**
52
- * @type {Map<FontKey, FontEntry>}
53
- */
54
- this._fonts = new InternMap([], JSON.stringify);
55
-
56
- /** @type {Map<string, Promise<GoogleFontMetadataEntry[]>>} */
57
- this._metadataPromises = new Map();
58
-
59
- /** @type {Map<string, Promise<BMFontMetrics>>} */
60
- this._fontPromises = new Map();
61
-
62
- /** @type {Promise<void>[]} Keep track of overall font loading state */
63
- this._promises = [];
64
-
65
- /**
66
- * A default/fallback font to be used when font loading fails
67
- * @type {FontEntry}
68
- */
69
- this._defaultFontEntry = {
70
- metrics: getMetrics(latoRegular),
71
- texture: this._createTextureNow(latoRegularBitmap),
72
- };
73
- }
74
-
75
- async waitUntilReady() {
76
- await Promise.all(this._promises);
77
- }
78
-
79
- /**
80
- *
81
- * @param {string} family For example: "Lato"
82
- * @param {FontStyle} style
83
- * @param {FontWeight | keyof WEIGHTS} weight
84
- * @returns {FontEntry}
85
- */
86
- getFont(family, style = "normal", weight = "regular") {
87
- if (isString(weight)) {
88
- weight =
89
- WEIGHTS[/** @type {keyof WEIGHTS} */ (weight.toLowerCase())];
90
- if (!weight) {
91
- throw new Error("Unknown font weight: " + weight);
92
- }
93
- }
94
-
95
- const key = { family, style, weight };
96
- let fontEntry = this._fonts.get(key);
97
- if (!fontEntry) {
98
- // Return and empty entry, load it asynchronously
99
- fontEntry = {
100
- metrics: undefined,
101
- texture: undefined,
102
- };
103
- this._fonts.set(key, fontEntry);
104
-
105
- this._promises.push(this._loadFontEntry(fontEntry, key));
106
- }
107
-
108
- return fontEntry;
109
- }
110
-
111
- /**
112
- *
113
- * @param {FontEntry} fontEntry An uninitialized font entry
114
- * @param {FontKey} key
115
- */
116
- async _loadFontEntry(fontEntry, key) {
117
- try {
118
- const metadataEntries = await this._loadMetadata(key.family);
119
- const filename = findFilename(metadataEntries, key);
120
-
121
- const urlBase =
122
- this.fontRepository +
123
- simplifyFamily(key.family) +
124
- "/" +
125
- filename.replace(/\.\w+/, "");
126
-
127
- const texturePromise = this._createTexture(urlBase + ".png");
128
- const metricsPromise = this._loadFont(urlBase + ".json");
129
-
130
- fontEntry.texture = await texturePromise;
131
- fontEntry.metrics = await metricsPromise;
132
- } catch (error) {
133
- console.log("Cannot load font. Using default.", error);
134
-
135
- fontEntry.metrics = this._defaultFontEntry.metrics;
136
- fontEntry.texture = this._defaultFontEntry.texture;
137
- }
138
- }
139
-
140
- /**
141
- * @param {string} url
142
- */
143
- _loadFont(url) {
144
- let promise = this._fontPromises.get(url);
145
- if (!promise) {
146
- promise = fetch(url)
147
- .then((response) => {
148
- if (!response.ok) {
149
- throw new Error(
150
- "Could not load font: " + response.status
151
- );
152
- }
153
- return response;
154
- })
155
- .then((response) => response.json())
156
- .then((json) => getMetrics(/** @type {BMFont} */ (json)));
157
-
158
- this._fontPromises.set(url, promise);
159
- }
160
- return promise;
161
- }
162
-
163
- /**
164
- *
165
- * @param {string} family
166
- */
167
- _loadMetadata(family) {
168
- const dir = simplifyFamily(family);
169
-
170
- let promise = this._metadataPromises.get(dir);
171
- if (!promise) {
172
- promise = fetch(this.fontRepository + dir + "/METADATA.pb")
173
- .then((response) => {
174
- if (!response.ok) {
175
- throw new Error(
176
- "Could not load font metadata: " + response.status
177
- );
178
- }
179
- return response;
180
- })
181
- .then((response) => response.text())
182
- .then((text) => parseMetadataPb(text))
183
- .catch((error) => {
184
- console.warn(error);
185
- return undefined;
186
- });
187
-
188
- this._metadataPromises.set(dir, promise);
189
- }
190
-
191
- return promise;
192
- }
193
-
194
- getDefaultFont() {
195
- return this._defaultFontEntry;
196
- }
197
-
198
- /**
199
- *
200
- * @param {string} bitmapUrl
201
- * @returns {Promise<WebGLTexture>}
202
- */
203
- _createTexture(bitmapUrl) {
204
- const gl = this._webGLHelper.gl;
205
-
206
- return new Promise((resolve, reject) => {
207
- createTexture(
208
- gl,
209
- {
210
- src: bitmapUrl,
211
- min: gl.LINEAR,
212
- },
213
- (err, texture, source) => {
214
- if (err) {
215
- reject(err);
216
- } else {
217
- resolve(texture);
218
- }
219
- }
220
- );
221
- });
222
- }
223
-
224
- /**
225
- *
226
- * @param {string} bitmapUrl
227
- * @returns {WebGLTexture}
228
- */
229
- _createTextureNow(bitmapUrl) {
230
- const gl = this._webGLHelper.gl;
231
-
232
- /** @type {WebGLTexture} */
233
- let texture;
234
- const promise = new Promise((resolve, reject) => {
235
- texture = createTexture(
236
- gl,
237
- {
238
- src: bitmapUrl,
239
- min: gl.LINEAR,
240
- },
241
- (err, texture, source) => {
242
- if (err) {
243
- reject(err);
244
- } else {
245
- resolve(texture);
246
- }
247
- }
248
- );
249
- });
250
-
251
- this._promises.push(promise);
252
- return texture;
253
- }
254
- }
255
-
256
- /**
257
- *
258
- * @param {string} family
259
- */
260
- function simplifyFamily(family) {
261
- return family.toLowerCase().replaceAll(/[^\w]/g, "");
262
- }
263
-
264
- /**
265
- * A super-naive method for parsing METADATA.pb.
266
- * It's a text-format protobuf message, but I couldn't find a lightweight parser
267
- * for it.
268
- *
269
- * @typedef {object} GoogleFontMetadataEntry
270
- * @prop {string} name "Open Sans"
271
- * @prop {string} style "italic"
272
- * @prop {number} weight 400
273
- * @prop {string} filename "OpenSans-Italic.ttf"
274
- * @prop {string} post_script_name "OpenSans-Italic"
275
- * @prop {string} full_name "Open Sans Italic"
276
- * @prop {string} copyright "Digitized data copyright 2010-2011, Google Corporation."
277
- *
278
- * @param {string} metadata
279
- * @returns {GoogleFontMetadataEntry[]}
280
- */
281
- function parseMetadataPb(metadata) {
282
- const lines = metadata.split("\n");
283
-
284
- /** @type {GoogleFontMetadataEntry[]} */
285
- const entries = [];
286
-
287
- /** @type {GoogleFontMetadataEntry} */
288
- let entry;
289
-
290
- for (const line of lines) {
291
- if (line.startsWith("fonts {")) {
292
- /** @type {GoogleFontMetadataEntry} */
293
- entry = {
294
- name: undefined,
295
- style: undefined,
296
- weight: undefined,
297
- filename: undefined,
298
- post_script_name: undefined,
299
- full_name: undefined,
300
- copyright: undefined,
301
- };
302
- }
303
-
304
- if (line.startsWith("}")) {
305
- entries.push(entry);
306
- entry = undefined;
307
- }
308
-
309
- if (entry) {
310
- let m = line.match(/^\s*([A-Za-z_]+):[ ]?"(.*)"$/);
311
- if (m) {
312
- const key = /** @type {keyof GoogleFontMetadataEntry}*/ (m[1]);
313
- // @ts-ignore
314
- entry[key] = m[2];
315
- }
316
-
317
- m = line.match(/^\s*([A-Za-z_]+):[ ]?(\d+)$/);
318
- if (m) {
319
- const key = /** @type {keyof GoogleFontMetadataEntry}*/ (m[1]);
320
- // @ts-ignore
321
- entry[key] = +m[2];
322
- }
323
- }
324
- }
325
-
326
- return entries;
327
- }
328
-
329
- /**
330
- * @param {GoogleFontMetadataEntry[]} metadataEntries
331
- * @param {FontKey} key
332
- */
333
- function findFilename(metadataEntries, key) {
334
- /** @type {GoogleFontMetadataEntry} */
335
- let closest;
336
- let closestDistance = Number.POSITIVE_INFINITY;
337
-
338
- for (const e of metadataEntries) {
339
- if (
340
- key.family.localeCompare(e.name, undefined, {
341
- sensitivity: "accent",
342
- }) != 0
343
- ) {
344
- continue;
345
- }
346
-
347
- if (key.style == e.style) {
348
- const distance = Math.abs(key.weight - e.weight);
349
- if (distance < closestDistance) {
350
- closestDistance = distance;
351
- closest = e;
352
- }
353
- }
354
- }
355
-
356
- return closest?.filename;
357
- }
@@ -1,108 +0,0 @@
1
- export const SDF_PADDING = 5; // Not sure if this is same with all msdf bmfonts...
2
-
3
- const MAX_ASCII = 127;
4
-
5
- /**
6
- * Metrics calculation for msdf bmfonts:
7
- *
8
- * https://github.com/mattdesl/bmfont2json
9
- * https://github.com/etiennepinchon/aframe-fonts
10
- *
11
- * @typedef {import("./bmFont").Char} Char
12
- *
13
- * @typedef {object} BMFontMetrics
14
- * @prop {(text: string, fontSize?: number) => number} measureWidth
15
- * @prop {(charCode: number) => Char} getCharByCode
16
- * @prop {(char: string) => Char} getChar
17
- * @prop {number} xHeight
18
- * @prop {number} capHeight
19
- * @prop {number} descent
20
- * @prop {import("./bmFont").Common} common
21
- *
22
- * @param {import("./bmFont").BMFont} bmFont
23
- * @returns {BMFontMetrics}
24
- */
25
- export default function getMetrics(bmFont) {
26
- /**
27
- * Use an ordinary array for fast lookup of ascii chars
28
- *
29
- * @type {import("./bmFont").Char[]}
30
- */
31
- const asciiChars = [];
32
-
33
- // Ensure that the array is not "holey": https://v8.dev/blog/elements-kinds
34
- for (let i = 0; i <= MAX_ASCII; i++) {
35
- asciiChars.push(undefined);
36
- }
37
-
38
- /**
39
- * Put the rest (unicode = sparse and infrequent) chars into a map
40
- *
41
- * @type {Map<number, Char>}
42
- */
43
- const unicodeChars = new Map();
44
-
45
- for (const char of bmFont.chars) {
46
- if (char.id <= MAX_ASCII) {
47
- asciiChars[char.id] = char;
48
- } else {
49
- unicodeChars.set(char.id, char);
50
- }
51
- }
52
-
53
- // Workaround https://github.com/d3/d3-format/commit/39f41940386024d3b8a2172240189a0950c8dd23
54
- const minusHyphen = 8722;
55
- if (!unicodeChars.has(minusHyphen)) {
56
- unicodeChars.set(minusHyphen, asciiChars["-".charCodeAt(0)]);
57
- }
58
-
59
- /** @param {number} charCode */
60
- function getCharByCode(charCode) {
61
- const char =
62
- charCode <= MAX_ASCII
63
- ? asciiChars[charCode]
64
- : unicodeChars.get(charCode);
65
- return char || asciiChars[63];
66
- }
67
-
68
- /** @param {string} char */
69
- function getChar(char) {
70
- return getCharByCode(char.charCodeAt(0));
71
- }
72
-
73
- const base = bmFont.common.base;
74
-
75
- // Font metrics are not available in the bmfont metadata. Have to calculate...
76
- const x = getChar("x");
77
- const X = getChar("X");
78
- const q = getChar("q");
79
-
80
- const xHeight = x.height - SDF_PADDING * 2;
81
- const capHeight = X.height - SDF_PADDING * 2;
82
- const descent = q.height - x.height + q.yoffset - x.yoffset;
83
-
84
- /**
85
- * TODO: Kerning
86
- *
87
- * @param {string} text text to measure
88
- * @param {number} fontSize
89
- */
90
- function measureWidth(text, fontSize = 1.0) {
91
- let width = 0;
92
- for (let i = 0; i < text.length; i++) {
93
- width += getCharByCode(text.charCodeAt(i)).xadvance;
94
- }
95
-
96
- return (width / base) * fontSize;
97
- }
98
-
99
- return {
100
- measureWidth,
101
- getCharByCode,
102
- getChar,
103
- xHeight,
104
- capHeight,
105
- descent,
106
- common: bmFont.common,
107
- };
108
- }