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
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- import { StrokeCap, StrokeJoin } from '@shopify/react-native-skia';
4
- export const PT_TO_PX = 4 / 3;
5
- export const VEXFLOW_SCORE_COLORS = {
6
- light: {
7
- fill: '#111827',
8
- stroke: '#111827'
9
- },
10
- dark: {
11
- fill: '#F9FAFB',
12
- stroke: '#F9FAFB'
13
- }
14
- };
15
- export const DEFAULT_FILL_STYLE = VEXFLOW_SCORE_COLORS.light.fill;
16
- export const DEFAULT_STROKE_STYLE = VEXFLOW_SCORE_COLORS.light.stroke;
17
- export const DEFAULT_LINE_WIDTH = 1;
18
- export const DEFAULT_FONT = '12px Bravura';
19
- export const LINE_CAP_MAP = {
20
- butt: StrokeCap.Butt,
21
- round: StrokeCap.Round,
22
- square: StrokeCap.Square
23
- };
24
- export const LINE_JOIN_MAP = {
25
- miter: StrokeJoin.Miter,
26
- round: StrokeJoin.Round,
27
- bevel: StrokeJoin.Bevel
28
- };
29
- export const fontCache = new Map();
30
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["StrokeCap","StrokeJoin","PT_TO_PX","VEXFLOW_SCORE_COLORS","light","fill","stroke","dark","DEFAULT_FILL_STYLE","DEFAULT_STROKE_STYLE","DEFAULT_LINE_WIDTH","DEFAULT_FONT","LINE_CAP_MAP","butt","Butt","round","Round","square","Square","LINE_JOIN_MAP","miter","Miter","bevel","Bevel","fontCache","Map"],"sourceRoot":"../../src","sources":["constants.tsx"],"mappings":";;AAAA,SAAsBA,SAAS,EAAEC,UAAU,QAAQ,4BAA4B;AAG/E,OAAO,MAAMC,QAAQ,GAAG,CAAC,GAAG,CAAC;AAE7B,OAAO,MAAMC,oBAAoB,GAAG;EAClCC,KAAK,EAAE;IACLC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV,CAAC;EACDC,IAAI,EAAE;IACJF,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACV;AACF,CAAU;AAEV,OAAO,MAAME,kBAAkB,GAAGL,oBAAoB,CAACC,KAAK,CAACC,IAAI;AACjE,OAAO,MAAMI,oBAAoB,GAAGN,oBAAoB,CAACC,KAAK,CAACE,MAAM;AACrE,OAAO,MAAMI,kBAAkB,GAAG,CAAC;AACnC,OAAO,MAAMC,YAAY,GAAG,cAAc;AAE1C,OAAO,MAAMC,YAAwC,GAAG;EACtDC,IAAI,EAAEb,SAAS,CAACc,IAAI;EACpBC,KAAK,EAAEf,SAAS,CAACgB,KAAK;EACtBC,MAAM,EAAEjB,SAAS,CAACkB;AACpB,CAAC;AAED,OAAO,MAAMC,aAA2C,GAAG;EACzDC,KAAK,EAAEnB,UAAU,CAACoB,KAAK;EACvBN,KAAK,EAAEd,UAAU,CAACe,KAAK;EACvBM,KAAK,EAAErB,UAAU,CAACsB;AACpB,CAAC;AAED,OAAO,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAiB,CAAC","ignoreList":[]}
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- export * from "./constants.js";
4
- export * from "./types.js";
5
- export * from "./utils.js";
6
- export { default as SkiaVexflowContext } from "./SkiaVexflowContext.js";
7
- export { default as VexflowCanvas } from "./VexflowCanvas.js";
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["default","SkiaVexflowContext","VexflowCanvas"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,gBAAa;AAC3B,cAAc,YAAS;AACvB,cAAc,YAAS;AAEvB,SAASA,OAAO,IAAIC,kBAAkB,QAAQ,yBAAsB;AACpE,SAASD,OAAO,IAAIE,aAAa,QAAQ,oBAAiB","ignoreList":[]}
@@ -1,101 +0,0 @@
1
- import { type SkCanvas, type SkFont } from '@shopify/react-native-skia';
2
- import { RenderContext as VexflowRenderContext } from 'vexflow';
3
- import type { FontInfo } from 'vexflow';
4
- type SkiaVexflowContextOptions = {
5
- defaultFillStyle?: string;
6
- defaultStrokeStyle?: string;
7
- };
8
- type CanvasLineCap = 'butt' | 'round' | 'square';
9
- interface DOMMatrix2DInit {
10
- a?: number;
11
- b?: number;
12
- c?: number;
13
- d?: number;
14
- e?: number;
15
- f?: number;
16
- m11?: number;
17
- m12?: number;
18
- m21?: number;
19
- m22?: number;
20
- m41?: number;
21
- m42?: number;
22
- }
23
- interface CanvasGradient {
24
- /**
25
- * The **`CanvasGradient.addColorStop()`** method adds a new color stop, defined by an `offset` and a `color`, to a given canvas gradient.
26
- *
27
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CanvasGradient/addColorStop)
28
- */
29
- addColorStop(offset: number, color: string): void;
30
- }
31
- interface CanvasPattern {
32
- /**
33
- * The **`CanvasPattern.setTransform()`** method uses a DOMMatrix object as the pattern's transformation matrix and invokes it on the pattern.
34
- *
35
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CanvasPattern/setTransform)
36
- */
37
- setTransform(transform?: DOMMatrix2DInit): void;
38
- }
39
- export default class SkiaVexflowContext implements VexflowRenderContext {
40
- static get CATEGORY(): string;
41
- private canvas;
42
- private currentPath;
43
- private fillPaint;
44
- private strokePaint;
45
- private textFont;
46
- private bravuraFont;
47
- private defaultFillStyle;
48
- private defaultStrokeStyle;
49
- private stateStack;
50
- private state;
51
- constructor(canvas: SkCanvas, bravuraFont?: SkFont | null, options?: SkiaVexflowContextOptions);
52
- private applyState;
53
- clear(): void;
54
- setFillStyle(style: string): this;
55
- setBackgroundFillStyle(style: string): this;
56
- setStrokeStyle(style: string): this;
57
- setShadowColor(color: string): this;
58
- setShadowBlur(blur: number): this;
59
- setLineWidth(width: number): this;
60
- setLineCap(capType: CanvasLineCap): this;
61
- setLineDash(dashPattern: number[]): this;
62
- scale(x: number, y: number): this;
63
- rect(x: number, y: number, width: number, height: number): this;
64
- resize(width: number, height: number): this;
65
- fillRect(x: number, y: number, width: number, height: number): this;
66
- clearRect(x: number, y: number, width: number, height: number): this;
67
- pointerRect(x: number, y: number, width: number, height: number): this;
68
- beginPath(): this;
69
- moveTo(x: number, y: number): this;
70
- lineTo(x: number, y: number): this;
71
- bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
72
- quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
73
- arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: boolean): this;
74
- fill(attributes?: any): this;
75
- stroke(): this;
76
- closePath(): this;
77
- fillText(text: string, x: number, y: number): this;
78
- save(): this;
79
- restore(): this;
80
- openGroup(cls?: string, id?: string): null;
81
- closeGroup(): void;
82
- openRotation(angleDegrees: number, x: number, y: number): void;
83
- closeRotation(): void;
84
- add(child: any): void;
85
- measureText(text: string): {
86
- x: number;
87
- y: number;
88
- width: number;
89
- height: number;
90
- };
91
- set fillStyle(style: string | CanvasGradient | CanvasPattern);
92
- get fillStyle(): string | CanvasGradient | CanvasPattern;
93
- set strokeStyle(style: string | CanvasGradient | CanvasPattern);
94
- get strokeStyle(): string | CanvasGradient | CanvasPattern;
95
- setFont(font?: string | FontInfo, size?: string | number, weight?: string | number, style?: string): this;
96
- getFont(): string;
97
- set font(font: string);
98
- get font(): string;
99
- }
100
- export {};
101
- //# sourceMappingURL=SkiaVexflowContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SkiaVexflowContext.d.ts","sourceRoot":"","sources":["../../../src/SkiaVexflowContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,MAAM,EAGZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS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,IAAI,CAAC,IAAI,EAAE,MAAM,EAIpB;IAED,IAAI,IAAI,IANO,MAAM,CAQpB;CACF"}
@@ -1,17 +0,0 @@
1
- import { useFont } from '@shopify/react-native-skia';
2
- import SkiaVexflowContext from './SkiaVexflowContext';
3
- export type VexflowCanvasDrawArgs = {
4
- ctx: SkiaVexflowContext;
5
- width: number;
6
- height: number;
7
- };
8
- type VexflowCanvasProps = {
9
- onDraw: (args: VexflowCanvasDrawArgs) => void;
10
- font: Parameters<typeof useFont>[0];
11
- width?: number;
12
- height?: number;
13
- colorScheme?: 'light' | 'dark';
14
- };
15
- export default function VexflowCanvas({ onDraw, font, width, height, colorScheme, }: VexflowCanvasProps): import("react/jsx-runtime").JSX.Element;
16
- export {};
17
- //# sourceMappingURL=VexflowCanvas.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VexflowCanvas.d.ts","sourceRoot":"","sources":["../../../src/VexflowCanvas.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,OAAO,EAGR,MAAM,4BAA4B,CAAC;AAKpC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAMtD,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,kBAAkB,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC9C,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAChC,CAAC;AAqEF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,MAAM,EACN,IAAI,EACJ,KAAK,EACL,MAAsB,EACtB,WAAqB,GACtB,EAAE,kBAAkB,2CAuCpB"}
@@ -1,2 +0,0 @@
1
- export declare function resolveScoreColor(style: string, themeColor: string): string;
2
- //# sourceMappingURL=colorUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"colorUtils.d.ts","sourceRoot":"","sources":["../../../src/colorUtils.ts"],"names":[],"mappings":"AAgDA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM3E"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=colorUtils.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"colorUtils.test.d.ts","sourceRoot":"","sources":["../../../src/colorUtils.test.ts"],"names":[],"mappings":""}
@@ -1,21 +0,0 @@
1
- import { type SkFont, StrokeCap, StrokeJoin } from '@shopify/react-native-skia';
2
- import { type LineCap, type LineJoin } from './types';
3
- export declare const PT_TO_PX: number;
4
- export declare const VEXFLOW_SCORE_COLORS: {
5
- readonly light: {
6
- readonly fill: "#111827";
7
- readonly stroke: "#111827";
8
- };
9
- readonly dark: {
10
- readonly fill: "#F9FAFB";
11
- readonly stroke: "#F9FAFB";
12
- };
13
- };
14
- export declare const DEFAULT_FILL_STYLE: "#111827";
15
- export declare const DEFAULT_STROKE_STYLE: "#111827";
16
- export declare const DEFAULT_LINE_WIDTH = 1;
17
- export declare const DEFAULT_FONT = "12px Bravura";
18
- export declare const LINE_CAP_MAP: Record<LineCap, StrokeCap>;
19
- export declare const LINE_JOIN_MAP: Record<LineJoin, StrokeJoin>;
20
- export declare const fontCache: Map<string, SkFont>;
21
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAE9B,eAAO,MAAM,oBAAoB;;;;;;;;;CASvB,CAAC;AAEX,eAAO,MAAM,kBAAkB,WAAkC,CAAC;AAClE,eAAO,MAAM,oBAAoB,WAAoC,CAAC;AACtE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAInD,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,QAAQ,EAAE,UAAU,CAItD,CAAC;AAEF,eAAO,MAAM,SAAS,qBAA4B,CAAC"}
@@ -1,7 +0,0 @@
1
- export * from './constants';
2
- export * from './types';
3
- export * from './utils';
4
- export { default as SkiaVexflowContext } from './SkiaVexflowContext';
5
- export { default as VexflowCanvas } from './VexflowCanvas';
6
- export type { VexflowCanvasDrawArgs } from './VexflowCanvas';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,YAAY,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,462 +0,0 @@
1
- import {
2
- BlendMode,
3
- PaintStyle,
4
- Skia,
5
- type SkCanvas,
6
- type SkFont,
7
- type SkPaint,
8
- type SkPath,
9
- } from '@shopify/react-native-skia';
10
- import { RenderContext as VexflowRenderContext } from 'vexflow';
11
- import type { FontInfo } from 'vexflow';
12
-
13
- import {
14
- DEFAULT_FILL_STYLE,
15
- DEFAULT_FONT,
16
- DEFAULT_LINE_WIDTH,
17
- DEFAULT_STROKE_STYLE,
18
- LINE_CAP_MAP,
19
- LINE_JOIN_MAP,
20
- } from './constants';
21
- import { resolveScoreColor } from './colorUtils';
22
- import { type LineCap, type LineJoin } from './types';
23
- import {
24
- createFont,
25
- getAdvanceWidth,
26
- parseCssFontShorthand,
27
- toPxFontSize,
28
- } from './utils';
29
-
30
- /* eslint-disable no-void */
31
-
32
- type RenderState = {
33
- fillStyle: string;
34
- strokeStyle: string;
35
- lineWidth: number;
36
- lineCap: LineCap;
37
- lineJoin: LineJoin;
38
- font: string;
39
- };
40
-
41
- type SkiaVexflowContextOptions = {
42
- defaultFillStyle?: string;
43
- defaultStrokeStyle?: string;
44
- };
45
-
46
- const isWarnDisabled = true;
47
-
48
- function notImplemented(methodName: string): void {
49
- if (!isWarnDisabled) {
50
- console.warn(`SkiaVexflowContext: ${methodName} is not implemented yet.`);
51
- }
52
- }
53
-
54
- // MDN copied types
55
- type CanvasLineCap = 'butt' | 'round' | 'square';
56
-
57
- interface DOMMatrix2DInit {
58
- a?: number;
59
- b?: number;
60
- c?: number;
61
- d?: number;
62
- e?: number;
63
- f?: number;
64
- m11?: number;
65
- m12?: number;
66
- m21?: number;
67
- m22?: number;
68
- m41?: number;
69
- m42?: number;
70
- }
71
-
72
- interface CanvasGradient {
73
- /**
74
- * The **`CanvasGradient.addColorStop()`** method adds a new color stop, defined by an `offset` and a `color`, to a given canvas gradient.
75
- *
76
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CanvasGradient/addColorStop)
77
- */
78
- addColorStop(offset: number, color: string): void;
79
- }
80
-
81
- interface CanvasPattern {
82
- /**
83
- * The **`CanvasPattern.setTransform()`** method uses a DOMMatrix object as the pattern's transformation matrix and invokes it on the pattern.
84
- *
85
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CanvasPattern/setTransform)
86
- */
87
- setTransform(transform?: DOMMatrix2DInit): void;
88
- }
89
-
90
- export default class SkiaVexflowContext implements VexflowRenderContext {
91
- static get CATEGORY() {
92
- return 'SkiaVexflowContext';
93
- }
94
-
95
- private canvas: SkCanvas;
96
- private currentPath: SkPath;
97
- private fillPaint: SkPaint;
98
- private strokePaint: SkPaint;
99
- private textFont: SkFont;
100
- private bravuraFont: SkFont | null;
101
- private defaultFillStyle: string;
102
- private defaultStrokeStyle: string;
103
- private stateStack: RenderState[] = [];
104
-
105
- private state: RenderState = {
106
- fillStyle: DEFAULT_FILL_STYLE,
107
- strokeStyle: DEFAULT_STROKE_STYLE,
108
- lineWidth: DEFAULT_LINE_WIDTH,
109
- lineCap: 'butt',
110
- lineJoin: 'miter',
111
- font: DEFAULT_FONT,
112
- };
113
-
114
- constructor(
115
- canvas: SkCanvas,
116
- bravuraFont: SkFont | null = null,
117
- options: SkiaVexflowContextOptions = {}
118
- ) {
119
- this.canvas = canvas;
120
- this.bravuraFont = bravuraFont;
121
-
122
- this.currentPath = Skia.Path.Make();
123
-
124
- this.fillPaint = Skia.Paint();
125
- this.fillPaint.setStyle(PaintStyle.Fill);
126
- this.fillPaint.setAntiAlias(true);
127
-
128
- this.strokePaint = Skia.Paint();
129
- this.strokePaint.setStyle(PaintStyle.Stroke);
130
- this.strokePaint.setAntiAlias(true);
131
-
132
- this.textFont = createFont(12, 'Bravura', this.bravuraFont);
133
-
134
- if (options.defaultFillStyle !== undefined) {
135
- this.state.fillStyle = options.defaultFillStyle;
136
- }
137
-
138
- if (options.defaultStrokeStyle !== undefined) {
139
- this.state.strokeStyle = options.defaultStrokeStyle;
140
- }
141
-
142
- this.defaultFillStyle = this.state.fillStyle;
143
- this.defaultStrokeStyle = this.state.strokeStyle;
144
-
145
- this.applyState();
146
- }
147
-
148
- private applyState(): void {
149
- this.fillPaint.setColor(Skia.Color(this.state.fillStyle));
150
-
151
- this.strokePaint.setColor(Skia.Color(this.state.strokeStyle));
152
- this.strokePaint.setStrokeWidth(this.state.lineWidth);
153
- this.strokePaint.setStrokeCap(LINE_CAP_MAP[this.state.lineCap]);
154
- this.strokePaint.setStrokeJoin(LINE_JOIN_MAP[this.state.lineJoin]);
155
-
156
- const parsed = parseCssFontShorthand(this.state.font);
157
- this.textFont = createFont(parsed.sizePx, parsed.family, this.bravuraFont);
158
- }
159
-
160
- clear() {
161
- this.canvas.clear(Skia.Color('transparent'));
162
- }
163
-
164
- setFillStyle(style: string) {
165
- this.fillStyle = style;
166
- return this;
167
- }
168
-
169
- setBackgroundFillStyle(style: string) {
170
- void style;
171
- notImplemented('setBackgroundFillStyle');
172
- return this;
173
- }
174
-
175
- setStrokeStyle(style: string) {
176
- this.strokeStyle = style;
177
- return this;
178
- }
179
-
180
- setShadowColor(color: string) {
181
- void color;
182
- notImplemented('setShadowColor');
183
- return this;
184
- }
185
-
186
- setShadowBlur(blur: number) {
187
- void blur;
188
- notImplemented('setShadowBlur');
189
- return this;
190
- }
191
-
192
- setLineWidth(width: number) {
193
- this.state.lineWidth = width;
194
- this.strokePaint.setStrokeWidth(width);
195
- return this;
196
- }
197
-
198
- setLineCap(capType: CanvasLineCap) {
199
- const cap: LineCap =
200
- capType === 'round' || capType === 'square' ? capType : 'butt';
201
- this.state.lineCap = cap;
202
- this.strokePaint.setStrokeCap(LINE_CAP_MAP[cap]);
203
- return this;
204
- }
205
-
206
- setLineDash(dashPattern: number[]) {
207
- void dashPattern;
208
- notImplemented('setLineDash');
209
- return this;
210
- }
211
-
212
- scale(x: number, y: number) {
213
- this.canvas.scale(x, y);
214
- return this;
215
- }
216
-
217
- rect(x: number, y: number, width: number, height: number) {
218
- this.currentPath.addRect(Skia.XYWHRect(x, y, width, height));
219
- return this;
220
- }
221
-
222
- resize(width: number, height: number) {
223
- void width;
224
- void height;
225
- notImplemented('resize');
226
- return this;
227
- }
228
-
229
- fillRect(x: number, y: number, width: number, height: number) {
230
- this.canvas.drawRect(Skia.XYWHRect(x, y, width, height), this.fillPaint);
231
- return this;
232
- }
233
-
234
- clearRect(x: number, y: number, width: number, height: number) {
235
- const clearPaint = Skia.Paint();
236
- clearPaint.setBlendMode(BlendMode.Clear);
237
- this.canvas.drawRect(Skia.XYWHRect(x, y, width, height), clearPaint);
238
- return this;
239
- }
240
-
241
- pointerRect(x: number, y: number, width: number, height: number) {
242
- void x;
243
- void y;
244
- void width;
245
- void height;
246
- notImplemented('pointerRect');
247
- return this;
248
- }
249
-
250
- beginPath() {
251
- this.currentPath = Skia.Path.Make();
252
- return this;
253
- }
254
-
255
- moveTo(x: number, y: number) {
256
- this.currentPath.moveTo(x, y);
257
- return this;
258
- }
259
-
260
- lineTo(x: number, y: number) {
261
- this.currentPath.lineTo(x, y);
262
- return this;
263
- }
264
-
265
- bezierCurveTo(
266
- cp1x: number,
267
- cp1y: number,
268
- cp2x: number,
269
- cp2y: number,
270
- x: number,
271
- y: number
272
- ) {
273
- this.currentPath.cubicTo(cp1x, cp1y, cp2x, cp2y, x, y);
274
- return this;
275
- }
276
-
277
- quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
278
- this.currentPath.quadTo(cpx, cpy, x, y);
279
- return this;
280
- }
281
-
282
- arc(
283
- x: number,
284
- y: number,
285
- radius: number,
286
- startAngle: number,
287
- endAngle: number,
288
- anticlockwise: boolean
289
- ) {
290
- const startDeg = (startAngle * 180) / Math.PI;
291
- const endDeg = (endAngle * 180) / Math.PI;
292
- const sweep = anticlockwise ? startDeg - endDeg : endDeg - startDeg;
293
-
294
- this.currentPath.addArc(
295
- Skia.XYWHRect(x - radius, y - radius, radius * 2, radius * 2),
296
- startDeg,
297
- sweep
298
- );
299
- return this;
300
- }
301
-
302
- fill(attributes?: any) {
303
- void attributes;
304
- this.canvas.drawPath(this.currentPath, this.fillPaint);
305
- return this;
306
- }
307
-
308
- stroke() {
309
- this.canvas.drawPath(this.currentPath, this.strokePaint);
310
- return this;
311
- }
312
-
313
- closePath() {
314
- this.currentPath.close();
315
- return this;
316
- }
317
-
318
- fillText(text: string, x: number, y: number) {
319
- this.canvas.drawText(text, x, y, this.fillPaint, this.textFont);
320
- return this;
321
- }
322
-
323
- save() {
324
- this.canvas.save();
325
- this.stateStack.push({ ...this.state });
326
- return this;
327
- }
328
-
329
- restore() {
330
- this.canvas.restore();
331
- const prevState = this.stateStack.pop();
332
- if (prevState) {
333
- this.state = prevState;
334
- this.applyState();
335
- }
336
-
337
- return this;
338
- }
339
-
340
- openGroup(cls?: string, id?: string) {
341
- void cls;
342
- void id;
343
- notImplemented('openGroup');
344
- return null;
345
- }
346
-
347
- closeGroup() {
348
- notImplemented('closeGroup');
349
- }
350
-
351
- openRotation(angleDegrees: number, x: number, y: number) {
352
- void angleDegrees;
353
- void x;
354
- void y;
355
- notImplemented('openRotation');
356
- }
357
-
358
- closeRotation() {
359
- notImplemented('closeRotation');
360
- }
361
-
362
- add(child: any) {
363
- void child;
364
- notImplemented('add');
365
- }
366
-
367
- measureText(text: string) {
368
- const rect = this.textFont.measureText(text);
369
- const width = getAdvanceWidth(this.textFont, text);
370
- const height = rect.height;
371
-
372
- return {
373
- x: rect.x,
374
- y: rect.y,
375
- width,
376
- height,
377
- };
378
- }
379
-
380
- set fillStyle(style: string | CanvasGradient | CanvasPattern) {
381
- if (typeof style === 'string') {
382
- const resolvedStyle = resolveScoreColor(style, this.defaultFillStyle);
383
- this.state.fillStyle = resolvedStyle;
384
- this.fillPaint.setColor(Skia.Color(resolvedStyle));
385
- return;
386
- }
387
-
388
- notImplemented('set fillStyle (gradient/pattern)');
389
- }
390
-
391
- get fillStyle() {
392
- return this.state.fillStyle;
393
- }
394
-
395
- set strokeStyle(style: string | CanvasGradient | CanvasPattern) {
396
- if (typeof style === 'string') {
397
- const resolvedStyle = resolveScoreColor(style, this.defaultStrokeStyle);
398
- this.state.strokeStyle = resolvedStyle;
399
- this.strokePaint.setColor(Skia.Color(resolvedStyle));
400
- return;
401
- }
402
-
403
- notImplemented('set strokeStyle (gradient/pattern)');
404
- }
405
-
406
- get strokeStyle() {
407
- return this.state.strokeStyle;
408
- }
409
-
410
- setFont(
411
- font?: string | FontInfo,
412
- size?: string | number,
413
- weight?: string | number,
414
- style?: string
415
- ) {
416
- if (typeof font === 'object' && font !== null) {
417
- const fontSize = toPxFontSize(font.size);
418
- const family = Array.isArray(font.family)
419
- ? font.family.join(', ')
420
- : font.family;
421
- const fontWeight = font.weight ? ` ${font.weight}` : '';
422
- const fontStyle = font.style ? ` ${font.style}` : '';
423
-
424
- this.font = `${fontStyle}${fontWeight} ${fontSize}px ${
425
- family ?? 'sans-serif'
426
- }`.trim();
427
- return this;
428
- }
429
-
430
- if (
431
- typeof font === 'string' &&
432
- size === undefined &&
433
- weight === undefined &&
434
- style === undefined
435
- ) {
436
- this.font = font;
437
- return this;
438
- }
439
-
440
- const fontSize = toPxFontSize(size);
441
- const fontWeight = weight ? ` ${weight}` : '';
442
- const fontStyle = style ? ` ${style}` : '';
443
- const family = font || 'sans-serif';
444
-
445
- this.font = `${fontStyle}${fontWeight} ${fontSize}px ${family}`.trim();
446
- return this;
447
- }
448
-
449
- getFont() {
450
- return this.state.font;
451
- }
452
-
453
- set font(font: string) {
454
- this.state.font = font;
455
- const parsed = parseCssFontShorthand(font);
456
- this.textFont = createFont(parsed.sizePx, parsed.family, this.bravuraFont);
457
- }
458
-
459
- get font() {
460
- return this.state.font;
461
- }
462
- }