jpfun 0.3.0 → 0.4.0

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 (125) hide show
  1. package/README.md +73 -1
  2. package/dist/converter/midi/convert.d.ts +50 -0
  3. package/dist/converter/midi/convert.js +700 -0
  4. package/dist/converter/midi/index.d.ts +5 -0
  5. package/dist/converter/midi/index.js +11 -0
  6. package/dist/converter/midi/json.d.ts +38 -0
  7. package/dist/converter/midi/json.js +1 -0
  8. package/dist/converter/midi/triplet.d.ts +30 -0
  9. package/dist/converter/midi/triplet.js +75 -0
  10. package/dist/converter/musicxml/dom.d.ts +25 -0
  11. package/dist/converter/musicxml/dom.js +65 -0
  12. package/dist/converter/musicxml/features.d.ts +51 -0
  13. package/dist/converter/musicxml/features.js +232 -0
  14. package/dist/converter/musicxml/index.d.ts +9 -0
  15. package/dist/converter/musicxml/index.js +1140 -0
  16. package/dist/converter/musicxml/model.d.ts +123 -0
  17. package/dist/converter/musicxml/model.js +1 -0
  18. package/dist/converter/source.d.ts +22 -0
  19. package/dist/converter/source.js +51 -0
  20. package/dist/core.d.ts +22 -0
  21. package/dist/core.js +22 -0
  22. package/dist/functions/ASTtypes.d.ts +28 -25
  23. package/dist/functions/ASTtypes.js +25 -23
  24. package/dist/functions/adjust/index.js +1 -1
  25. package/dist/functions/arpeggio/index.d.ts +2 -0
  26. package/dist/functions/arpeggio/index.js +180 -0
  27. package/dist/functions/arpeggio/shape.d.ts +7 -0
  28. package/dist/functions/arpeggio/shape.js +122 -0
  29. package/dist/functions/bar/index.js +23 -15
  30. package/dist/functions/beam/auto.d.ts +1 -1
  31. package/dist/functions/beam/auto.js +1 -1
  32. package/dist/functions/beam/layout.d.ts +2 -2
  33. package/dist/functions/beam/layout.js +1 -1
  34. package/dist/functions/box/index.js +2 -2
  35. package/dist/functions/br/index.js +1 -1
  36. package/dist/functions/dash/index.js +7 -6
  37. package/dist/functions/default.js +6 -2
  38. package/dist/functions/dot/index.js +12 -22
  39. package/dist/functions/dyn/index.d.ts +2 -0
  40. package/dist/functions/dyn/index.js +242 -0
  41. package/dist/functions/grace/index.d.ts +1 -1
  42. package/dist/functions/grace/index.js +2 -3
  43. package/dist/functions/head/index.js +149 -145
  44. package/dist/functions/key/index.js +5 -4
  45. package/dist/functions/meter/index.js +6 -5
  46. package/dist/functions/note/index.js +68 -21
  47. package/dist/functions/note/noteNameFSM.js +52 -63
  48. package/dist/functions/page/index.d.ts +2 -0
  49. package/dist/functions/page/index.js +22 -7
  50. package/dist/functions/program/index.d.ts +2 -0
  51. package/dist/functions/program/index.js +30 -0
  52. package/dist/functions/set/index.js +8 -5
  53. package/dist/functions/symbol/index.d.ts +13 -3
  54. package/dist/functions/symbol/index.js +61 -16
  55. package/dist/functions/symbol/shape.d.ts +2 -0
  56. package/dist/functions/symbol/shape.js +14 -10
  57. package/dist/functions/symbol/symbols/dc.d.ts +4 -0
  58. package/dist/functions/symbol/symbols/dc.js +82 -0
  59. package/dist/functions/symbol/symbols/{f.d.ts → ds.d.ts} +1 -1
  60. package/dist/functions/symbol/symbols/ds.js +93 -0
  61. package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
  62. package/dist/functions/symbol/symbols/dynamics.js +168 -0
  63. package/dist/functions/symbol/symbols/{p.d.ts → fine.d.ts} +1 -1
  64. package/dist/functions/symbol/symbols/fine.js +12 -0
  65. package/dist/functions/symbol/symbols/mordent.js +44 -31
  66. package/dist/functions/symbol/symbols/prall.d.ts +2 -0
  67. package/dist/functions/symbol/symbols/prall.js +42 -0
  68. package/dist/functions/symbol/symbols/segno.d.ts +4 -0
  69. package/dist/functions/symbol/symbols/segno.js +82 -0
  70. package/dist/functions/symbol/symbols/tr.js +0 -4
  71. package/dist/functions/tempo/index.js +5 -3
  72. package/dist/functions/temporal.d.ts +138 -0
  73. package/dist/functions/temporal.js +101 -0
  74. package/dist/functions/text/index.js +14 -7
  75. package/dist/functions/tie/index.js +37 -28
  76. package/dist/functions/tuplet/index.js +14 -7
  77. package/dist/functions/up/index.js +23 -21
  78. package/dist/functions/voice/index.js +121 -45
  79. package/dist/functions/volta/index.js +51 -48
  80. package/dist/iife/core.d.ts +1 -0
  81. package/dist/iife/core.js +3 -0
  82. package/dist/iife/from-midi.d.ts +1 -0
  83. package/dist/iife/from-midi.js +15 -0
  84. package/dist/iife/from-musicxml.d.ts +1 -0
  85. package/dist/iife/from-musicxml.js +3 -0
  86. package/dist/iife/full.d.ts +1 -0
  87. package/dist/iife/full.js +3 -0
  88. package/dist/index.d.ts +3 -21
  89. package/dist/index.js +3 -21
  90. package/dist/jpfun.core.min.js +153 -0
  91. package/dist/jpfun.from-midi.min.js +9 -0
  92. package/dist/jpfun.from-musicxml.min.js +12 -0
  93. package/dist/jpfun.min.js +71 -48
  94. package/dist/layout/default.js +2 -3
  95. package/dist/layout/engine.d.ts +2 -1
  96. package/dist/layout/engine.js +71 -26
  97. package/dist/layout/model.d.ts +4 -4
  98. package/dist/layout/model.js +15 -12
  99. package/dist/layout/page.js +5 -4
  100. package/dist/layout/path.js +3 -3
  101. package/dist/layout/types.d.ts +20 -2
  102. package/dist/lowering/loweringContext.d.ts +3 -1
  103. package/dist/lowering/loweringContext.js +28 -14
  104. package/dist/lowering/track.d.ts +4 -8
  105. package/dist/lowering/track.js +6 -1
  106. package/dist/lowering/types.d.ts +5 -128
  107. package/dist/lowering/types.js +1 -98
  108. package/dist/parser/parse-utils/string-utils.d.ts +2 -0
  109. package/dist/parser/parse-utils/string-utils.js +4 -0
  110. package/dist/parser/parserContext.d.ts +7 -8
  111. package/dist/parser/parserContext.js +41 -36
  112. package/dist/pipeline.d.ts +6 -5
  113. package/dist/pipeline.js +4 -5
  114. package/dist/playback/compile.d.ts +1 -1
  115. package/dist/playback/compile.js +15 -2
  116. package/dist/playback/event.d.ts +17 -3
  117. package/dist/playback/event.js +30 -12
  118. package/dist/playback/time.js +1 -1
  119. package/dist/playback/types.d.ts +5 -4
  120. package/dist/render/text.d.ts +6 -1
  121. package/dist/render/text.js +8 -1
  122. package/grammar.md +44 -8
  123. package/package.json +11 -2
  124. package/dist/functions/symbol/symbols/f.js +0 -55
  125. package/dist/functions/symbol/symbols/p.js +0 -61
@@ -1,43 +1,56 @@
1
1
  import { ornament } from "../ornament.js";
2
2
  export const mordentSymbol = {
3
3
  name: "mordent",
4
- description: "波音:本音、调内上方二度、本音",
5
- weight: 0.55,
4
+ description: "下波音:本音、调内下方二度、本音",
5
+ // = prall 的 0.55 × 10.0123/7.5001:竖线让字形更高,按这个比例放大波浪笔画才等大
6
+ weight: 0.73423,
6
7
  shapes: [
7
8
  {
8
9
  path: [
9
- { op: "M", x: 3.12541, y: 0.06003 },
10
- { op: "C", cx1: 3.18541, cy1: 0.03003, cx2: 3.30541, cy2: 0.00003, x: 3.36541, y: 0.00003 },
11
- { op: "C", cx1: 3.66541, cy1: 0.00003, cx2: 3.63541, cy2: -0.02997, x: 5.25541, y: 1.95003 },
12
- { op: "L", x: 6.78541, y: 3.78003 },
13
- { op: "C", cx1: 6.81541, cy1: 3.78003, cx2: 7.35541, cy2: 2.94003, x: 8.01541, y: 1.95003 },
14
- { op: "C", cx1: 9.15541, cy1: 0.27003, cx2: 9.24541, cy2: 0.12003, x: 9.36541, y: 0.06003 },
15
- { op: "C", cx1: 9.42541, cy1: 0.03003, cx2: 9.54541, cy2: 0.00003, x: 9.60541, y: 0.00003 },
16
- { op: "C", cx1: 9.90541, cy1: 0.00003, cx2: 9.87541, cy2: -0.02997, x: 11.49541, y: 1.95003 },
17
- { op: "L", x: 13.02541, y: 3.78003 },
18
- { op: "L", x: 13.50541, y: 3.09003 },
19
- { op: "C", cx1: 14.01541, cy1: 2.31003, cx2: 14.04541, cy2: 2.25003, x: 14.19541, y: 2.19003 },
20
- { op: "C", cx1: 14.61541, cy1: 2.01003, cx2: 15.06541, cy2: 2.34003, x: 15.00541, y: 2.79003 },
21
- { op: "C", cx1: 14.97541, cy1: 2.91003, cx2: 14.70541, cy2: 3.30003, x: 13.50541, y: 5.16003 },
22
- { op: "C", cx1: 12.12541, cy1: 7.23003, cx2: 12.00541, cy2: 7.38003, x: 11.88541, y: 7.44003 },
23
- { op: "C", cx1: 11.82541, cy1: 7.47003, cx2: 11.70541, cy2: 7.50003, x: 11.64541, y: 7.50003 },
24
- { op: "C", cx1: 11.34541, cy1: 7.50003, cx2: 11.37541, cy2: 7.53003, x: 9.75541, y: 5.55003 },
25
- { op: "L", x: 8.22541, y: 3.72003 },
26
- { op: "C", cx1: 8.19541, cy1: 3.72003, cx2: 7.65541, cy2: 4.56003, x: 6.99541, y: 5.55003 },
27
- { op: "C", cx1: 5.85541, cy1: 7.23003, cx2: 5.76541, cy2: 7.38003, x: 5.64541, y: 7.44003 },
28
- { op: "C", cx1: 5.58541, cy1: 7.47003, cx2: 5.46541, cy2: 7.50003, x: 5.40541, y: 7.50003 },
29
- { op: "C", cx1: 5.10541, cy1: 7.50003, cx2: 5.13541, cy2: 7.53003, x: 3.51541, y: 5.55003 },
30
- { op: "L", x: 1.98541, y: 3.72003 },
31
- { op: "L", x: 1.50541, y: 4.41003 },
32
- { op: "C", cx1: 0.99541, cy1: 5.19003, cx2: 0.96541, cy2: 5.25003, x: 0.81541, y: 5.31003 },
33
- { op: "C", cx1: 0.39541, cy1: 5.49003, cx2: -0.05459, cy2: 5.16003, x: 0.00541, y: 4.71004 },
34
- { op: "C", cx1: 0.03541, cy1: 4.59004, cx2: 0.30541, cy2: 4.20004, x: 1.50541, y: 2.34004 },
35
- { op: "C", cx1: 2.88541, cy1: 0.27004, cx2: 3.00541, cy2: 0.12004, x: 3.12541, y: 0.06004 },
36
- { op: "L", x: 3.12541, y: 0.06003 },
10
+ { op: "M", x: 7.29541, y: 0.05944 },
11
+ { op: "C", cx1: 7.56541, cy1: -0.09056, cx2: 7.92541, cy2: 0.05944, x: 8.04541, y: 0.32944 },
12
+ { op: "C", cx1: 8.10541, cy1: 0.44944, cx2: 8.10541, cy2: 0.56944, x: 8.10541, y: 1.76943 },
13
+ { op: "L", x: 8.10541, y: 3.05943 },
14
+ { op: "L", x: 8.67541, y: 2.21943 },
15
+ { op: "C", cx1: 9.18541, cy1: 1.46943, cx2: 9.24541, cy2: 1.37943, x: 9.36541, y: 1.31943 },
16
+ { op: "C", cx1: 9.42541, cy1: 1.28943, cx2: 9.54541, cy2: 1.25943, x: 9.60541, y: 1.25943 },
17
+ { op: "C", cx1: 9.90541, cy1: 1.25943, cx2: 9.87541, cy2: 1.22943, x: 11.49541, y: 3.20943 },
18
+ { op: "L", x: 13.02541, y: 5.03943 },
19
+ { op: "L", x: 13.50541, y: 4.34943 },
20
+ { op: "C", cx1: 14.01541, cy1: 3.56943, cx2: 14.04541, cy2: 3.50943, x: 14.19541, y: 3.44943 },
21
+ { op: "C", cx1: 14.61541, cy1: 3.26943, cx2: 15.06541, cy2: 3.59943, x: 15.00541, y: 4.04943 },
22
+ { op: "C", cx1: 14.97541, cy1: 4.16943, cx2: 14.70541, cy2: 4.55943, x: 13.50541, y: 6.41943 },
23
+ { op: "C", cx1: 12.12541, cy1: 8.48943, cx2: 12.00541, cy2: 8.63943, x: 11.88541, y: 8.69943 },
24
+ { op: "C", cx1: 11.82541, cy1: 8.72943, cx2: 11.70541, cy2: 8.75943, x: 11.64541, y: 8.75943 },
25
+ { op: "C", cx1: 11.34541, cy1: 8.75943, cx2: 11.37541, cy2: 8.78943, x: 9.81541, y: 6.86943 },
26
+ { op: "C", cx1: 9.00541, cy1: 5.87943, cx2: 8.31541, cy2: 5.06943, x: 8.28541, y: 5.00943 },
27
+ { op: "C", cx1: 8.22541, cy1: 4.97943, cx2: 8.22541, cy2: 4.97943, x: 8.16541, y: 5.03943 },
28
+ { op: "C", cx1: 8.10541, cy1: 5.09943, cx2: 8.10541, cy2: 5.18943, x: 8.10541, y: 7.31943 },
29
+ { op: "C", cx1: 8.10541, cy1: 9.26943, cx2: 8.10541, cy2: 9.56943, x: 8.04541, y: 9.65943 },
30
+ { op: "C", cx1: 7.86541, cy1: 10.10943, cx2: 7.23541, cy2: 10.13943, x: 6.99541, y: 9.68943 },
31
+ { op: "C", cx1: 6.96541, cy1: 9.62943, cx2: 6.93541, cy2: 9.44943, x: 6.93541, y: 8.27943 },
32
+ { op: "L", x: 6.93541, y: 6.92943 },
33
+ { op: "L", x: 6.36541, y: 7.76943 },
34
+ { op: "C", cx1: 5.82541, cy1: 8.54943, cx2: 5.76541, cy2: 8.63943, x: 5.64541, y: 8.69943 },
35
+ { op: "C", cx1: 5.58541, cy1: 8.72943, cx2: 5.46541, cy2: 8.75943, x: 5.40541, y: 8.75943 },
36
+ { op: "C", cx1: 5.10541, cy1: 8.75943, cx2: 5.13541, cy2: 8.78943, x: 3.51541, y: 6.80943 },
37
+ { op: "L", x: 1.98541, y: 4.97943 },
38
+ { op: "L", x: 1.50541, y: 5.66943 },
39
+ { op: "C", cx1: 0.99541, cy1: 6.44943, cx2: 0.96541, cy2: 6.50943, x: 0.81541, y: 6.56943 },
40
+ { op: "C", cx1: 0.39541, cy1: 6.74943, cx2: -0.05459, cy2: 6.41943, x: 0.00541, y: 5.96943 },
41
+ { op: "C", cx1: 0.03541, cy1: 5.84943, cx2: 0.30541, cy2: 5.45943, x: 1.50541, y: 3.59943 },
42
+ { op: "C", cx1: 2.88541, cy1: 1.52943, cx2: 3.00541, cy2: 1.37943, x: 3.12541, y: 1.31943 },
43
+ { op: "C", cx1: 3.18541, cy1: 1.28943, cx2: 3.30541, cy2: 1.25943, x: 3.36541, y: 1.25943 },
44
+ { op: "C", cx1: 3.66541, cy1: 1.25943, cx2: 3.63541, cy2: 1.22943, x: 5.25541, y: 3.20943 },
45
+ { op: "L", x: 6.78541, y: 5.03943 },
46
+ { op: "C", cx1: 6.81541, cy1: 5.03943, cx2: 6.84541, cy2: 4.97943, x: 6.87541, y: 4.94943 },
47
+ { op: "C", cx1: 6.93541, cy1: 4.82943, cx2: 6.93541, cy2: 4.79943, x: 6.93541, y: 2.66943 },
48
+ { op: "C", cx1: 6.93541, cy1: 0.74943, cx2: 6.93541, cy2: 0.44943, x: 6.99541, y: 0.35943 },
49
+ { op: "C", cx1: 7.05541, cy1: 0.20943, cx2: 7.14541, cy2: 0.11943, x: 7.29541, y: 0.05943 },
37
50
  { op: "Z" },
38
51
  ],
39
52
  style: { fill: "#000" },
40
53
  },
41
54
  ],
42
- emitPlayback: emitter => emitter.affectFollowing(ornament({ body: [0, 1, 0] })),
55
+ emitPlayback: emitter => emitter.affectFollowing(ornament({ body: [0, -1, 0] })),
43
56
  };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const prallSymbol: SymbolDefinition;
@@ -0,0 +1,42 @@
1
+ import { ornament } from "../ornament.js";
2
+ export const prallSymbol = {
3
+ name: "prall",
4
+ description: "上波音:本音、调内上方二度、本音",
5
+ weight: 0.55,
6
+ shapes: [
7
+ {
8
+ path: [
9
+ { op: "M", x: 3.12541, y: 0.06003 },
10
+ { op: "C", cx1: 3.18541, cy1: 0.03003, cx2: 3.30541, cy2: 0.00003, x: 3.36541, y: 0.00003 },
11
+ { op: "C", cx1: 3.66541, cy1: 0.00003, cx2: 3.63541, cy2: -0.02997, x: 5.25541, y: 1.95003 },
12
+ { op: "L", x: 6.78541, y: 3.78003 },
13
+ { op: "C", cx1: 6.81541, cy1: 3.78003, cx2: 7.35541, cy2: 2.94003, x: 8.01541, y: 1.95003 },
14
+ { op: "C", cx1: 9.15541, cy1: 0.27003, cx2: 9.24541, cy2: 0.12003, x: 9.36541, y: 0.06003 },
15
+ { op: "C", cx1: 9.42541, cy1: 0.03003, cx2: 9.54541, cy2: 0.00003, x: 9.60541, y: 0.00003 },
16
+ { op: "C", cx1: 9.90541, cy1: 0.00003, cx2: 9.87541, cy2: -0.02997, x: 11.49541, y: 1.95003 },
17
+ { op: "L", x: 13.02541, y: 3.78003 },
18
+ { op: "L", x: 13.50541, y: 3.09003 },
19
+ { op: "C", cx1: 14.01541, cy1: 2.31003, cx2: 14.04541, cy2: 2.25003, x: 14.19541, y: 2.19003 },
20
+ { op: "C", cx1: 14.61541, cy1: 2.01003, cx2: 15.06541, cy2: 2.34003, x: 15.00541, y: 2.79003 },
21
+ { op: "C", cx1: 14.97541, cy1: 2.91003, cx2: 14.70541, cy2: 3.30003, x: 13.50541, y: 5.16003 },
22
+ { op: "C", cx1: 12.12541, cy1: 7.23003, cx2: 12.00541, cy2: 7.38003, x: 11.88541, y: 7.44003 },
23
+ { op: "C", cx1: 11.82541, cy1: 7.47003, cx2: 11.70541, cy2: 7.50003, x: 11.64541, y: 7.50003 },
24
+ { op: "C", cx1: 11.34541, cy1: 7.50003, cx2: 11.37541, cy2: 7.53003, x: 9.75541, y: 5.55003 },
25
+ { op: "L", x: 8.22541, y: 3.72003 },
26
+ { op: "C", cx1: 8.19541, cy1: 3.72003, cx2: 7.65541, cy2: 4.56003, x: 6.99541, y: 5.55003 },
27
+ { op: "C", cx1: 5.85541, cy1: 7.23003, cx2: 5.76541, cy2: 7.38003, x: 5.64541, y: 7.44003 },
28
+ { op: "C", cx1: 5.58541, cy1: 7.47003, cx2: 5.46541, cy2: 7.50003, x: 5.40541, y: 7.50003 },
29
+ { op: "C", cx1: 5.10541, cy1: 7.50003, cx2: 5.13541, cy2: 7.53003, x: 3.51541, y: 5.55003 },
30
+ { op: "L", x: 1.98541, y: 3.72003 },
31
+ { op: "L", x: 1.50541, y: 4.41003 },
32
+ { op: "C", cx1: 0.99541, cy1: 5.19003, cx2: 0.96541, cy2: 5.25003, x: 0.81541, y: 5.31003 },
33
+ { op: "C", cx1: 0.39541, cy1: 5.49003, cx2: -0.05459, cy2: 5.16003, x: 0.00541, y: 4.71004 },
34
+ { op: "C", cx1: 0.03541, cy1: 4.59004, cx2: 0.30541, cy2: 4.20004, x: 1.50541, y: 2.34004 },
35
+ { op: "C", cx1: 2.88541, cy1: 0.27004, cx2: 3.00541, cy2: 0.12004, x: 3.12541, y: 0.06004 },
36
+ { op: "Z" },
37
+ ],
38
+ style: { fill: "#000" },
39
+ },
40
+ ],
41
+ emitPlayback: emitter => emitter.affectFollowing(ornament({ body: [0, 1, 0] })),
42
+ };
@@ -0,0 +1,4 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ /** D.S. 的回跳目标;符号之间本不该有依赖,但「从记号处反复」的语义要求两者认识同一个标记 */
3
+ export declare const SEGNO_MARK = "repeat.segno";
4
+ export declare const segnoSymbol: SymbolDefinition;
@@ -0,0 +1,82 @@
1
+ /** D.S. 的回跳目标;符号之间本不该有依赖,但「从记号处反复」的语义要求两者认识同一个标记 */
2
+ export const SEGNO_MARK = "repeat.segno";
3
+ export const segnoSymbol = {
4
+ name: "segno",
5
+ description: "反复记号:D.S. 的回跳目标",
6
+ weight: 1.15,
7
+ playbackMarks: () => [SEGNO_MARK],
8
+ shapes: [
9
+ {
10
+ path: [
11
+ { op: "M", x: 3.75502, y: 7.52938 },
12
+ { op: "C", cx1: 1.3411, cy1: 6.32492, cx2: 0.10249, cy2: 4.89115, x: 0.03897, y: 3.23307 },
13
+ { op: "C", cx1: 0.06833, cy1: 2.69176, cx2: 0.20975, cy2: 2.17002, x: 0.45843, y: 1.67267 },
14
+ { op: "C", cx1: 0.71191, cy1: 1.1751, cx2: 1.05826, cy2: 0.77042, x: 1.49231, y: 0.46321 },
15
+ { op: "C", cx1: 1.93115, cy1: 0.156, cx2: 2.41873, cy2: 0, x: 2.95524, y: 0 },
16
+ { op: "C", cx1: 3.6136, cy1: 0, cx2: 4.17428, cy2: 0.17538, x: 4.64747, y: 0.52174 },
17
+ { op: "C", cx1: 5.12047, cy1: 0.8679, cx2: 5.35457, cy2: 1.36047, x: 5.35457, y: 1.99925 },
18
+ { op: "C", cx1: 5.33499, cy1: 2.26751, cx2: 5.21315, cy2: 2.49182, x: 4.98384, y: 2.66739 },
19
+ { op: "C", cx1: 4.75473, cy1: 2.83817, cx2: 4.50106, cy2: 2.93565, x: 4.21343, y: 2.95502 },
20
+ { op: "C", cx1: 3.67691, cy1: 2.90629, cx2: 3.35013, cy2: 2.68696, x: 3.23807, y: 2.29686 },
21
+ { op: "L", x: 3.06249, y: 1.73119 },
22
+ { op: "C", cx1: 2.93086, cy1: 1.31652, cx2: 2.71134, cy2: 1.0191, x: 2.29687, y: 1.0191 },
23
+ { op: "C", cx1: 1.99446, cy1: 1.0191, cx2: 1.74578, cy2: 1.16551, x: 1.55561, y: 1.46293 },
24
+ { op: "C", cx1: 1.36544, cy1: 1.76035, cx2: 1.26798, cy2: 2.06276, x: 1.25819, y: 2.37476 },
25
+ { op: "C", cx1: 1.28735, cy1: 2.79902, cx2: 1.42398, cy2: 3.17954, x: 1.66287, y: 3.50612 },
26
+ { op: "C", cx1: 1.90677, cy1: 3.8329, cx2: 2.20418, cy2: 4.11094, x: 2.56012, y: 4.34984 },
27
+ { op: "C", cx1: 2.91627, cy1: 4.58394, cx2: 3.31116, cy2: 4.79846, x: 3.73542, y: 4.99841 },
28
+ { op: "C", cx1: 4.15967, cy1: 5.19835, cx2: 4.57914, cy2: 5.38851, x: 4.99361, y: 5.57387 },
29
+ { op: "L", x: 8.62659, y: 0.12183 },
30
+ { op: "L", x: 9.70919, y: 0.12183 },
31
+ { op: "L", x: 5.85194, y: 5.97376 },
32
+ { op: "C", cx1: 6.5005, cy1: 6.29076, cx2: 7.09535, cy2: 6.65649, x: 7.62705, y: 7.06117 },
33
+ { op: "C", cx1: 8.15855, cy1: 7.47085, cx2: 8.60221, cy2: 7.95363, x: 8.95835, y: 8.50473 },
34
+ { op: "C", cx1: 9.3143, cy1: 9.05562, cx2: 9.48985, cy2: 9.65546, x: 9.48985, y: 10.30403 },
35
+ { op: "C", cx1: 9.48985, cy1: 10.86491, cx2: 9.35822, cy2: 11.39164, x: 9.08996, y: 11.88421 },
36
+ { op: "C", cx1: 8.82652, cy1: 12.37658, cx2: 8.44618, cy2: 12.77167, x: 7.9488, y: 13.0643 },
37
+ { op: "C", cx1: 7.45147, cy1: 13.35691, cx2: 6.871, cy2: 13.50314, x: 6.21285, y: 13.50314 },
38
+ { op: "C", cx1: 5.62259, cy1: 13.44461, cx2: 5.1448, cy2: 13.23009, x: 4.78386, y: 12.85457 },
39
+ { op: "C", cx1: 4.42791, cy1: 12.47906, cx2: 4.23776, cy2: 12.06938, x: 4.21338, y: 11.62572 },
40
+ { op: "C", cx1: 4.23275, cy1: 11.35746, cx2: 4.33043, cy2: 11.12338, x: 4.5108, y: 10.92821 },
41
+ { op: "C", cx1: 4.69118, cy1: 10.73326, cx2: 4.94485, cy2: 10.626, x: 5.27163, y: 10.60644 },
42
+ { op: "C", cx1: 5.63239, cy1: 10.60644, cx2: 5.88605, cy2: 10.68931, x: 6.03726, y: 10.85033 },
43
+ { op: "C", cx1: 6.18828, cy1: 11.01611, cx2: 6.31031, cy2: 11.26001, x: 6.3932, y: 11.58656 },
44
+ { op: "C", cx1: 6.48092, cy1: 11.91335, cx2: 6.56377, cy2: 12.14745, x: 6.64186, y: 12.2791 },
45
+ { op: "C", cx1: 6.72476, cy1: 12.41573, cx2: 6.88578, cy2: 12.48404, x: 7.12944, y: 12.48404 },
46
+ { op: "C", cx1: 7.50019, cy1: 12.48404, cx2: 7.78783, cy2: 12.35718, x: 7.99756, y: 12.10353 },
47
+ { op: "C", cx1: 8.20729, cy1: 11.85485, cx2: 8.30974, cy2: 11.52805, x: 8.30974, y: 11.12338 },
48
+ { op: "C", cx1: 8.30974, cy1: 10.57728, cx2: 8.11459, cy2: 10.11887, x: 7.72451, y: 9.74812 },
49
+ { op: "C", cx1: 7.33918, cy1: 9.38239, cx2: 6.75395, cy2: 9.00689, x: 5.97375, y: 8.62657 },
50
+ { op: "C", cx1: 5.19353, cy1: 8.25105, cx2: 4.73513, cy2: 8.01693, x: 4.59371, y: 7.92926 },
51
+ { op: "L", x: 1.05823, y: 13.42024 },
52
+ { op: "L", x: 0, y: 13.42024 },
53
+ { op: "L", x: 3.755, y: 7.52937 },
54
+ { op: "L", x: 3.75502, y: 7.52938 },
55
+ { op: "Z" },
56
+ { op: "M", x: 0.07812, y: 8.54848 },
57
+ { op: "C", cx1: 0.07812, cy1: 8.20711, cx2: 0.18039, cy2: 7.95364, x: 0.38033, y: 7.78285 },
58
+ { op: "C", cx1: 0.58028, cy1: 7.61227, cx2: 0.81937, cy2: 7.5294, x: 1.09721, y: 7.5294 },
59
+ { op: "C", cx1: 1.36068, cy1: 7.55377, cx2: 1.58499, cy2: 7.65124, x: 1.76535, y: 7.822 },
60
+ { op: "C", cx1: 1.94572, cy1: 7.99259, cx2: 2.03841, cy2: 8.25105, x: 2.03841, y: 8.58763 },
61
+ { op: "C", cx1: 2.03841, cy1: 8.79736, cx2: 1.93594, cy2: 8.99731, x: 1.736, y: 9.19226 },
62
+ { op: "C", cx1: 1.53606, cy1: 9.39222, cx2: 1.32153, cy2: 9.48971, x: 1.09721, y: 9.48971 },
63
+ { op: "C", cx1: 0.81936, cy1: 9.48971, cx2: 0.57548, cy2: 9.41181, x: 0.37553, y: 9.25081 },
64
+ { op: "C", cx1: 0.17558, cy1: 9.08978, cx2: 0.07811, cy2: 8.85588, x: 0.07811, y: 8.54849 },
65
+ { op: "L", x: 0.07812, y: 8.54848 },
66
+ { op: "Z" },
67
+ { op: "M", x: 8.3098, y: 5.11547 },
68
+ { op: "C", cx1: 8.3098, cy1: 4.7789, cx2: 8.4023, cy2: 4.51564, x: 8.58285, y: 4.33027 },
69
+ { op: "C", cx1: 8.76803, cy1: 4.14508, cx2: 9.00212, cy2: 4.05242, x: 9.28995, y: 4.05242 },
70
+ { op: "C", cx1: 9.57758, cy1: 4.05242, cx2: 9.82145, cy2: 4.14011, x: 10.01644, y: 4.31568 },
71
+ { op: "C", cx1: 10.21158, cy1: 4.48627, cx2: 10.30902, cy2: 4.73994, x: 10.30902, y: 5.07152 },
72
+ { op: "C", cx1: 10.30902, cy1: 5.30083, cx2: 10.20677, cy2: 5.51036, x: 10.00184, y: 5.69572 },
73
+ { op: "C", cx1: 9.7971, cy1: 5.88108, cx2: 9.57279, cy2: 5.97376, x: 9.32892, y: 5.97376 },
74
+ { op: "C", cx1: 9.07043, cy1: 5.97376, cx2: 8.83156, cy2: 5.88587, x: 8.62182, y: 5.71529 },
75
+ { op: "C", cx1: 8.41209, cy1: 5.53971, cx2: 8.3098, cy2: 5.33977, x: 8.3098, y: 5.11546 },
76
+ { op: "L", x: 8.3098, y: 5.11547 },
77
+ { op: "Z" },
78
+ ],
79
+ style: { fill: "#000" },
80
+ },
81
+ ],
82
+ };
@@ -14,8 +14,6 @@ export const trSymbol = {
14
14
  { op: "C", cx1: 1.30118, cy1: 5.68954, cx2: 1.61988, cy2: 5.79586, x: 1.95843, y: 5.79586 },
15
15
  { op: "C", cx1: 1.9916, cy1: 5.79586, cx2: 2.03157, cy2: 5.8157, x: 2.06475, y: 5.84888 },
16
16
  { op: "C", cx1: 2.24394, cy1: 5.82904, cx2: 2.61568, cy2: 5.69632, x: 3.17992, y: 5.46383 },
17
- { op: "L", x: 3.17992, y: 5.46383 },
18
- { op: "L", x: 3.17992, y: 5.46383 },
19
17
  { op: "Z" },
20
18
  { op: "M", x: 6.579, y: 9.87204 },
21
19
  { op: "L", x: 8.40472, y: 3.75096 },
@@ -55,7 +53,6 @@ export const trSymbol = {
55
53
  { op: "C", cx1: 10.01808, cy1: 5.11195, cx2: 9.77253, cy2: 5.69632, x: 9.57321, y: 6.36662 },
56
54
  { op: "L", x: 8.45798, y: 9.87203 },
57
55
  { op: "L", x: 6.57899, y: 9.87203 },
58
- { op: "L", x: 6.57899, y: 9.87203 },
59
56
  { op: "L", x: 6.579, y: 9.87204 },
60
57
  { op: "Z" },
61
58
  { op: "M", x: 5.05893, y: 5.62971 },
@@ -64,7 +61,6 @@ export const trSymbol = {
64
61
  { op: "C", cx1: 3.89045, cy1: 9.48047, cx2: 4.06285, cy2: 9.65287, x: 4.40821, y: 9.70617 },
65
62
  { op: "C", cx1: 5.404, cy1: 9.22134, cx2: 5.9019, cy2: 8.51787, x: 5.9019, y: 7.58841 },
66
63
  { op: "C", cx1: 5.9019, cy1: 6.99751, cx2: 5.62318, cy2: 6.34681, x: 5.05893, y: 5.62972 },
67
- { op: "L", x: 5.05893, y: 5.62972 },
68
64
  { op: "L", x: 5.05893, y: 5.62971 },
69
65
  { op: "Z" },
70
66
  ],
@@ -1,4 +1,4 @@
1
- import { TemporalNodeBase } from "../../lowering/types.js";
1
+ import { TemporalNodeBase } from "../temporal.js";
2
2
  import { ASTFunctionNode } from "../ASTtypes.js";
3
3
  import { prepareQuarterNote } from "./glyph.js";
4
4
  class TempoFunction extends ASTFunctionNode {
@@ -25,16 +25,18 @@ class TempoFunction extends ASTFunctionNode {
25
25
  };
26
26
  bpm;
27
27
  size;
28
+ font;
28
29
  constructor(sourceSpan, args, ctx, parent = null) {
29
30
  super(sourceSpan, parent);
30
31
  const [bpm, size] = this.getArgValue(args, ctx);
31
32
  this.bpm = bpm;
32
33
  this.size = ctx.length2px(size);
34
+ this.font = ctx.variables.font;
33
35
  }
34
36
  loweringEnter() {
35
37
  return [new TempoTemporalNode(this)];
36
38
  }
37
- toString() { return `@tempo(${this.bpm})`; }
39
+ toString() { return `@tempo(${this.bpm}, size=${this.size}px)`; }
38
40
  }
39
41
  export const TempoNode = TempoFunction;
40
42
  class TempoTemporalNode extends TemporalNodeBase {
@@ -50,7 +52,7 @@ class TempoTemporalNode extends TemporalNodeBase {
50
52
  this.ast = ast;
51
53
  this.glyph = prepareQuarterNote(ast.size);
52
54
  this.text = `= ${ast.bpm}`;
53
- this.style = { fontSize: ast.size, fill: "#000" };
55
+ this.style = { fontSize: ast.size, fontFamily: ast.font, fill: "#000" };
54
56
  // 非法值不入时间状态,也不告知播放系统,效果是保持上一个速度
55
57
  if (Number.isFinite(ast.bpm) && ast.bpm > 0)
56
58
  this.playbackState = { bpm: ast.bpm };
@@ -0,0 +1,138 @@
1
+ /**
2
+ * 时间线事件的基类
3
+ * 由 AST 产生,跨越 lowering / layout / playback 三个阶段
4
+ */
5
+ import type { ASTNodeBase } from "./ASTtypes.js";
6
+ import { Fraction } from "../fraction.js";
7
+ import type { HorizontalSpringConfig, LayoutBox, LayoutDecoration, LayoutHost, LayoutPoint, LayoutPrepareContext, HorizontalLineView, TimeLineEvent } from "../layout/types.js";
8
+ import type { Track } from "../lowering/track.js";
9
+ import type { PlaybackEmitter, PlaybackState } from "../playback/types.js";
10
+ import type { Painter } from "../render/types.js";
11
+ /**
12
+ * 沿记谱顺序流动的时间状态
13
+ *
14
+ * 速度、力度、调性、音色是系统级字段:有确定的类型和初值,任何时刻都能直接读,不用写兼容分支。
15
+ * 其余键由具体函数自行约定,核心不认识。
16
+ *
17
+ * velocity 和 program 按音轨各自流动,新音轨继承分叉处父轨的值;其余键整篇共享。
18
+ */
19
+ export interface TimeState {
20
+ bpm: number;
21
+ velocity: number;
22
+ keySignature: string;
23
+ program: number;
24
+ [key: string]: any;
25
+ }
26
+ export declare const DEFAULT_BPM = 120;
27
+ export declare const DEFAULT_VELOCITY = 80;
28
+ export declare const DEFAULT_TONALITY = "C4";
29
+ export declare const DEFAULT_PROGRAM = 0;
30
+ /**
31
+ * 事件的合并组:同一时刻 mergeKey 相等的事件归并成一列
32
+ *
33
+ * 缺省取事件自身的 order,因而互不相等、各自独占一列;需要合并的显式取相同的值。
34
+ * 数值同时决定同时刻的列先后,越小越靠左。已占用的共享常量:-1 br,-2 声部名
35
+ */
36
+ /** 时间对齐点(小节线);必须是最小值,最先出队 */
37
+ export declare const ANCHOR_KEY: number;
38
+ /** 普通事件的公共组 */
39
+ export declare const DEFAULT_KEY: number;
40
+ /**
41
+ * 时间线事件
42
+ *
43
+ * 由 AST 节点在 lowering 阶段产生,负责得到时间、设置布局参数
44
+ */
45
+ export declare class TemporalNodeBase implements TimeLineEvent {
46
+ readonly t: Fraction;
47
+ readonly T: Fraction;
48
+ track: Track;
49
+ ast: ASTNodeBase;
50
+ order: number;
51
+ addon?: Record<string, any>;
52
+ /**
53
+ * 时间列合并组:同一时刻 mergeKey 相等的事件归并成一列
54
+ *
55
+ * 缺省取事件自身的 order,因而互不相等、各自独占一列;需要合并的显式取相同的值。
56
+ * 数值同时决定同时刻的列先后,越小越靠左。已占用的共享常量:-1 br,-2 声部名
57
+ */
58
+ mergeKey: number;
59
+ /**
60
+ * 被折叠进哪个宿主的盒子(由宿主自己设置)
61
+ *
62
+ * 折叠成员不进入全局 columns,在时间流里没有独立位置,
63
+ * 按全局事件工作的消费者可以沿链上溯到宿主。
64
+ */
65
+ foldedInto?: TemporalNodeBase;
66
+ /** 请求在自己所在时间列之前换几行,默认 0 */
67
+ breakBefore: number;
68
+ /** 由 LoweringContext 在列归并后固化的谱面行号 */
69
+ layoutLine: number;
70
+ /** 不可见状态事件保持 undefined */
71
+ box?: LayoutBox;
72
+ /**
73
+ * 横向弹簧布局参数
74
+ * 大部分对象使用空对象即可采用布局器默认值
75
+ */
76
+ springConfig: HorizontalSpringConfig;
77
+ /**
78
+ * 关系函数可使用的命名局部坐标
79
+ * prepareLayout 每次执行时由具体节点和装饰函数重新生成
80
+ */
81
+ ports: Record<string, LayoutPoint>;
82
+ /**
83
+ * 当前一次 layout 已经实例化并完成测量的装饰对象
84
+ *
85
+ * 起因:addon 只保存 lowering 阶段冻结的语义值,例如 `@div: 2`,它没有字号、局部坐标,也不能表达 note 自身生成的下八度点。
86
+ * 布局需要把这些语义统一转换成可排序、可占高、可绘制的 LayoutDecoration 实例。
87
+ *
88
+ * 生命周期:
89
+ * 1. layout 的 prepareLayoutHost 开始时创建或清空数组;
90
+ * 2. Temporal.prepareLayout 可先加入节点自身的装饰,例如下八度点;
91
+ * 3. 引擎再通过 addon 对应的 layoutDecorationHandler 加入函数装饰;
92
+ * 4. arrangeBelowDecorations 按 below.order 分配主体下方空间并调用 below.place;
93
+ * 5. 最终 paintLayout 在主体 paint 后依次调用 decoration.paint。
94
+ *
95
+ * 数组必须保留到绘制结束,因为 decoration 通常以闭包保存本次测量得到的几何。它只属于当前 layout pass,不能跨 pass 复用。
96
+ * prepare 阶段生成、place 后冻结、paint 后失效
97
+ */
98
+ decorations: LayoutDecoration[];
99
+ /**
100
+ * 创建并返回当前事件唯一的 LayoutBox
101
+ * 可见子类应在构造函数中调用一次(或自行填写)
102
+ */
103
+ protected initLayoutBox(): LayoutBox;
104
+ /**
105
+ * 时间状态 修改&冻结 入口
106
+ * 调用时机在时间位置已经确定之后,处理“调性、速度、拍号”等时间信息的固化
107
+ */
108
+ onTimeState?(state: TimeState): void;
109
+ /** 把已固化的音乐语义声明为播放事件;不执行实时播放 */
110
+ emitPlayback?(emitter: PlaybackEmitter): void;
111
+ /** 给自己所在的时间列贴播放标记,供控制流游标查询 */
112
+ playbackMarks?(): readonly string[];
113
+ /** 向播放系统告知自己这个记谱位置上的速度与力度 */
114
+ playbackState?: PlaybackState;
115
+ /**
116
+ * 根据已经固化的语义生成固有尺寸
117
+ * 一般为测量函数自有图形或使用 LayoutPrepareContext.textMeasurer 测量文本,填写 box.w/h/anchor/visualAxis
118
+ * 此时 x 和 y 仍然没有最终含义
119
+ */
120
+ prepareLayout(_ctx: LayoutPrepareContext): void;
121
+ /** 横向拓扑建立后调整弹簧参数或注册横向布局 hook */
122
+ prepareHorizontal?(_line: HorizontalLineView): void;
123
+ /**
124
+ * 得到了最终的 box 后被调用(和 prepareLayout 之间隔了 decoration 的布局计算)
125
+ * 可在这里发布依赖最终 box.w/box.h 的端口
126
+ */
127
+ finalizeLayout?(_ctx: LayoutPrepareContext): void;
128
+ /**
129
+ * 布局器每次改变 x 或 y 后调用
130
+ * 普通叶节点不需要处理,具有内部几何的复合节点可用它同步子对象坐标
131
+ */
132
+ onPlaced?(): void;
133
+ /** 只执行绘制,不允许在这里重新测量或改变 LayoutBox */
134
+ paint(_painter: Painter): void;
135
+ }
136
+ /** 可以进入视觉布局的 Temporal,同时满足 decoration 所需的 LayoutHost 协议 */
137
+ export type VisualTemporalNode = TemporalNodeBase & LayoutHost;
138
+ export declare function isVisualTemporalNode(node: TemporalNodeBase): node is VisualTemporalNode;
@@ -0,0 +1,101 @@
1
+ import { Fraction } from "../fraction.js";
2
+ export const DEFAULT_BPM = 120;
3
+ export const DEFAULT_VELOCITY = 80;
4
+ export const DEFAULT_TONALITY = "C4";
5
+ export const DEFAULT_PROGRAM = 0;
6
+ /**
7
+ * 事件的合并组:同一时刻 mergeKey 相等的事件归并成一列
8
+ *
9
+ * 缺省取事件自身的 order,因而互不相等、各自独占一列;需要合并的显式取相同的值。
10
+ * 数值同时决定同时刻的列先后,越小越靠左。已占用的共享常量:-1 br,-2 声部名
11
+ */
12
+ /** 时间对齐点(小节线);必须是最小值,最先出队 */
13
+ export const ANCHOR_KEY = -Infinity;
14
+ /** 普通事件的公共组 */
15
+ export const DEFAULT_KEY = Infinity;
16
+ /**
17
+ * 时间线事件
18
+ *
19
+ * 由 AST 节点在 lowering 阶段产生,负责得到时间、设置布局参数
20
+ */
21
+ export class TemporalNodeBase {
22
+ // 下面这批字段统一由 LoweringContext.initEvent 原地补全
23
+ // 横向 layout 要用的三个属性
24
+ t = new Fraction(); // 事件发生的时间点
25
+ T = new Fraction(); // 事件的持续时间
26
+ track; // 所在的纵向音轨;同轨判断使用引用相等
27
+ ast; // 对应的 AST 节点
28
+ order; // 事件创建序号,作为id。可用于区分同时发生的父子、排序同一时刻发生的事件
29
+ addon; // 其他任意字段,仅在存在已固化的函数语义时创建,比如存储 div 和 dot 的数目
30
+ /**
31
+ * 时间列合并组:同一时刻 mergeKey 相等的事件归并成一列
32
+ *
33
+ * 缺省取事件自身的 order,因而互不相等、各自独占一列;需要合并的显式取相同的值。
34
+ * 数值同时决定同时刻的列先后,越小越靠左。已占用的共享常量:-1 br,-2 声部名
35
+ */
36
+ mergeKey;
37
+ /**
38
+ * 被折叠进哪个宿主的盒子(由宿主自己设置)
39
+ *
40
+ * 折叠成员不进入全局 columns,在时间流里没有独立位置,
41
+ * 按全局事件工作的消费者可以沿链上溯到宿主。
42
+ */
43
+ foldedInto;
44
+ /** 请求在自己所在时间列之前换几行,默认 0 */
45
+ breakBefore = 0;
46
+ /** 由 LoweringContext 在列归并后固化的谱面行号 */
47
+ layoutLine = 0;
48
+ /** 不可见状态事件保持 undefined */
49
+ box;
50
+ /**
51
+ * 横向弹簧布局参数
52
+ * 大部分对象使用空对象即可采用布局器默认值
53
+ */
54
+ springConfig;
55
+ /**
56
+ * 关系函数可使用的命名局部坐标
57
+ * prepareLayout 每次执行时由具体节点和装饰函数重新生成
58
+ */
59
+ ports;
60
+ /**
61
+ * 当前一次 layout 已经实例化并完成测量的装饰对象
62
+ *
63
+ * 起因:addon 只保存 lowering 阶段冻结的语义值,例如 `@div: 2`,它没有字号、局部坐标,也不能表达 note 自身生成的下八度点。
64
+ * 布局需要把这些语义统一转换成可排序、可占高、可绘制的 LayoutDecoration 实例。
65
+ *
66
+ * 生命周期:
67
+ * 1. layout 的 prepareLayoutHost 开始时创建或清空数组;
68
+ * 2. Temporal.prepareLayout 可先加入节点自身的装饰,例如下八度点;
69
+ * 3. 引擎再通过 addon 对应的 layoutDecorationHandler 加入函数装饰;
70
+ * 4. arrangeBelowDecorations 按 below.order 分配主体下方空间并调用 below.place;
71
+ * 5. 最终 paintLayout 在主体 paint 后依次调用 decoration.paint。
72
+ *
73
+ * 数组必须保留到绘制结束,因为 decoration 通常以闭包保存本次测量得到的几何。它只属于当前 layout pass,不能跨 pass 复用。
74
+ * prepare 阶段生成、place 后冻结、paint 后失效
75
+ */
76
+ decorations;
77
+ /**
78
+ * 创建并返回当前事件唯一的 LayoutBox
79
+ * 可见子类应在构造函数中调用一次(或自行填写)
80
+ */
81
+ initLayoutBox() {
82
+ return this.box = {
83
+ x: 0, y: 0,
84
+ w: 0, h: 0,
85
+ anchor: 0, visualAxis: 0,
86
+ };
87
+ }
88
+ /** 向播放系统告知自己这个记谱位置上的速度与力度 */
89
+ playbackState;
90
+ /**
91
+ * 根据已经固化的语义生成固有尺寸
92
+ * 一般为测量函数自有图形或使用 LayoutPrepareContext.textMeasurer 测量文本,填写 box.w/h/anchor/visualAxis
93
+ * 此时 x 和 y 仍然没有最终含义
94
+ */
95
+ prepareLayout(_ctx) { }
96
+ /** 只执行绘制,不允许在这里重新测量或改变 LayoutBox */
97
+ paint(_painter) { }
98
+ }
99
+ export function isVisualTemporalNode(node) {
100
+ return node.box !== undefined;
101
+ }
@@ -1,7 +1,7 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
2
  import { ErrorDiagnostic } from "../../diagnostic.js";
3
- import { findClosingQuote, removeQuote } from "../../parser/parse-utils/string-utils.js";
4
- import { DEFAULT_KEY, TemporalNodeBase } from "../../lowering/types.js";
3
+ import { findClosingQuote, quote, removeQuote } from "../../parser/parse-utils/string-utils.js";
4
+ import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
5
5
  class TextFunction extends ASTFunctionNode {
6
6
  static def = {
7
7
  name: ["text"],
@@ -18,7 +18,7 @@ class TextFunction extends ASTFunctionNode {
18
18
  name: "size",
19
19
  type: "length",
20
20
  default: {
21
- value: 1,
21
+ value: 0.8, // 常用于标记,默认小一些
22
22
  unit: "em",
23
23
  },
24
24
  },
@@ -31,7 +31,12 @@ class TextFunction extends ASTFunctionNode {
31
31
  name: "align",
32
32
  type: "string",
33
33
  default: "left",
34
- }
34
+ },
35
+ {
36
+ name: "font",
37
+ type: "string",
38
+ default: ""
39
+ },
35
40
  ],
36
41
  };
37
42
  static deSugarAtom(source, start, end) {
@@ -54,9 +59,11 @@ class TextFunction extends ASTFunctionNode {
54
59
  size;
55
60
  lineAdvance;
56
61
  align;
62
+ font;
57
63
  constructor(sourceSpan, args, ctx, parent = null) {
58
64
  super(sourceSpan, parent);
59
- const [text, size, lineHeight, align] = this.getArgValue(args, ctx);
65
+ const [text, size, lineHeight, align, font] = this.getArgValue(args, ctx);
66
+ this.font = font || ctx.variables.font;
60
67
  if (align !== "left" && align !== "center" && align !== "right") {
61
68
  throw new ErrorDiagnostic("E_TEXT_INVALID_ALIGN", "@text 的 align 参数必须是 'left'、'center' 或 'right'", sourceSpan);
62
69
  }
@@ -68,7 +75,7 @@ class TextFunction extends ASTFunctionNode {
68
75
  loweringEnter() { return [new TextTemporalNode(this)]; }
69
76
  toString() {
70
77
  const lineHeight = this.size === 0 ? 1.25 : this.lineAdvance / this.size;
71
- return `@text(${JSON.stringify(this.lines.join("\n"))}, size=${this.size}px, lineheight=${lineHeight}, align=${this.align})`;
78
+ return `@text(${quote(this.lines.join("\n"))}, size=${this.size}px, lineheight=${lineHeight}, align=${this.align}, font=${quote(this.font)})`;
72
79
  }
73
80
  }
74
81
  export const TextNode = TextFunction;
@@ -79,7 +86,7 @@ class TextTemporalNode extends TemporalNodeBase {
79
86
  super();
80
87
  this.ast = ast;
81
88
  this.mergeKey = DEFAULT_KEY;
82
- this.style = { fontSize: ast.size, fill: "#000", textAlign: ast.align };
89
+ this.style = { fontSize: ast.size, fontFamily: ast.font, fill: "#000", textAlign: ast.align };
83
90
  this.initLayoutBox();
84
91
  }
85
92
  prepareLayout(context) {