vexflow-native 0.2.0 → 1.0.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 (259) hide show
  1. package/README.md +265 -37
  2. package/lib/module/base/FontManager.js +139 -0
  3. package/lib/module/base/FontManager.js.map +1 -0
  4. package/lib/module/base/TextMeasureContext.js +46 -0
  5. package/lib/module/base/TextMeasureContext.js.map +1 -0
  6. package/lib/module/base/VexflowCanvas.js +48 -0
  7. package/lib/module/base/VexflowCanvas.js.map +1 -0
  8. package/lib/module/base/VexflowColorScheme.js +16 -0
  9. package/lib/module/base/VexflowColorScheme.js.map +1 -0
  10. package/lib/module/base/VexflowRecordingContext.js +425 -0
  11. package/lib/module/base/VexflowRecordingContext.js.map +1 -0
  12. package/lib/module/base/VexflowRecordingReplay.js +140 -0
  13. package/lib/module/base/VexflowRecordingReplay.js.map +1 -0
  14. package/lib/module/base/VexflowRecordingTypes.js +4 -0
  15. package/lib/module/base/VexflowRecordingTypes.js.map +1 -0
  16. package/lib/module/base/index.js +8 -0
  17. package/lib/module/base/index.js.map +1 -0
  18. package/lib/module/base/setupVexflowReactNative.js +96 -0
  19. package/lib/module/base/setupVexflowReactNative.js.map +1 -0
  20. package/lib/module/base/types.js +4 -0
  21. package/lib/module/base/types.js.map +1 -0
  22. package/lib/module/base/utils.js +18 -0
  23. package/lib/module/base/utils.js.map +1 -0
  24. package/lib/module/musicxml/MusicXmlParser/InternalTypes.js +4 -0
  25. package/lib/module/musicxml/MusicXmlParser/InternalTypes.js.map +1 -0
  26. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js +269 -0
  27. package/lib/module/musicxml/MusicXmlParser/MeasureParser.js.map +1 -0
  28. package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js +62 -0
  29. package/lib/module/musicxml/MusicXmlParser/MusicXmlDirections.js.map +1 -0
  30. package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js +124 -0
  31. package/lib/module/musicxml/MusicXmlParser/MusicXmlTiming.js.map +1 -0
  32. package/lib/module/musicxml/MusicXmlParser/PartParser.js +41 -0
  33. package/lib/module/musicxml/MusicXmlParser/PartParser.js.map +1 -0
  34. package/lib/module/musicxml/MusicXmlParser/Spanners.js +149 -0
  35. package/lib/module/musicxml/MusicXmlParser/Spanners.js.map +1 -0
  36. package/lib/module/musicxml/MusicXmlParser/XmlOrder.js +106 -0
  37. package/lib/module/musicxml/MusicXmlParser/XmlOrder.js.map +1 -0
  38. package/lib/module/musicxml/MusicXmlParser/index.js +110 -0
  39. package/lib/module/musicxml/MusicXmlParser/index.js.map +1 -0
  40. package/lib/module/musicxml/MusicXmlParser/mappers.js +312 -0
  41. package/lib/module/musicxml/MusicXmlParser/mappers.js.map +1 -0
  42. package/lib/module/musicxml/MusicXmlParser/types.js +10 -0
  43. package/lib/module/musicxml/MusicXmlParser/types.js.map +1 -0
  44. package/lib/module/musicxml/index.js +4 -0
  45. package/lib/module/musicxml/index.js.map +1 -0
  46. package/lib/module/musicxml/testfiles/lg-8102429.xml +79620 -0
  47. package/lib/module/renderer/Layout/DocumentLayout.js +156 -0
  48. package/lib/module/renderer/Layout/DocumentLayout.js.map +1 -0
  49. package/lib/module/renderer/Layout/LayoutMetrics.js +13 -0
  50. package/lib/module/renderer/Layout/LayoutMetrics.js.map +1 -0
  51. package/lib/module/renderer/Layout/VerticalSpacing.js +69 -0
  52. package/lib/module/renderer/Layout/VerticalSpacing.js.map +1 -0
  53. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js +232 -0
  54. package/lib/module/renderer/ScoreRenderer/ScoreRenderer.js.map +1 -0
  55. package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js +108 -0
  56. package/lib/module/renderer/ScoreRenderer/ScoreScrollbar.js.map +1 -0
  57. package/lib/module/renderer/ScoreRenderer/index.js +7 -0
  58. package/lib/module/renderer/ScoreRenderer/index.js.map +1 -0
  59. package/lib/module/renderer/ScoreRenderer/types.js +4 -0
  60. package/lib/module/renderer/ScoreRenderer/types.js.map +1 -0
  61. package/lib/module/renderer/ScoreRenderer/useScoreScroll.js +77 -0
  62. package/lib/module/renderer/ScoreRenderer/useScoreScroll.js.map +1 -0
  63. package/lib/module/renderer/colorScheme.js +17 -0
  64. package/lib/module/renderer/colorScheme.js.map +1 -0
  65. package/lib/module/renderer/constants.js +18 -0
  66. package/lib/module/renderer/constants.js.map +1 -0
  67. package/lib/module/renderer/index.js +6 -0
  68. package/lib/module/renderer/index.js.map +1 -0
  69. package/lib/module/renderer/layout.js +153 -0
  70. package/lib/module/renderer/layout.js.map +1 -0
  71. package/lib/module/renderer/measure.js +202 -0
  72. package/lib/module/renderer/measure.js.map +1 -0
  73. package/lib/module/renderer/render.js +163 -0
  74. package/lib/module/renderer/render.js.map +1 -0
  75. package/lib/module/renderer/scoreParsing.js +230 -0
  76. package/lib/module/renderer/scoreParsing.js.map +1 -0
  77. package/lib/module/renderer/types.js +4 -0
  78. package/lib/module/renderer/types.js.map +1 -0
  79. package/lib/module/renderer/useScoreRecording.js +112 -0
  80. package/lib/module/renderer/useScoreRecording.js.map +1 -0
  81. package/lib/module/renderer/viewport.js +26 -0
  82. package/lib/module/renderer/viewport.js.map +1 -0
  83. package/lib/module/shared/Logger.js +67 -0
  84. package/lib/module/shared/Logger.js.map +1 -0
  85. package/lib/module/state/index.js +4 -0
  86. package/lib/module/state/index.js.map +1 -0
  87. package/lib/module/state/types.js +2 -0
  88. package/lib/module/state/types.js.map +1 -0
  89. package/lib/module/types.js +7 -0
  90. package/lib/module/types.js.map +1 -1
  91. package/lib/module/utils.js +42 -77
  92. package/lib/module/utils.js.map +1 -1
  93. package/lib/typescript/src/base/FontManager.d.ts +23 -0
  94. package/lib/typescript/src/base/FontManager.d.ts.map +1 -0
  95. package/lib/typescript/src/base/TextMeasureContext.d.ts +22 -0
  96. package/lib/typescript/src/base/TextMeasureContext.d.ts.map +1 -0
  97. package/lib/typescript/src/base/VexflowCanvas.d.ts +5 -0
  98. package/lib/typescript/src/base/VexflowCanvas.d.ts.map +1 -0
  99. package/lib/typescript/src/base/VexflowColorScheme.d.ts +7 -0
  100. package/lib/typescript/src/base/VexflowColorScheme.d.ts.map +1 -0
  101. package/lib/typescript/src/base/VexflowRecordingContext.d.ts +74 -0
  102. package/lib/typescript/src/base/VexflowRecordingContext.d.ts.map +1 -0
  103. package/lib/typescript/src/base/VexflowRecordingReplay.d.ts +4 -0
  104. package/lib/typescript/src/base/VexflowRecordingReplay.d.ts.map +1 -0
  105. package/lib/typescript/src/base/VexflowRecordingTypes.d.ts +94 -0
  106. package/lib/typescript/src/base/VexflowRecordingTypes.d.ts.map +1 -0
  107. package/lib/typescript/src/base/index.d.ts +6 -0
  108. package/lib/typescript/src/base/index.d.ts.map +1 -0
  109. package/lib/typescript/src/base/setupVexflowReactNative.d.ts +11 -0
  110. package/lib/typescript/src/base/setupVexflowReactNative.d.ts.map +1 -0
  111. package/lib/typescript/src/base/types.d.ts +13 -0
  112. package/lib/typescript/src/base/types.d.ts.map +1 -0
  113. package/lib/typescript/src/base/utils.d.ts +2 -0
  114. package/lib/typescript/src/base/utils.d.ts.map +1 -0
  115. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts +30 -0
  116. package/lib/typescript/src/musicxml/MusicXmlParser/InternalTypes.d.ts.map +1 -0
  117. package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts +4 -0
  118. package/lib/typescript/src/musicxml/MusicXmlParser/MeasureParser.d.ts.map +1 -0
  119. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts +5 -0
  120. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlDirections.d.ts.map +1 -0
  121. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts +6 -0
  122. package/lib/typescript/src/musicxml/MusicXmlParser/MusicXmlTiming.d.ts.map +1 -0
  123. package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts +8 -0
  124. package/lib/typescript/src/musicxml/MusicXmlParser/PartParser.d.ts.map +1 -0
  125. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts +4 -0
  126. package/lib/typescript/src/musicxml/MusicXmlParser/Spanners.d.ts.map +1 -0
  127. package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts +20 -0
  128. package/lib/typescript/src/musicxml/MusicXmlParser/XmlOrder.d.ts.map +1 -0
  129. package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts +5 -0
  130. package/lib/typescript/src/musicxml/MusicXmlParser/index.d.ts.map +1 -0
  131. package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts +15 -0
  132. package/lib/typescript/src/musicxml/MusicXmlParser/mappers.d.ts.map +1 -0
  133. package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts +13 -0
  134. package/lib/typescript/src/musicxml/MusicXmlParser/types.d.ts.map +1 -0
  135. package/lib/typescript/src/musicxml/index.d.ts +2 -0
  136. package/lib/typescript/src/musicxml/index.d.ts.map +1 -0
  137. package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts +10 -0
  138. package/lib/typescript/src/renderer/Layout/DocumentLayout.d.ts.map +1 -0
  139. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts +6 -0
  140. package/lib/typescript/src/renderer/Layout/LayoutMetrics.d.ts.map +1 -0
  141. package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts +9 -0
  142. package/lib/typescript/src/renderer/Layout/VerticalSpacing.d.ts.map +1 -0
  143. package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts +14 -0
  144. package/lib/typescript/src/renderer/ScoreRenderer/ScoreRenderer.d.ts.map +1 -0
  145. package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts +24 -0
  146. package/lib/typescript/src/renderer/ScoreRenderer/ScoreScrollbar.d.ts.map +1 -0
  147. package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts +5 -0
  148. package/lib/typescript/src/renderer/ScoreRenderer/index.d.ts.map +1 -0
  149. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts +12 -0
  150. package/lib/typescript/src/renderer/ScoreRenderer/types.d.ts.map +1 -0
  151. package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts +13 -0
  152. package/lib/typescript/src/renderer/ScoreRenderer/useScoreScroll.d.ts.map +1 -0
  153. package/lib/typescript/src/renderer/colorScheme.d.ts +9 -0
  154. package/lib/typescript/src/renderer/colorScheme.d.ts.map +1 -0
  155. package/lib/typescript/src/renderer/constants.d.ts +5 -0
  156. package/lib/typescript/src/renderer/constants.d.ts.map +1 -0
  157. package/lib/typescript/src/renderer/index.d.ts +4 -0
  158. package/lib/typescript/src/renderer/index.d.ts.map +1 -0
  159. package/lib/typescript/src/renderer/layout.d.ts +56 -0
  160. package/lib/typescript/src/renderer/layout.d.ts.map +1 -0
  161. package/lib/typescript/src/renderer/measure.d.ts +23 -0
  162. package/lib/typescript/src/renderer/measure.d.ts.map +1 -0
  163. package/lib/typescript/src/renderer/render.d.ts +9 -0
  164. package/lib/typescript/src/renderer/render.d.ts.map +1 -0
  165. package/lib/typescript/src/renderer/scoreParsing.d.ts +76 -0
  166. package/lib/typescript/src/renderer/scoreParsing.d.ts.map +1 -0
  167. package/lib/typescript/src/renderer/types.d.ts +51 -0
  168. package/lib/typescript/src/renderer/types.d.ts.map +1 -0
  169. package/lib/typescript/src/renderer/useScoreRecording.d.ts +21 -0
  170. package/lib/typescript/src/renderer/useScoreRecording.d.ts.map +1 -0
  171. package/lib/typescript/src/renderer/viewport.d.ts +3 -0
  172. package/lib/typescript/src/renderer/viewport.d.ts.map +1 -0
  173. package/lib/typescript/src/shared/Logger.d.ts +18 -0
  174. package/lib/typescript/src/shared/Logger.d.ts.map +1 -0
  175. package/lib/typescript/src/state/index.d.ts +2 -0
  176. package/lib/typescript/src/state/index.d.ts.map +1 -0
  177. package/lib/typescript/src/state/types.d.ts +190 -0
  178. package/lib/typescript/src/state/types.d.ts.map +1 -0
  179. package/lib/typescript/src/types.d.ts +0 -6
  180. package/lib/typescript/src/types.d.ts.map +1 -1
  181. package/lib/typescript/src/utils.d.ts +0 -6
  182. package/lib/typescript/src/utils.d.ts.map +1 -1
  183. package/package.json +41 -13
  184. package/src/base/FontManager.ts +206 -0
  185. package/src/base/TextMeasureContext.ts +59 -0
  186. package/src/base/VexflowCanvas.tsx +60 -0
  187. package/src/base/VexflowColorScheme.ts +32 -0
  188. package/src/base/VexflowRecordingContext.ts +495 -0
  189. package/src/base/VexflowRecordingReplay.ts +211 -0
  190. package/src/base/VexflowRecordingTypes.ts +117 -0
  191. package/src/base/index.ts +6 -0
  192. package/src/base/setupVexflowReactNative.ts +124 -0
  193. package/src/base/types.ts +17 -0
  194. package/src/base/utils.ts +21 -0
  195. package/src/musicxml/MusicXmlParser/InternalTypes.ts +41 -0
  196. package/src/musicxml/MusicXmlParser/MeasureParser.ts +469 -0
  197. package/src/musicxml/MusicXmlParser/MusicXmlDirections.ts +84 -0
  198. package/src/musicxml/MusicXmlParser/MusicXmlTiming.ts +153 -0
  199. package/src/musicxml/MusicXmlParser/PartParser.ts +69 -0
  200. package/src/musicxml/MusicXmlParser/Spanners.ts +215 -0
  201. package/src/musicxml/MusicXmlParser/XmlOrder.ts +170 -0
  202. package/src/musicxml/MusicXmlParser/index.ts +144 -0
  203. package/src/musicxml/MusicXmlParser/mappers.ts +307 -0
  204. package/src/musicxml/MusicXmlParser/types.ts +24 -0
  205. package/src/musicxml/index.ts +5 -0
  206. package/src/musicxml/testfiles/lg-8102429.xml +79620 -0
  207. package/src/renderer/Layout/DocumentLayout.ts +240 -0
  208. package/src/renderer/Layout/LayoutMetrics.ts +21 -0
  209. package/src/renderer/Layout/VerticalSpacing.ts +122 -0
  210. package/src/renderer/ScoreRenderer/ScoreRenderer.tsx +310 -0
  211. package/src/renderer/ScoreRenderer/ScoreScrollbar.tsx +231 -0
  212. package/src/renderer/ScoreRenderer/index.ts +13 -0
  213. package/src/renderer/ScoreRenderer/types.ts +14 -0
  214. package/src/renderer/ScoreRenderer/useScoreScroll.ts +146 -0
  215. package/src/renderer/colorScheme.ts +28 -0
  216. package/src/renderer/constants.ts +19 -0
  217. package/src/renderer/index.ts +3 -0
  218. package/src/renderer/layout.ts +309 -0
  219. package/src/renderer/measure.tsx +304 -0
  220. package/src/renderer/render.tsx +281 -0
  221. package/src/renderer/scoreParsing.tsx +352 -0
  222. package/src/renderer/types.ts +60 -0
  223. package/src/renderer/useScoreRecording.ts +177 -0
  224. package/src/renderer/viewport.ts +45 -0
  225. package/src/shared/Logger.ts +85 -0
  226. package/src/state/index.ts +1 -0
  227. package/src/state/types.ts +295 -0
  228. package/src/types.ts +6 -6
  229. package/src/utils.tsx +32 -98
  230. package/lib/module/SkiaVexflowContext.js +0 -285
  231. package/lib/module/SkiaVexflowContext.js.map +0 -1
  232. package/lib/module/VexflowCanvas.js +0 -103
  233. package/lib/module/VexflowCanvas.js.map +0 -1
  234. package/lib/module/colorUtils.js +0 -34
  235. package/lib/module/colorUtils.js.map +0 -1
  236. package/lib/module/colorUtils.test.js +0 -37
  237. package/lib/module/colorUtils.test.js.map +0 -1
  238. package/lib/module/constants.js +0 -30
  239. package/lib/module/constants.js.map +0 -1
  240. package/lib/module/index.js +0 -8
  241. package/lib/module/index.js.map +0 -1
  242. package/lib/typescript/src/SkiaVexflowContext.d.ts +0 -101
  243. package/lib/typescript/src/SkiaVexflowContext.d.ts.map +0 -1
  244. package/lib/typescript/src/VexflowCanvas.d.ts +0 -17
  245. package/lib/typescript/src/VexflowCanvas.d.ts.map +0 -1
  246. package/lib/typescript/src/colorUtils.d.ts +0 -2
  247. package/lib/typescript/src/colorUtils.d.ts.map +0 -1
  248. package/lib/typescript/src/colorUtils.test.d.ts +0 -2
  249. package/lib/typescript/src/colorUtils.test.d.ts.map +0 -1
  250. package/lib/typescript/src/constants.d.ts +0 -21
  251. package/lib/typescript/src/constants.d.ts.map +0 -1
  252. package/lib/typescript/src/index.d.ts +0 -7
  253. package/lib/typescript/src/index.d.ts.map +0 -1
  254. package/src/SkiaVexflowContext.ts +0 -462
  255. package/src/VexflowCanvas.tsx +0 -145
  256. package/src/colorUtils.test.ts +0 -52
  257. package/src/colorUtils.ts +0 -55
  258. package/src/constants.tsx +0 -34
  259. package/src/index.ts +0 -8
package/src/utils.tsx CHANGED
@@ -1,108 +1,42 @@
1
- import { Skia, type SkFont } from '@shopify/react-native-skia';
1
+ // import { PT_TO_PX } from './constants';
2
+ // import { type ParsedCssFont } from './types';
2
3
 
3
- import { fontCache, PT_TO_PX } from './constants';
4
- import { type ParsedCssFont } from './types';
4
+ // export function toPxFontSize(size: number | string | undefined): number {
5
+ // if (size === undefined || size === null) return 12;
5
6
 
6
- export function getAdvanceWidth(font: SkFont, text: string): number {
7
- const glyphs = font.getGlyphIDs(text);
8
- const widths = font.getGlyphWidths(glyphs);
9
- return widths.reduce((sum, width) => sum + width, 0);
10
- }
7
+ // if (typeof size === 'number' && Number.isFinite(size)) {
8
+ // return size * PT_TO_PX;
9
+ // }
11
10
 
12
- export function toPxFontSize(size: number | string | undefined): number {
13
- if (size === undefined || size === null) return 12;
11
+ // if (typeof size === 'string') {
12
+ // const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt)?$/i);
14
13
 
15
- if (typeof size === 'number' && Number.isFinite(size)) {
16
- return size * PT_TO_PX;
17
- }
14
+ // if (match) {
15
+ // const value = Number.parseFloat(match[1] || '12');
16
+ // const unit = match[2]?.toLowerCase();
17
+ // if (!unit || unit === 'px') return value;
18
+ // return value * PT_TO_PX;
19
+ // }
20
+ // }
18
21
 
19
- if (typeof size === 'string') {
20
- const match = size.trim().match(/^(\d+(?:\.\d+)?)(px|pt)?$/i);
22
+ // return 12;
23
+ // }
21
24
 
22
- if (match) {
23
- const value = Number.parseFloat(match[1] || '12');
24
- const unit = match[2]?.toLowerCase();
25
- if (!unit || unit === 'px') return value;
26
- return value * PT_TO_PX;
27
- }
28
- }
25
+ // export function parseCssFontShorthand(cssFont: string): ParsedCssFont {
26
+ // const sizeMatch = cssFont.match(/(\d+(?:\.\d+)?(?:px|pt))/i);
29
27
 
30
- return 12;
31
- }
28
+ // if (!sizeMatch) {
29
+ // return { sizePx: 12 };
30
+ // }
32
31
 
33
- export function parseCssFontShorthand(cssFont: string): ParsedCssFont {
34
- const sizeMatch = cssFont.match(/(\d+(?:\.\d+)?(?:px|pt))/i);
32
+ // const sizePx = toPxFontSize(sizeMatch[1]);
35
33
 
36
- if (!sizeMatch) {
37
- return { sizePx: 12 };
38
- }
34
+ // const family = cssFont
35
+ // .slice((sizeMatch.index ?? 0) + (sizeMatch[1]?.length || 0))
36
+ // .trim();
39
37
 
40
- const sizePx = toPxFontSize(sizeMatch[1]);
41
-
42
- const family = cssFont
43
- .slice((sizeMatch.index ?? 0) + (sizeMatch[1]?.length || 0))
44
- .trim();
45
-
46
- return {
47
- sizePx,
48
- family: family || undefined,
49
- };
50
- }
51
-
52
- export function createFont(
53
- size: number,
54
- familyName?: string,
55
- bravuraFont?: SkFont | null
56
- ): SkFont {
57
- const fontSize = Number.isFinite(size) && size > 0 ? size : 12;
58
- const family = familyName?.trim();
59
-
60
- if (family?.toLowerCase().includes('bravura') && bravuraFont) {
61
- const cacheKey = `Bravura-${fontSize}`;
62
- const cached = fontCache.get(cacheKey);
63
- if (cached) return cached;
64
-
65
- const typeface = bravuraFont.getTypeface();
66
- if (typeface) {
67
- const font = Skia.Font(typeface, fontSize);
68
- fontCache.set(cacheKey, font);
69
- return font;
70
- }
71
- }
72
-
73
- const fontMgr = Skia.FontMgr.System();
74
- const requestedFamilies = family
75
- ? family
76
- .replace(/["']/g, '')
77
- .split(',')
78
- .map((part) => part.trim())
79
- .filter(Boolean)
80
- : [];
81
-
82
- for (const requestedFamily of requestedFamilies) {
83
- const typeface = fontMgr.matchFamilyStyle(requestedFamily, {
84
- weight: 400,
85
- width: 5,
86
- slant: 0,
87
- });
88
-
89
- if (typeface) {
90
- return Skia.Font(typeface, fontSize);
91
- }
92
- }
93
-
94
- for (let i = 0; i < fontMgr.countFamilies(); i++) {
95
- const systemFamily = fontMgr.getFamilyName(i);
96
- const typeface = fontMgr.matchFamilyStyle(systemFamily, {
97
- weight: 400,
98
- width: 5,
99
- slant: 0,
100
- });
101
-
102
- if (typeface) {
103
- return Skia.Font(typeface, fontSize);
104
- }
105
- }
106
-
107
- throw new Error('Unable to create a Skia font.');
108
- }
38
+ // return {
39
+ // sizePx,
40
+ // family: family || undefined,
41
+ // };
42
+ // }
@@ -1,285 +0,0 @@
1
- "use strict";
2
-
3
- import { BlendMode, PaintStyle, Skia } from '@shopify/react-native-skia';
4
- import { DEFAULT_FILL_STYLE, DEFAULT_FONT, DEFAULT_LINE_WIDTH, DEFAULT_STROKE_STYLE, LINE_CAP_MAP, LINE_JOIN_MAP } from "./constants.js";
5
- import { resolveScoreColor } from "./colorUtils.js";
6
- import { createFont, getAdvanceWidth, parseCssFontShorthand, toPxFontSize } from "./utils.js";
7
-
8
- /* eslint-disable no-void */
9
-
10
- const isWarnDisabled = true;
11
- function notImplemented(methodName) {
12
- if (!isWarnDisabled) {
13
- console.warn(`SkiaVexflowContext: ${methodName} is not implemented yet.`);
14
- }
15
- }
16
-
17
- // MDN copied types
18
-
19
- export default class SkiaVexflowContext {
20
- static get CATEGORY() {
21
- return 'SkiaVexflowContext';
22
- }
23
- stateStack = [];
24
- state = {
25
- fillStyle: DEFAULT_FILL_STYLE,
26
- strokeStyle: DEFAULT_STROKE_STYLE,
27
- lineWidth: DEFAULT_LINE_WIDTH,
28
- lineCap: 'butt',
29
- lineJoin: 'miter',
30
- font: DEFAULT_FONT
31
- };
32
- constructor(canvas, bravuraFont = null, options = {}) {
33
- this.canvas = canvas;
34
- this.bravuraFont = bravuraFont;
35
- this.currentPath = Skia.Path.Make();
36
- this.fillPaint = Skia.Paint();
37
- this.fillPaint.setStyle(PaintStyle.Fill);
38
- this.fillPaint.setAntiAlias(true);
39
- this.strokePaint = Skia.Paint();
40
- this.strokePaint.setStyle(PaintStyle.Stroke);
41
- this.strokePaint.setAntiAlias(true);
42
- this.textFont = createFont(12, 'Bravura', this.bravuraFont);
43
- if (options.defaultFillStyle !== undefined) {
44
- this.state.fillStyle = options.defaultFillStyle;
45
- }
46
- if (options.defaultStrokeStyle !== undefined) {
47
- this.state.strokeStyle = options.defaultStrokeStyle;
48
- }
49
- this.defaultFillStyle = this.state.fillStyle;
50
- this.defaultStrokeStyle = this.state.strokeStyle;
51
- this.applyState();
52
- }
53
- applyState() {
54
- this.fillPaint.setColor(Skia.Color(this.state.fillStyle));
55
- this.strokePaint.setColor(Skia.Color(this.state.strokeStyle));
56
- this.strokePaint.setStrokeWidth(this.state.lineWidth);
57
- this.strokePaint.setStrokeCap(LINE_CAP_MAP[this.state.lineCap]);
58
- this.strokePaint.setStrokeJoin(LINE_JOIN_MAP[this.state.lineJoin]);
59
- const parsed = parseCssFontShorthand(this.state.font);
60
- this.textFont = createFont(parsed.sizePx, parsed.family, this.bravuraFont);
61
- }
62
- clear() {
63
- this.canvas.clear(Skia.Color('transparent'));
64
- }
65
- setFillStyle(style) {
66
- this.fillStyle = style;
67
- return this;
68
- }
69
- setBackgroundFillStyle(style) {
70
- void style;
71
- notImplemented('setBackgroundFillStyle');
72
- return this;
73
- }
74
- setStrokeStyle(style) {
75
- this.strokeStyle = style;
76
- return this;
77
- }
78
- setShadowColor(color) {
79
- void color;
80
- notImplemented('setShadowColor');
81
- return this;
82
- }
83
- setShadowBlur(blur) {
84
- void blur;
85
- notImplemented('setShadowBlur');
86
- return this;
87
- }
88
- setLineWidth(width) {
89
- this.state.lineWidth = width;
90
- this.strokePaint.setStrokeWidth(width);
91
- return this;
92
- }
93
- setLineCap(capType) {
94
- const cap = capType === 'round' || capType === 'square' ? capType : 'butt';
95
- this.state.lineCap = cap;
96
- this.strokePaint.setStrokeCap(LINE_CAP_MAP[cap]);
97
- return this;
98
- }
99
- setLineDash(dashPattern) {
100
- void dashPattern;
101
- notImplemented('setLineDash');
102
- return this;
103
- }
104
- scale(x, y) {
105
- this.canvas.scale(x, y);
106
- return this;
107
- }
108
- rect(x, y, width, height) {
109
- this.currentPath.addRect(Skia.XYWHRect(x, y, width, height));
110
- return this;
111
- }
112
- resize(width, height) {
113
- void width;
114
- void height;
115
- notImplemented('resize');
116
- return this;
117
- }
118
- fillRect(x, y, width, height) {
119
- this.canvas.drawRect(Skia.XYWHRect(x, y, width, height), this.fillPaint);
120
- return this;
121
- }
122
- clearRect(x, y, width, height) {
123
- const clearPaint = Skia.Paint();
124
- clearPaint.setBlendMode(BlendMode.Clear);
125
- this.canvas.drawRect(Skia.XYWHRect(x, y, width, height), clearPaint);
126
- return this;
127
- }
128
- pointerRect(x, y, width, height) {
129
- void x;
130
- void y;
131
- void width;
132
- void height;
133
- notImplemented('pointerRect');
134
- return this;
135
- }
136
- beginPath() {
137
- this.currentPath = Skia.Path.Make();
138
- return this;
139
- }
140
- moveTo(x, y) {
141
- this.currentPath.moveTo(x, y);
142
- return this;
143
- }
144
- lineTo(x, y) {
145
- this.currentPath.lineTo(x, y);
146
- return this;
147
- }
148
- bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
149
- this.currentPath.cubicTo(cp1x, cp1y, cp2x, cp2y, x, y);
150
- return this;
151
- }
152
- quadraticCurveTo(cpx, cpy, x, y) {
153
- this.currentPath.quadTo(cpx, cpy, x, y);
154
- return this;
155
- }
156
- arc(x, y, radius, startAngle, endAngle, anticlockwise) {
157
- const startDeg = startAngle * 180 / Math.PI;
158
- const endDeg = endAngle * 180 / Math.PI;
159
- const sweep = anticlockwise ? startDeg - endDeg : endDeg - startDeg;
160
- this.currentPath.addArc(Skia.XYWHRect(x - radius, y - radius, radius * 2, radius * 2), startDeg, sweep);
161
- return this;
162
- }
163
- fill(attributes) {
164
- void attributes;
165
- this.canvas.drawPath(this.currentPath, this.fillPaint);
166
- return this;
167
- }
168
- stroke() {
169
- this.canvas.drawPath(this.currentPath, this.strokePaint);
170
- return this;
171
- }
172
- closePath() {
173
- this.currentPath.close();
174
- return this;
175
- }
176
- fillText(text, x, y) {
177
- this.canvas.drawText(text, x, y, this.fillPaint, this.textFont);
178
- return this;
179
- }
180
- save() {
181
- this.canvas.save();
182
- this.stateStack.push({
183
- ...this.state
184
- });
185
- return this;
186
- }
187
- restore() {
188
- this.canvas.restore();
189
- const prevState = this.stateStack.pop();
190
- if (prevState) {
191
- this.state = prevState;
192
- this.applyState();
193
- }
194
- return this;
195
- }
196
- openGroup(cls, id) {
197
- void cls;
198
- void id;
199
- notImplemented('openGroup');
200
- return null;
201
- }
202
- closeGroup() {
203
- notImplemented('closeGroup');
204
- }
205
- openRotation(angleDegrees, x, y) {
206
- void angleDegrees;
207
- void x;
208
- void y;
209
- notImplemented('openRotation');
210
- }
211
- closeRotation() {
212
- notImplemented('closeRotation');
213
- }
214
- add(child) {
215
- void child;
216
- notImplemented('add');
217
- }
218
- measureText(text) {
219
- const rect = this.textFont.measureText(text);
220
- const width = getAdvanceWidth(this.textFont, text);
221
- const height = rect.height;
222
- return {
223
- x: rect.x,
224
- y: rect.y,
225
- width,
226
- height
227
- };
228
- }
229
- set fillStyle(style) {
230
- if (typeof style === 'string') {
231
- const resolvedStyle = resolveScoreColor(style, this.defaultFillStyle);
232
- this.state.fillStyle = resolvedStyle;
233
- this.fillPaint.setColor(Skia.Color(resolvedStyle));
234
- return;
235
- }
236
- notImplemented('set fillStyle (gradient/pattern)');
237
- }
238
- get fillStyle() {
239
- return this.state.fillStyle;
240
- }
241
- set strokeStyle(style) {
242
- if (typeof style === 'string') {
243
- const resolvedStyle = resolveScoreColor(style, this.defaultStrokeStyle);
244
- this.state.strokeStyle = resolvedStyle;
245
- this.strokePaint.setColor(Skia.Color(resolvedStyle));
246
- return;
247
- }
248
- notImplemented('set strokeStyle (gradient/pattern)');
249
- }
250
- get strokeStyle() {
251
- return this.state.strokeStyle;
252
- }
253
- setFont(font, size, weight, style) {
254
- if (typeof font === 'object' && font !== null) {
255
- const fontSize = toPxFontSize(font.size);
256
- const family = Array.isArray(font.family) ? font.family.join(', ') : font.family;
257
- const fontWeight = font.weight ? ` ${font.weight}` : '';
258
- const fontStyle = font.style ? ` ${font.style}` : '';
259
- this.font = `${fontStyle}${fontWeight} ${fontSize}px ${family ?? 'sans-serif'}`.trim();
260
- return this;
261
- }
262
- if (typeof font === 'string' && size === undefined && weight === undefined && style === undefined) {
263
- this.font = font;
264
- return this;
265
- }
266
- const fontSize = toPxFontSize(size);
267
- const fontWeight = weight ? ` ${weight}` : '';
268
- const fontStyle = style ? ` ${style}` : '';
269
- const family = font || 'sans-serif';
270
- this.font = `${fontStyle}${fontWeight} ${fontSize}px ${family}`.trim();
271
- return this;
272
- }
273
- getFont() {
274
- return this.state.font;
275
- }
276
- set font(font) {
277
- this.state.font = font;
278
- const parsed = parseCssFontShorthand(font);
279
- this.textFont = createFont(parsed.sizePx, parsed.family, this.bravuraFont);
280
- }
281
- get font() {
282
- return this.state.font;
283
- }
284
- }
285
- //# sourceMappingURL=SkiaVexflowContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["BlendMode","PaintStyle","Skia","DEFAULT_FILL_STYLE","DEFAULT_FONT","DEFAULT_LINE_WIDTH","DEFAULT_STROKE_STYLE","LINE_CAP_MAP","LINE_JOIN_MAP","resolveScoreColor","createFont","getAdvanceWidth","parseCssFontShorthand","toPxFontSize","isWarnDisabled","notImplemented","methodName","console","warn","SkiaVexflowContext","CATEGORY","stateStack","state","fillStyle","strokeStyle","lineWidth","lineCap","lineJoin","font","constructor","canvas","bravuraFont","options","currentPath","Path","Make","fillPaint","Paint","setStyle","Fill","setAntiAlias","strokePaint","Stroke","textFont","defaultFillStyle","undefined","defaultStrokeStyle","applyState","setColor","Color","setStrokeWidth","setStrokeCap","setStrokeJoin","parsed","sizePx","family","clear","setFillStyle","style","setBackgroundFillStyle","setStrokeStyle","setShadowColor","color","setShadowBlur","blur","setLineWidth","width","setLineCap","capType","cap","setLineDash","dashPattern","scale","x","y","rect","height","addRect","XYWHRect","resize","fillRect","drawRect","clearRect","clearPaint","setBlendMode","Clear","pointerRect","beginPath","moveTo","lineTo","bezierCurveTo","cp1x","cp1y","cp2x","cp2y","cubicTo","quadraticCurveTo","cpx","cpy","quadTo","arc","radius","startAngle","endAngle","anticlockwise","startDeg","Math","PI","endDeg","sweep","addArc","fill","attributes","drawPath","stroke","closePath","close","fillText","text","drawText","save","push","restore","prevState","pop","openGroup","cls","id","closeGroup","openRotation","angleDegrees","closeRotation","add","child","measureText","resolvedStyle","setFont","size","weight","fontSize","Array","isArray","join","fontWeight","fontStyle","trim","getFont"],"sourceRoot":"../../src","sources":["SkiaVexflowContext.ts"],"mappings":";;AAAA,SACEA,SAAS,EACTC,UAAU,EACVC,IAAI,QAKC,4BAA4B;AAInC,SACEC,kBAAkB,EAClBC,YAAY,EACZC,kBAAkB,EAClBC,oBAAoB,EACpBC,YAAY,EACZC,aAAa,QACR,gBAAa;AACpB,SAASC,iBAAiB,QAAQ,iBAAc;AAEhD,SACEC,UAAU,EACVC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,QACP,YAAS;;AAEhB;;AAgBA,MAAMC,cAAc,GAAG,IAAI;AAE3B,SAASC,cAAcA,CAACC,UAAkB,EAAQ;EAChD,IAAI,CAACF,cAAc,EAAE;IACnBG,OAAO,CAACC,IAAI,CAAC,uBAAuBF,UAAU,0BAA0B,CAAC;EAC3E;AACF;;AAEA;;AAoCA,eAAe,MAAMG,kBAAkB,CAAiC;EACtE,WAAWC,QAAQA,CAAA,EAAG;IACpB,OAAO,oBAAoB;EAC7B;EAUQC,UAAU,GAAkB,EAAE;EAE9BC,KAAK,GAAgB;IAC3BC,SAAS,EAAEpB,kBAAkB;IAC7BqB,WAAW,EAAElB,oBAAoB;IACjCmB,SAAS,EAAEpB,kBAAkB;IAC7BqB,OAAO,EAAE,MAAM;IACfC,QAAQ,EAAE,OAAO;IACjBC,IAAI,EAAExB;EACR,CAAC;EAEDyB,WAAWA,CACTC,MAAgB,EAChBC,W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AAMH,MAAM,GAAG3B,IAAI,IAAI,YAAY;IAEnC,IAAI,CAACA,IAAI,GAAG,GAAGoH,SAAS,GAAGD,UAAU,IAAIJ,QAAQ,MAAMpF,MAAM,EAAE,CAAC0F,IAAI,CAAC,CAAC;IACtE,OAAO,IAAI;EACb;EAEAC,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAAC5H,KAAK,CAACM,IAAI;EACxB;EAEA,IAAIA,IAAIA,CAACA,IAAY,EAAE;IACrB,IAAI,CAACN,KAAK,CAACM,IAAI,GAAGA,IAAI;IACtB,MAAMyB,MAAM,GAAGzC,qBAAqB,CAACgB,IAAI,CAAC;IAC1C,IAAI,CAACe,QAAQ,GAAGjC,UAAU,CAAC2C,MAAM,CAACC,MAAM,EAAED,MAAM,CAACE,MAAM,EAAE,IAAI,CAACxB,WAAW,CAAC;EAC5E;EAEA,IAAIH,IAAIA,CAAA,EAAG;IACT,OAAO,IAAI,CAACN,KAAK,CAACM,IAAI;EACxB;AACF","ignoreList":[]}
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- import { Canvas, Picture, Skia, useFont } from '@shopify/react-native-skia';
4
- import { useMemo } from 'react';
5
- import { Element } from 'vexflow';
6
- import { Text, useWindowDimensions } from 'react-native';
7
- import SkiaVexflowContext from "./SkiaVexflowContext.js";
8
- import { VEXFLOW_SCORE_COLORS } from "./constants.js";
9
- import { createFont, getAdvanceWidth, parseCssFontShorthand } from "./utils.js";
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- const CANVAS_HEIGHT = 180;
12
- const fontName = 'vexflowFont';
13
- function createTextMeasurementCanvas(skiaFont) {
14
- let currentFont = createFont(12, fontName, skiaFont);
15
- const measureContext = {
16
- measureText: text => {
17
- const rect = currentFont.measureText(text);
18
- const width = getAdvanceWidth(currentFont, text);
19
- const ascent = Math.max(0, -rect.y);
20
- const descent = Math.max(0, rect.y + rect.height);
21
- return {
22
- width,
23
- actualBoundingBoxAscent: ascent,
24
- actualBoundingBoxDescent: descent,
25
- fontBoundingBoxAscent: ascent,
26
- fontBoundingBoxDescent: descent,
27
- actualBoundingBoxLeft: rect.x,
28
- actualBoundingBoxRight: rect.x + rect.width
29
- };
30
- }
31
- };
32
- Object.defineProperty(measureContext, 'font', {
33
- get() {
34
- return '';
35
- },
36
- set(value) {
37
- try {
38
- const parsed = parseCssFontShorthand(value);
39
- currentFont = createFont(parsed.sizePx, parsed.family, skiaFont);
40
- } catch {
41
- currentFont = createFont(12, fontName, skiaFont);
42
- }
43
- }
44
- });
45
- return {
46
- getContext: type => type === '2d' ? measureContext : null
47
- };
48
- }
49
- function createVexflowPicture(width, height, onDraw, skiaFont, scoreColors) {
50
- const recorder = Skia.PictureRecorder();
51
- const canvas = recorder.beginRecording(Skia.XYWHRect(0, 0, width, height));
52
- const ctx = new SkiaVexflowContext(canvas, skiaFont, {
53
- defaultFillStyle: scoreColors.fill,
54
- defaultStrokeStyle: scoreColors.stroke
55
- });
56
- onDraw({
57
- ctx,
58
- width,
59
- height
60
- });
61
- return recorder.finishRecordingAsPicture();
62
- }
63
- export default function VexflowCanvas({
64
- onDraw,
65
- font,
66
- width,
67
- height = CANVAS_HEIGHT,
68
- colorScheme = 'light'
69
- }) {
70
- const {
71
- width: windowWidth
72
- } = useWindowDimensions();
73
- const scoreColors = colorScheme === 'dark' ? VEXFLOW_SCORE_COLORS.dark : VEXFLOW_SCORE_COLORS.light;
74
- const canvasWidth = width ?? Math.max(300, Math.floor(windowWidth) - 32);
75
- const skiaFont = useFont(font, 30);
76
- const pictureInfo = useMemo(() => {
77
- if (!skiaFont) {
78
- return null;
79
- }
80
- Element.setTextMeasurementCanvas(createTextMeasurementCanvas(skiaFont));
81
- const picture = createVexflowPicture(canvasWidth, height, onDraw, skiaFont, scoreColors);
82
- return {
83
- picture,
84
- width: canvasWidth,
85
- height
86
- };
87
- }, [skiaFont, canvasWidth, height, onDraw, scoreColors]);
88
- if (!pictureInfo) {
89
- return /*#__PURE__*/_jsx(Text, {
90
- children: "Loading font..."
91
- });
92
- }
93
- return /*#__PURE__*/_jsx(Canvas, {
94
- style: {
95
- width: pictureInfo.width,
96
- height: pictureInfo.height
97
- },
98
- children: /*#__PURE__*/_jsx(Picture, {
99
- picture: pictureInfo.picture
100
- })
101
- });
102
- }
103
- //# sourceMappingURL=VexflowCanvas.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Canvas","Picture","Skia","useFont","useMemo","Element","Text","useWindowDimensions","SkiaVexflowContext","VEXFLOW_SCORE_COLORS","createFont","getAdvanceWidth","parseCssFontShorthand","jsx","_jsx","CANVAS_HEIGHT","fontName","createTextMeasurementCanvas","skiaFont","currentFont","measureContext","measureText","text","rect","width","ascent","Math","max","y","descent","height","actualBoundingBoxAscent","actualBoundingBoxDescent","fontBoundingBoxAscent","fontBoundingBoxDescent","actualBoundingBoxLeft","x","actualBoundingBoxRight","Object","defineProperty","get","set","value","parsed","sizePx","family","getContext","type","createVexflowPicture","onDraw","scoreColors","recorder","PictureRecorder","canvas","beginRecording","XYWHRect","ctx","defaultFillStyle","fill","defaultStrokeStyle","stroke","finishRecordingAsPicture","VexflowCanvas","font","colorScheme","windowWidth","dark","light","canvasWidth","floor","pictureInfo","setTextMeasurementCanvas","picture","children","style"],"sourceRoot":"../../src","sources":["VexflowCanvas.tsx"],"mappings":";;AAAA,SACEA,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,OAAO,QAGF,4BAA4B;AACnC,SAASC,OAAO,QAAQ,OAAO;AAC/B,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,IAAI,EAAEC,mBAAmB,QAAQ,cAAc;AAExD,OAAOC,kBAAkB,MAAM,yBAAsB;AACrD,SAASC,oBAAoB,QAAQ,gBAAa;AAClD,SAASC,UAAU,EAAEC,eAAe,EAAEC,qBAAqB,QAAQ,YAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE7E,MAAMC,aAAa,GAAG,GAAG;AAgBzB,MAAMC,QAAQ,GAAG,aAAa;AAE9B,S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GlE,OAAO,CAAC,MAAM;IAChC,IAAI,CAACc,QAAQ,EAAE;MACb,OAAO,IAAI;IACb;IAEAb,OAAO,CAACkE,wBAAwB,CAC9BtD,2BAA2B,CAACC,QAAQ,CACtC,CAAC;IAED,MAAMsD,OAAO,GAAGxB,oBAAoB,CAClCoB,WAAW,EACXtC,MAAM,EACNmB,MAAM,EACN/B,QAAQ,EACRgC,WACF,CAAC;IAED,OAAO;MAAEsB,OAAO;MAAEhD,KAAK,EAAE4C,WAAW;MAAEtC;IAAO,CAAC;EAChD,CAAC,EAAE,CAACZ,QAAQ,EAAEkD,WAAW,EAAEtC,MAAM,EAAEmB,MAAM,EAAEC,WAAW,CAAC,CAAC;EAExD,IAAI,CAACoB,WAAW,EAAE;IAChB,oBAAOxD,IAAA,CAACR,IAAI;MAAAmE,QAAA,EAAC;IAAe,CAAM,CAAC;EACrC;EAEA,oBACE3D,IAAA,CAACd,MAAM;IAAC0E,KAAK,EAAE;MAAElD,KAAK,EAAE8C,WAAW,CAAC9C,KAAK;MAAEM,MAAM,EAAEwC,WAAW,CAACxC;IAAO,CAAE;IAAA2C,QAAA,eACtE3D,IAAA,CAACb,OAAO;MAACuE,OAAO,EAAEF,WAAW,CAACE;IAAQ,CAAE;EAAC,CACnC,CAAC;AAEb","ignoreList":[]}
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- const SCORE_THEME_HEX_TOKENS = new Set(['#000', '#000000', '#444', '#444444', '#777', '#777777', '#999', '#999999']);
4
- const BLACK_KEYWORD = 'black';
5
- const BLACK_RGB_REGEX = /^rgb\(0,0,0\)$/;
6
- const BLACK_RGBA_REGEX = /^rgba\(0,0,0,(1|1\.0+|0?\.\d+)\)$/;
7
- const LEDGER_RGB_REGEX = /^rgb\(68,68,68\)$/;
8
- const LEDGER_RGBA_REGEX = /^rgba\(68,68,68,(1|1\.0+|0?\.\d+)\)$/;
9
- const BEND_RGB_REGEX = /^rgb\(119,119,119\)$/;
10
- const BEND_RGBA_REGEX = /^rgba\(119,119,119,(1|1\.0+|0?\.\d+)\)$/;
11
- const TAB_STAVE_RGB_REGEX = /^rgb\(153,153,153\)$/;
12
- const TAB_STAVE_RGBA_REGEX = /^rgba\(153,153,153,(1|1\.0+|0?\.\d+)\)$/;
13
- function normalizeColorToken(style) {
14
- return style.trim().toLowerCase().replace(/\s+/g, '');
15
- }
16
- function isBlackColorToken(style) {
17
- const normalized = normalizeColorToken(style);
18
- if (SCORE_THEME_HEX_TOKENS.has(normalized) || normalized === BLACK_KEYWORD) {
19
- return true;
20
- }
21
- if (BLACK_RGB_REGEX.test(normalized) || BLACK_RGBA_REGEX.test(normalized) || LEDGER_RGB_REGEX.test(normalized) || LEDGER_RGBA_REGEX.test(normalized) || BEND_RGB_REGEX.test(normalized) || BEND_RGBA_REGEX.test(normalized) || TAB_STAVE_RGB_REGEX.test(normalized) || TAB_STAVE_RGBA_REGEX.test(normalized)) {
22
- return true;
23
- }
24
- return false;
25
- }
26
-
27
- // Replaces VexFlow default black values with the active score theme color.
28
- export function resolveScoreColor(style, themeColor) {
29
- if (isBlackColorToken(style)) {
30
- return themeColor;
31
- }
32
- return style;
33
- }
34
- //# sourceMappingURL=colorUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["SCORE_THEME_HEX_TOKENS","Set","BLACK_KEYWORD","BLACK_RGB_REGEX","BLACK_RGBA_REGEX","LEDGER_RGB_REGEX","LEDGER_RGBA_REGEX","BEND_RGB_REGEX","BEND_RGBA_REGEX","TAB_STAVE_RGB_REGEX","TAB_STAVE_RGBA_REGEX","normalizeColorToken","style","trim","toLowerCase","replace","isBlackColorToken","normalized","has","test","resolveScoreColor","themeColor"],"sourceRoot":"../../src","sources":["colorUtils.ts"],"mappings":";;AAAA,MAAMA,sBAAsB,GAAG,IAAIC,GAAG,CAAC,CACrC,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,CACV,CAAC;AACF,MAAMC,aA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T,KAAK;AACd","ignoreList":[]}
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, expect, it } from '@jest/globals';
4
- import { resolveScoreColor } from "./colorUtils.js";
5
- describe('resolveScoreColor', () => {
6
- it('maps black tokens to active theme score color', () => {
7
- const themeColor = '#F9FAFB';
8
- expect(resolveScoreColor('black', themeColor)).toBe(themeColor);
9
- expect(resolveScoreColor('#000', themeColor)).toBe(themeColor);
10
- expect(resolveScoreColor('#000000', themeColor)).toBe(themeColor);
11
- expect(resolveScoreColor('rgb(0, 0, 0)', themeColor)).toBe(themeColor);
12
- expect(resolveScoreColor('rgba(0, 0, 0, 1)', themeColor)).toBe(themeColor);
13
- });
14
- it('maps VexFlow default ledger line tokens to active theme score color', () => {
15
- const themeColor = '#F9FAFB';
16
- expect(resolveScoreColor('#444', themeColor)).toBe(themeColor);
17
- expect(resolveScoreColor('#444444', themeColor)).toBe(themeColor);
18
- expect(resolveScoreColor('rgb(68, 68, 68)', themeColor)).toBe(themeColor);
19
- expect(resolveScoreColor('rgba(68, 68, 68, 1)', themeColor)).toBe(themeColor);
20
- });
21
- it('maps VexFlow default tab stave and bend tokens to active theme score color', () => {
22
- const themeColor = '#F9FAFB';
23
- expect(resolveScoreColor('#777', themeColor)).toBe(themeColor);
24
- expect(resolveScoreColor('#777777', themeColor)).toBe(themeColor);
25
- expect(resolveScoreColor('rgb(119, 119, 119)', themeColor)).toBe(themeColor);
26
- expect(resolveScoreColor('rgba(119, 119, 119, 1)', themeColor)).toBe(themeColor);
27
- expect(resolveScoreColor('#999', themeColor)).toBe(themeColor);
28
- expect(resolveScoreColor('#999999', themeColor)).toBe(themeColor);
29
- expect(resolveScoreColor('rgb(153, 153, 153)', themeColor)).toBe(themeColor);
30
- expect(resolveScoreColor('rgba(153, 153, 153, 1)', themeColor)).toBe(themeColor);
31
- });
32
- it('preserves non-black custom colors', () => {
33
- const themeColor = '#F9FAFB';
34
- expect(resolveScoreColor('#ef4444', themeColor)).toBe('#ef4444');
35
- });
36
- });
37
- //# sourceMappingURL=colorUtils.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["describe","expect","it","resolveScoreColor","themeColor","toBe"],"sourceRoot":"../../src","sources":["colorUtils.test.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,eAAe;AAEpD,SAASC,iBAAiB,QAAQ,iBAAc;AAEhDH,QAAQ,CAAC,mBAAmB,EAAE,MAAM;EAClCE,EAAE,CAAC,+CAA+C,EAAE,MAAM;IACxD,MAAME,UAAU,GAAG,SAAS;IAE5BH,MAAM,CAACE,iBAAiB,CAAC,OAAO,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IAC/DH,MAAM,CAACE,iBAAiB,CAAC,MAAM,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IAC9DH,MAAM,CAACE,iBAAiB,CAAC,SAAS,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IACjEH,MAAM,CAACE,iBAAiB,CAAC,cAAc,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IACtEH,MAAM,CAACE,iBAAiB,CAAC,kBAAkB,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;EAC5E,CAAC,CAAC;EAEFF,EAAE,CAAC,qEAAqE,EAAE,MAAM;IAC9E,MAAME,UAAU,GAAG,SAAS;IAE5BH,MAAM,CAACE,iBAAiB,CAAC,MAAM,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IAC9DH,MAAM,CAACE,iBAAiB,CAAC,SAAS,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IACjEH,MAAM,CAACE,iBAAiB,CAAC,iBAAiB,EAAEC,UAAU,CAAC,CAAC,CAACC,IAAI,CAACD,UAAU,CAAC;IACzEH,M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