@r_masseater/fumx 0.0.0-stage → 0.1.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 (66) hide show
  1. package/LICENSE +87 -0
  2. package/README.md +124 -2
  3. package/dist/analysis-BAPm6c9P.d.mts +75 -0
  4. package/dist/analysis-CRyaJD5D.mjs +294 -0
  5. package/dist/analysis-CRyaJD5D.mjs.map +1 -0
  6. package/dist/analysis.d.mts +3 -0
  7. package/dist/analysis.mjs +3 -0
  8. package/dist/cli-D2DptmOG.mjs +2506 -0
  9. package/dist/cli-D2DptmOG.mjs.map +1 -0
  10. package/dist/convert-als.d.mts +17 -0
  11. package/dist/convert-als.mjs +512 -0
  12. package/dist/convert-als.mjs.map +1 -0
  13. package/dist/convert-midi.d.mts +17 -0
  14. package/dist/convert-midi.mjs +273 -0
  15. package/dist/convert-midi.mjs.map +1 -0
  16. package/dist/fumx.mjs +9 -0
  17. package/dist/fumx.mjs.map +1 -0
  18. package/dist/grammar-Ds8M-PkG.mjs +9836 -0
  19. package/dist/grammar-Ds8M-PkG.mjs.map +1 -0
  20. package/dist/habits.d.mts +71 -0
  21. package/dist/habits.mjs +98 -0
  22. package/dist/habits.mjs.map +1 -0
  23. package/dist/index-Bc9UT9HF.d.mts +795 -0
  24. package/dist/index-C7av_aK1.d.mts +104 -0
  25. package/dist/index-DOfjU43D.d.mts +71 -0
  26. package/dist/index-KxUilka8.d.mts +6 -0
  27. package/dist/index.d.mts +5 -0
  28. package/dist/index.mjs +4 -0
  29. package/dist/lint-Bnl4l0aI.mjs +296 -0
  30. package/dist/lint-Bnl4l0aI.mjs.map +1 -0
  31. package/dist/lint-CJ5lq-Fr.d.mts +37 -0
  32. package/dist/lint.d.mts +3 -0
  33. package/dist/lint.mjs +1 -0
  34. package/dist/mapper.mjs +14 -0
  35. package/dist/mapper.mjs.map +1 -0
  36. package/dist/mix-facts-QCYCXdIA.mjs +7006 -0
  37. package/dist/mix-facts-QCYCXdIA.mjs.map +1 -0
  38. package/dist/presets.d.mts +35 -0
  39. package/dist/presets.mjs +814 -0
  40. package/dist/presets.mjs.map +1 -0
  41. package/dist/read-song-B9342KUK.mjs +13017 -0
  42. package/dist/read-song-B9342KUK.mjs.map +1 -0
  43. package/dist/read-song-CsW4kd7v.d.mts +1326 -0
  44. package/dist/read-song-DW8MLsln.mjs +2783 -0
  45. package/dist/read-song-DW8MLsln.mjs.map +1 -0
  46. package/dist/song-BlIPWk7b.mjs +387 -0
  47. package/dist/song-BlIPWk7b.mjs.map +1 -0
  48. package/dist/song-UZ4T_dj9.d.mts +1477 -0
  49. package/dist/sounding-BCyExbPp.d.mts +20 -0
  50. package/dist/sounding-DYDZFp4e.mjs +41 -0
  51. package/dist/sounding-DYDZFp4e.mjs.map +1 -0
  52. package/dist/style-rules-CjaZTDt_.d.mts +131 -0
  53. package/dist/ticks-D6yACwHt.mjs +26 -0
  54. package/dist/ticks-D6yACwHt.mjs.map +1 -0
  55. package/dist/transform-CeFBPHqb.mjs +108 -0
  56. package/dist/transform-CeFBPHqb.mjs.map +1 -0
  57. package/dist/vite.d.mts +8 -0
  58. package/dist/vite.mjs +127 -0
  59. package/dist/vite.mjs.map +1 -0
  60. package/dist/write-CHtCd-bG.mjs +747 -0
  61. package/dist/write-CHtCd-bG.mjs.map +1 -0
  62. package/package.json +118 -3
  63. package/skills/lint-songs/SKILL.md +54 -0
  64. package/skills/read-fumx/SKILL.md +89 -0
  65. package/skills/use-fumx-tools/SKILL.md +69 -0
  66. package/skills/use-lint-presets/SKILL.md +72 -0
@@ -0,0 +1,20 @@
1
+ import { Option } from "effect";
2
+ import "./index-Bc9UT9HF.mjs";
3
+ import { d as Song, u as Role } from "./song-UZ4T_dj9.mjs";
4
+ interface Span {
5
+ readonly start: number;
6
+ readonly end: number;
7
+ }
8
+ interface Sounding extends Span {
9
+ readonly track: string;
10
+ readonly line: number;
11
+ readonly column: number;
12
+ readonly bar: number;
13
+ readonly role: Option.Option<Role>;
14
+ readonly midi: number;
15
+ readonly spelling: string;
16
+ readonly pitchClass: string;
17
+ }
18
+ declare const overlapOf: (left: Span) => (right: Span) => number;
19
+ declare const soundingsOf: (song: Song) => readonly Sounding[];
20
+ export { soundingsOf as i, Span as n, overlapOf as r, Sounding as t };
@@ -0,0 +1,41 @@
1
+ import { Array, Option, String, pipe } from "effect";
2
+ import { Note } from "tonal";
3
+ import { n as fractionOf } from "./ticks-D6yACwHt.mjs";
4
+ // src/features/analyze-song/model/sounding.ts
5
+ const NONE = 0;
6
+ const FIRST = 1;
7
+ const CENTS = /[+-]\d+c$/u;
8
+ const pitchClassOf = (note) => {
9
+ const written = Note.pitchClass(String.replace(CENTS, "")(note.spelling));
10
+ if (String.isNonEmpty(written)) return written;
11
+ return Note.pitchClass(Note.fromMidi(note.midi));
12
+ };
13
+ const overlapOf = (left) => (right) => Math.max(NONE, Math.min(left.end, right.end) - Math.max(left.start, right.start));
14
+ const soundingsOf = (song) => {
15
+ const audible = pipe(song.tracks, Array.filter((track) => !track.mixer.muted));
16
+ return pipe(song.notes, Array.flatMap((note) => pipe(audible, Array.findFirst((track) => track.name === note.track), Option.map((track) => ({
17
+ track: note.track,
18
+ line: note.sourceLine,
19
+ column: note.sourceColumn,
20
+ bar: note.bar,
21
+ role: track.role,
22
+ midi: note.midi,
23
+ spelling: note.spelling,
24
+ pitchClass: pitchClassOf(note),
25
+ start: note.start,
26
+ end: note.start + Math.round(note.length * note.gate)
27
+ })), Option.toArray)));
28
+ };
29
+ const positionOf = (song) => (tick) => pipe(song.bars, Array.findLast((bar) => bar.start <= tick), Option.match({
30
+ onNone: () => ({
31
+ bar: FIRST,
32
+ offset: fractionOf(tick)
33
+ }),
34
+ onSome: (bar) => ({
35
+ bar: bar.index,
36
+ offset: fractionOf(tick - bar.start)
37
+ })
38
+ }));
39
+ export { positionOf as n, soundingsOf as r, overlapOf as t };
40
+
41
+ //# sourceMappingURL=sounding-DYDZFp4e.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sounding-DYDZFp4e.mjs","names":["TonalNote","Str","Arr"],"sources":["../src/features/analyze-song/model/sounding.ts"],"sourcesContent":["import { Array as Arr, Option, String as Str, pipe } from \"effect\";\nimport { Note as TonalNote } from \"tonal\";\n\nimport type { Note, Role, Song } from \"#/entities/song/index.ts\";\nimport { fractionOf } from \"#/shared/lib/ticks.ts\";\n\nconst NONE = 0;\nconst FIRST = 1;\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\nexport interface Sounding extends Span {\n readonly track: string;\n readonly line: number;\n readonly column: number;\n readonly bar: number;\n readonly role: Option.Option<Role>;\n readonly midi: number;\n readonly spelling: string;\n readonly pitchClass: string;\n}\n\nconst CENTS = /[+-]\\d+c$/u;\n\nconst pitchClassOf = (note: Note): string => {\n const written = TonalNote.pitchClass(Str.replace(CENTS, \"\")(note.spelling));\n if (Str.isNonEmpty(written)) {\n return written;\n }\n return TonalNote.pitchClass(TonalNote.fromMidi(note.midi));\n};\n\nexport const overlapOf =\n (left: Span) =>\n (right: Span): number =>\n Math.max(NONE, Math.min(left.end, right.end) - Math.max(left.start, right.start));\n\nexport const soundingsOf = (song: Song): readonly Sounding[] => {\n const audible = pipe(\n song.tracks,\n Arr.filter((track) => !track.mixer.muted),\n );\n return pipe(\n song.notes,\n Arr.flatMap((note) =>\n pipe(\n audible,\n Arr.findFirst((track) => track.name === note.track),\n Option.map((track) => ({\n track: note.track,\n line: note.sourceLine,\n column: note.sourceColumn,\n bar: note.bar,\n role: track.role,\n midi: note.midi,\n spelling: note.spelling,\n pitchClass: pitchClassOf(note),\n start: note.start,\n end: note.start + Math.round(note.length * note.gate),\n })),\n Option.toArray,\n ),\n ),\n );\n};\n\nexport const positionOf =\n (song: Song) =>\n (tick: number): { readonly bar: number; readonly offset: string } =>\n pipe(\n song.bars,\n Arr.findLast((bar) => bar.start <= tick),\n Option.match({\n onNone: () => ({ bar: FIRST, offset: fractionOf(tick) }),\n onSome: (bar) => ({ bar: bar.index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
1
+ import "./analysis-BAPm6c9P.mjs";
2
+ import "./index-KxUilka8.mjs";
3
+ import { Schema } from "effect";
4
+ interface Step {
5
+ readonly token: string;
6
+ readonly bar: number;
7
+ readonly line: number;
8
+ readonly column: number;
9
+ }
10
+ declare const StyleTableSchema: Schema.Struct<{
11
+ readonly name: Schema.String;
12
+ readonly source: Schema.String;
13
+ readonly order: Schema.Int;
14
+ readonly transitions: Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Int>>;
15
+ }>;
16
+ type StyleTable = typeof StyleTableSchema.Type;
17
+ type Transitions = StyleTable["transitions"];
18
+ declare const MixHabitSchema: Schema.Union<readonly [Schema.Struct<{
19
+ readonly type: Schema.Literal<"move">;
20
+ readonly track: Schema.String;
21
+ readonly parameter: Schema.Literals<readonly ["volume", "pan"]>;
22
+ readonly direction: Schema.Literals<readonly ["up", "down"]>;
23
+ readonly edge: Schema.Literals<readonly ["before", "after"]>;
24
+ }>, Schema.Struct<{
25
+ readonly type: Schema.Literal<"level">;
26
+ readonly track: Schema.String;
27
+ readonly decibels: Schema.Finite;
28
+ }>, Schema.Struct<{
29
+ readonly type: Schema.Literal<"pan">;
30
+ readonly track: Schema.String;
31
+ readonly pan: Schema.Finite;
32
+ }>, Schema.Struct<{
33
+ readonly type: Schema.Literal<"send">;
34
+ readonly track: Schema.String;
35
+ readonly bus: Schema.String;
36
+ readonly amount: Schema.Finite;
37
+ }>]>;
38
+ type MixHabit = typeof MixHabitSchema.Type;
39
+ declare const mixKeyOf: (habit: MixHabit) => string;
40
+ declare const HABIT_KINDS: readonly ["keep", "fix", "suggest"];
41
+ type HabitKind = (typeof HABIT_KINDS)[number];
42
+ declare const SubjectSchema: Schema.Union<readonly [Schema.Struct<{
43
+ readonly type: Schema.Literal<"chord">;
44
+ readonly context: Schema.String;
45
+ readonly next: Schema.String;
46
+ }>, Schema.Union<readonly [Schema.Struct<{
47
+ readonly type: Schema.Literal<"move">;
48
+ readonly track: Schema.String;
49
+ readonly parameter: Schema.Literals<readonly ["volume", "pan"]>;
50
+ readonly direction: Schema.Literals<readonly ["up", "down"]>;
51
+ readonly edge: Schema.Literals<readonly ["before", "after"]>;
52
+ }>, Schema.Struct<{
53
+ readonly type: Schema.Literal<"level">;
54
+ readonly track: Schema.String;
55
+ readonly decibels: Schema.Finite;
56
+ }>, Schema.Struct<{
57
+ readonly type: Schema.Literal<"pan">;
58
+ readonly track: Schema.String;
59
+ readonly pan: Schema.Finite;
60
+ }>, Schema.Struct<{
61
+ readonly type: Schema.Literal<"send">;
62
+ readonly track: Schema.String;
63
+ readonly bus: Schema.String;
64
+ readonly amount: Schema.Finite;
65
+ }>]>]>;
66
+ type Subject = typeof SubjectSchema.Type;
67
+ declare const HabitRuleSchema: Schema.Struct<{
68
+ readonly habit: Schema.Union<readonly [Schema.Struct<{
69
+ readonly type: Schema.Literal<"chord">;
70
+ readonly context: Schema.String;
71
+ readonly next: Schema.String;
72
+ }>, Schema.Union<readonly [Schema.Struct<{
73
+ readonly type: Schema.Literal<"move">;
74
+ readonly track: Schema.String;
75
+ readonly parameter: Schema.Literals<readonly ["volume", "pan"]>;
76
+ readonly direction: Schema.Literals<readonly ["up", "down"]>;
77
+ readonly edge: Schema.Literals<readonly ["before", "after"]>;
78
+ }>, Schema.Struct<{
79
+ readonly type: Schema.Literal<"level">;
80
+ readonly track: Schema.String;
81
+ readonly decibels: Schema.Finite;
82
+ }>, Schema.Struct<{
83
+ readonly type: Schema.Literal<"pan">;
84
+ readonly track: Schema.String;
85
+ readonly pan: Schema.Finite;
86
+ }>, Schema.Struct<{
87
+ readonly type: Schema.Literal<"send">;
88
+ readonly track: Schema.String;
89
+ readonly bus: Schema.String;
90
+ readonly amount: Schema.Finite;
91
+ }>]>]>;
92
+ readonly kind: Schema.Literals<readonly ["keep", "fix", "suggest"]>;
93
+ readonly aim: Schema.String;
94
+ readonly reason: Schema.optionalKey<Schema.String>;
95
+ }>;
96
+ type HabitRule = typeof HabitRuleSchema.Type;
97
+ declare const StyleRulesSchema: Schema.Struct<{
98
+ readonly name: Schema.String;
99
+ readonly habits: Schema.$Array<Schema.Struct<{
100
+ readonly habit: Schema.Union<readonly [Schema.Struct<{
101
+ readonly type: Schema.Literal<"chord">;
102
+ readonly context: Schema.String;
103
+ readonly next: Schema.String;
104
+ }>, Schema.Union<readonly [Schema.Struct<{
105
+ readonly type: Schema.Literal<"move">;
106
+ readonly track: Schema.String;
107
+ readonly parameter: Schema.Literals<readonly ["volume", "pan"]>;
108
+ readonly direction: Schema.Literals<readonly ["up", "down"]>;
109
+ readonly edge: Schema.Literals<readonly ["before", "after"]>;
110
+ }>, Schema.Struct<{
111
+ readonly type: Schema.Literal<"level">;
112
+ readonly track: Schema.String;
113
+ readonly decibels: Schema.Finite;
114
+ }>, Schema.Struct<{
115
+ readonly type: Schema.Literal<"pan">;
116
+ readonly track: Schema.String;
117
+ readonly pan: Schema.Finite;
118
+ }>, Schema.Struct<{
119
+ readonly type: Schema.Literal<"send">;
120
+ readonly track: Schema.String;
121
+ readonly bus: Schema.String;
122
+ readonly amount: Schema.Finite;
123
+ }>]>]>;
124
+ readonly kind: Schema.Literals<readonly ["keep", "fix", "suggest"]>;
125
+ readonly aim: Schema.String;
126
+ readonly reason: Schema.optionalKey<Schema.String>;
127
+ }>>;
128
+ }>;
129
+ type StyleRules = typeof StyleRulesSchema.Type;
130
+ declare const subjectKeyOf: (subject: Subject) => string;
131
+ export { StyleRulesSchema as a, subjectKeyOf as c, StyleTable as d, StyleTableSchema as f, StyleRules as i, MixHabit as l, Step as m, HabitKind as n, Subject as o, Transitions as p, HabitRule as r, SubjectSchema as s, HABIT_KINDS as t, mixKeyOf as u };
@@ -0,0 +1,26 @@
1
+ import { groupsOf } from "@r_masseater/masseater-utils/text";
2
+ import { Option, pipe } from "effect";
3
+ // src/shared/lib/ticks.ts
4
+ const TICKS_PER_WHOLE = 129024e3;
5
+ const FRACTION = /^(?<numerator>\d+)\/(?<denominator>\d+)$/u;
6
+ const NONE = 0;
7
+ const gcdOf = (left, right) => {
8
+ if (right === NONE) return left;
9
+ return gcdOf(right, left % right);
10
+ };
11
+ const partsOf = (text) => pipe(groupsOf(FRACTION)(text), Option.flatMap(({ numerator, denominator }) => Option.all({
12
+ numerator: Option.fromNullishOr(numerator),
13
+ denominator: Option.fromNullishOr(denominator)
14
+ })), Option.map(({ numerator, denominator }) => ({
15
+ numerator: Number(numerator),
16
+ denominator: Number(denominator)
17
+ })), Option.filter(({ denominator }) => denominator > NONE));
18
+ const ticksOf = (text) => pipe(partsOf(text), Option.map(({ numerator, denominator }) => TICKS_PER_WHOLE * numerator / denominator), Option.filter(Number.isInteger));
19
+ const fractionOf = (ticks) => {
20
+ if (ticks === NONE) return "0";
21
+ const divisor = gcdOf(ticks, TICKS_PER_WHOLE);
22
+ return `${String(ticks / divisor)}/${String(TICKS_PER_WHOLE / divisor)}`;
23
+ };
24
+ export { ticksOf as i, fractionOf as n, partsOf as r, TICKS_PER_WHOLE as t };
25
+
26
+ //# sourceMappingURL=ticks-D6yACwHt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ticks-D6yACwHt.mjs","names":[],"sources":["../src/shared/lib/ticks.ts"],"sourcesContent":["import { groupsOf } from \"@r_masseater/masseater-utils/text\";\nimport { Option, pipe } from \"effect\";\n\nexport const TICKS_PER_WHOLE = 129_024_000;\n\nconst FRACTION = /^(?<numerator>\\d+)\\/(?<denominator>\\d+)$/u;\nconst NONE = 0;\n\nexport interface Fraction {\n readonly numerator: number;\n readonly denominator: number;\n}\n\nconst gcdOf = (left: number, right: number): number => {\n if (right === NONE) {\n return left;\n }\n return gcdOf(right, left % right);\n};\n\nexport const partsOf = (text: string): Option.Option<Fraction> =>\n pipe(\n groupsOf(FRACTION)(text),\n Option.flatMap(({ numerator, denominator }) =>\n Option.all({\n numerator: Option.fromNullishOr(numerator),\n denominator: Option.fromNullishOr(denominator),\n }),\n ),\n Option.map(({ numerator, denominator }) => ({\n numerator: Number(numerator),\n denominator: Number(denominator),\n })),\n Option.filter(({ denominator }) => denominator > NONE),\n );\n\nexport const ticksOf = (text: string): Option.Option<number> =>\n pipe(\n partsOf(text),\n Option.map(({ numerator, denominator }) => (TICKS_PER_WHOLE * numerator) / denominator),\n Option.filter(Number.isInteger),\n );\n\nexport const fractionOf = (ticks: number): string => {\n if (ticks === NONE) {\n return \"0\";\n }\n const divisor = gcdOf(ticks, TICKS_PER_WHOLE);\n return `${String(ticks / divisor)}/${String(TICKS_PER_WHOLE / divisor)}`;\n};\n"],"mappings":";;;AAGA,MAAa,kBAAkB;AAE/B,MAAM,WAAW;AACjB,MAAM,OAAO;AAOb,MAAM,SAAS,MAAc,UAA0B;CACrD,IAAI,UAAU,MACZ,OAAO;CAET,OAAO,MAAM,OAAO,OAAO,KAAK;AAClC;AAEA,MAAa,WAAW,SACtB,KACE,SAAS,QAAQ,CAAC,CAAC,IAAI,GACvB,OAAO,SAAS,EAAE,WAAW,kBAC3B,OAAO,IAAI;CACT,WAAW,OAAO,cAAc,SAAS;CACzC,aAAa,OAAO,cAAc,WAAW;AAC/C,CAAC,CACH,GACA,OAAO,KAAK,EAAE,WAAW,mBAAmB;CAC1C,WAAW,OAAO,SAAS;CAC3B,aAAa,OAAO,WAAW;AACjC,EAAE,GACF,OAAO,QAAQ,EAAE,kBAAkB,cAAc,IAAI,CACvD;AAEF,MAAa,WAAW,SACtB,KACE,QAAQ,IAAI,GACZ,OAAO,KAAK,EAAE,WAAW,kBAAmB,kBAAkB,YAAa,WAAW,GACtF,OAAO,OAAO,OAAO,SAAS,CAChC;AAEF,MAAa,cAAc,UAA0B;CACnD,IAAI,UAAU,MACZ,OAAO;CAET,MAAM,UAAU,MAAM,OAAO,eAAe;CAC5C,OAAO,GAAG,OAAO,QAAQ,OAAO,EAAE,GAAG,OAAO,kBAAkB,OAAO;AACvE"}
@@ -0,0 +1,108 @@
1
+ import { NodeFileSystem } from "@effect/platform-node-shared";
2
+ import { mappedOutput } from "@r_masseater/masseater-utils/mapped-import/mapper";
3
+ import { Array, Effect, FileSystem, ManagedRuntime, Option, Record, Schema, pipe } from "effect";
4
+ import { nameLiteral, quoted, text } from "@r_masseater/masseater-utils/mapped-import";
5
+ import { s as SongSchema, t as readSong } from "./read-song-B9342KUK.mjs";
6
+ // src/features/build-song-module/model/song-module.ts
7
+ const NAMED_FIELDS = {
8
+ samples: "Sample",
9
+ kits: "Kit",
10
+ instruments: "Instrument",
11
+ buses: "Bus",
12
+ tracks: "Track",
13
+ plugins: "Plugin"
14
+ };
15
+ const SONG_MODULE = "#/app/index.ts";
16
+ const NEVER_SONG = "export declare const song: never;\n";
17
+ const titleSegments = (song, outline) => Option.match(outline.title, {
18
+ onNone: () => [text(quoted(song.title))],
19
+ onSome: ({ start, end }) => [{
20
+ kind: "alias",
21
+ text: quoted(song.title),
22
+ start,
23
+ end
24
+ }]
25
+ });
26
+ const fieldSegments = (song, outline) => ([field, type]) => [
27
+ text(` readonly ${field}: readonly [\n`),
28
+ ...pipe(song[field], Array.flatMap(({ name }) => [
29
+ text(` Song["${field}"][number] & { readonly name: `),
30
+ ...nameLiteral({
31
+ name,
32
+ span: pipe(outline.names, Array.findFirst((found) => found.type === type && found.name === name), Option.map((found) => found.span))
33
+ }),
34
+ text(" },\n")
35
+ ])),
36
+ text(" ];\n")
37
+ ];
38
+ const segmentsOf = (song, outline) => [
39
+ text(`import type { Song } from "${SONG_MODULE}";\n`),
40
+ text("export declare const song: Song & {\n readonly title: "),
41
+ ...titleSegments(song, outline),
42
+ text(";\n"),
43
+ ...pipe(Record.toEntries(NAMED_FIELDS), Array.flatMap(fieldSegments(song, outline))),
44
+ text("};\n")
45
+ ];
46
+ const issueOf = ({ path, outline }) => (issue) => {
47
+ if (issue.path === path) return {
48
+ message: issue.message,
49
+ start: issue.start,
50
+ end: issue.end
51
+ };
52
+ const at = pipe(outline.imports, Array.findFirst((found) => found.path === issue.path), Option.map((found) => found.span), Option.getOrElse(() => ({
53
+ start: 0,
54
+ end: 0
55
+ })));
56
+ return {
57
+ message: `${issue.path}:${String(issue.line)}:${String(issue.column)} ${issue.message}`,
58
+ ...at
59
+ };
60
+ };
61
+ const moduleOf = (path) => (source) => {
62
+ if (source.status === "invalid") return {
63
+ mapped: {
64
+ status: "error",
65
+ fallback: NEVER_SONG,
66
+ issues: pipe(source.issues, Array.map(issueOf({
67
+ path,
68
+ outline: source.outline
69
+ })))
70
+ },
71
+ song: Option.none(),
72
+ files: source.outline.files
73
+ };
74
+ return {
75
+ mapped: {
76
+ status: "ok",
77
+ segments: segmentsOf(source.song, source.outline)
78
+ },
79
+ song: Option.some(source.song),
80
+ files: source.outline.files
81
+ };
82
+ };
83
+ const songModuleOf = ({ path, content, read }) => readSong({
84
+ path,
85
+ read: (target) => {
86
+ if (target === path) return Effect.succeed(content);
87
+ return read(target);
88
+ }
89
+ }).pipe(Effect.map(moduleOf(path)));
90
+ Schema.encodeEffect(Schema.fromJsonString(SongSchema));
91
+ // src/app/transform.ts
92
+ const transformSong = Effect.fn("transformSong")(function* transformSong(request) {
93
+ const fileSystem = yield* FileSystem.FileSystem;
94
+ const { mapped } = yield* songModuleOf({
95
+ path: request.fileName,
96
+ content: request.content,
97
+ read: (path) => fileSystem.readFileString(path)
98
+ });
99
+ return mappedOutput({
100
+ request,
101
+ mapped
102
+ });
103
+ });
104
+ const runtime = ManagedRuntime.make(NodeFileSystem.layer);
105
+ const transform = (request) => runtime.runPromise(transformSong(request));
106
+ export { transform };
107
+
108
+ //# sourceMappingURL=transform-CeFBPHqb.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-CeFBPHqb.mjs","names":["Arr","Rec"],"sources":["../src/features/build-song-module/model/song-module.ts","../src/app/transform.ts"],"sourcesContent":["import { nameLiteral, quoted, text } from \"@r_masseater/masseater-utils/mapped-import\";\nimport type { Segment } from \"@r_masseater/masseater-utils/mapped-import\";\nimport type { Issue, Mapped } from \"@r_masseater/masseater-utils/mapped-import/mapper\";\nimport { Array as Arr, Effect, Option, Record as Rec, Schema, pipe } from \"effect\";\n\nimport { SongSchema } from \"#/entities/song/index.ts\";\nimport type { Song } from \"#/entities/song/index.ts\";\nimport { readSong } from \"#/features/read-song/@x/build-song-module.ts\";\nimport type {\n Named,\n Outline,\n SongSource,\n SourceIssue,\n} from \"#/features/read-song/@x/build-song-module.ts\";\n\nexport interface SongModuleSource<Failure> {\n readonly path: string;\n readonly content: string;\n readonly read: (path: string) => Effect.Effect<string, Failure>;\n}\n\nexport interface SongModule {\n readonly mapped: Mapped;\n readonly song: Option.Option<Song>;\n readonly files: readonly string[];\n}\n\ntype NamedField = {\n readonly [Field in keyof Song]: Song[Field] extends readonly { readonly name: string }[]\n ? Field\n : never;\n}[keyof Song];\n\nconst NAMED_FIELDS = {\n samples: \"Sample\",\n kits: \"Kit\",\n instruments: \"Instrument\",\n buses: \"Bus\",\n tracks: \"Track\",\n plugins: \"Plugin\",\n} as const satisfies Readonly<Record<NamedField, Named[\"$type\"]>>;\n\nconst SONG_MODULE = \"#/app/index.ts\";\n\nconst NEVER_SONG = \"export declare const song: never;\\n\";\n\nconst titleSegments = (song: Song, outline: Outline): readonly Segment[] =>\n Option.match(outline.title, {\n onNone: () => [text(quoted(song.title))],\n onSome: ({ start, end }): readonly Segment[] => [\n { kind: \"alias\", text: quoted(song.title), start, end },\n ],\n });\n\nconst fieldSegments =\n (song: Song, outline: Outline) =>\n ([field, type]: readonly [NamedField, Named[\"$type\"]]): readonly Segment[] => [\n text(` readonly ${field}: readonly [\\n`),\n ...pipe(\n song[field],\n Arr.flatMap(({ name }) => [\n text(` Song[\"${field}\"][number] & { readonly name: `),\n ...nameLiteral({\n name,\n span: pipe(\n outline.names,\n Arr.findFirst((found) => found.type === type && found.name === name),\n Option.map((found) => found.span),\n ),\n }),\n text(\" },\\n\"),\n ]),\n ),\n text(\" ];\\n\"),\n ];\n\nconst segmentsOf = (song: Song, outline: Outline): readonly Segment[] => [\n text(`import type { Song } from \"${SONG_MODULE}\";\\n`),\n text(\"export declare const song: Song & {\\n readonly title: \"),\n ...titleSegments(song, outline),\n text(\";\\n\"),\n ...pipe(Rec.toEntries(NAMED_FIELDS), Arr.flatMap(fieldSegments(song, outline))),\n text(\"};\\n\"),\n];\n\nconst issueOf =\n ({ path, outline }: Readonly<{ path: string; outline: Outline }>) =>\n (issue: SourceIssue): Issue => {\n if (issue.path === path) {\n return { message: issue.message, start: issue.start, end: issue.end };\n }\n const at = pipe(\n outline.imports,\n Arr.findFirst((found) => found.path === issue.path),\n Option.map((found) => found.span),\n Option.getOrElse(() => ({ start: 0, end: 0 })),\n );\n return {\n message: `${issue.path}:${String(issue.line)}:${String(issue.column)} ${issue.message}`,\n ...at,\n };\n };\n\nconst moduleOf =\n (path: string) =>\n (source: SongSource): SongModule => {\n if (source.status === \"invalid\") {\n return {\n mapped: {\n status: \"error\",\n fallback: NEVER_SONG,\n issues: pipe(source.issues, Arr.map(issueOf({ path, outline: source.outline }))),\n },\n song: Option.none(),\n files: source.outline.files,\n };\n }\n return {\n mapped: { status: \"ok\", segments: segmentsOf(source.song, source.outline) },\n song: Option.some(source.song),\n files: source.outline.files,\n };\n };\n\nexport const songModuleOf = <Failure>({\n path,\n content,\n read,\n}: SongModuleSource<Failure>): Effect.Effect<SongModule> =>\n readSong({\n path,\n read: (target) => {\n if (target === path) {\n return Effect.succeed(content);\n }\n return read(target);\n },\n }).pipe(Effect.map(moduleOf(path)));\n\nconst encodeSong = Schema.encodeEffect(Schema.fromJsonString(SongSchema));\n\nexport const songCodeOf = (song: Song): Effect.Effect<string> =>\n encodeSong(song).pipe(\n Effect.orDie,\n Effect.map(\n (json) =>\n `import { Schema } from \"effect\";\\nimport { SongSchema } from \"${SONG_MODULE}\";\\nexport const song = Schema.decodeSync(Schema.fromJsonString(SongSchema))(${quoted(json)});\\n`,\n ),\n );\n","import { NodeFileSystem } from \"@effect/platform-node-shared\";\nimport { mappedOutput } from \"@r_masseater/masseater-utils/mapped-import/mapper\";\nimport type { Request } from \"@r_masseater/masseater-utils/mapped-import/mapper\";\nimport { Effect, FileSystem, ManagedRuntime } from \"effect\";\nimport type { TransformResult } from \"ts-content-mapper\";\n\nimport { songModuleOf } from \"#/features/build-song-module/index.ts\";\n\nconst transformSong = Effect.fn(\"transformSong\")(function* transformSong(request: Request) {\n const fileSystem = yield* FileSystem.FileSystem;\n const { mapped } = yield* songModuleOf({\n path: request.fileName,\n content: request.content,\n read: (path) => fileSystem.readFileString(path),\n });\n return mappedOutput({ request, mapped });\n});\n\nconst runtime = ManagedRuntime.make(NodeFileSystem.layer);\n\nexport const transform = (request: Request): Promise<TransformResult> =>\n runtime.runPromise(transformSong(request));\n"],"mappings":";;;;;;AAiCA,MAAM,eAAe;CACnB,SAAS;CACT,MAAM;CACN,aAAa;CACb,OAAO;CACP,QAAQ;CACR,SAAS;AACX;AAEA,MAAM,cAAc;AAEpB,MAAM,aAAa;AAEnB,MAAM,iBAAiB,MAAY,YACjC,OAAO,MAAM,QAAQ,OAAO;CAC1B,cAAc,CAAC,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC;CACvC,SAAS,EAAE,OAAO,UAA8B,CAC9C;EAAE,MAAM;EAAS,MAAM,OAAO,KAAK,KAAK;EAAG;EAAO;CAAI,CACxD;AACF,CAAC;AAEH,MAAM,iBACH,MAAY,aACZ,CAAC,OAAO,UAAqE;CAC5E,KAAK,cAAc,MAAM,eAAe;CACxC,GAAG,KACD,KAAK,QACLA,MAAI,SAAS,EAAE,WAAW;EACxB,KAAK,aAAa,MAAM,+BAA+B;EACvD,GAAG,YAAY;GACb;GACA,MAAM,KACJ,QAAQ,OACRA,MAAI,WAAW,UAAU,MAAM,SAAS,QAAQ,MAAM,SAAS,IAAI,GACnE,OAAO,KAAK,UAAU,MAAM,IAAI,CAClC;EACF,CAAC;EACD,KAAK,OAAO;CACd,CAAC,CACH;CACA,KAAK,QAAQ;AACf;AAEF,MAAM,cAAc,MAAY,YAAyC;CACvE,KAAK,8BAA8B,YAAY,KAAK;CACpD,KAAK,yDAAyD;CAC9D,GA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CAAC;AAEjB,OAAO,aAAa,OAAO,eAAe,UAAU,CAAC;;ACnIxE,MAAM,gBAAgB,OAAO,GAAG,eAAe,CAAC,CAAC,UAAU,cAAc,SAAkB;CACzF,MAAM,aAAa,OAAO,WAAW;CACrC,MAAM,EAAE,WAAW,OAAO,aAAa;EACrC,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB,OAAO,SAAS,WAAW,eAAe,IAAI;CAChD,CAAC;CACD,OAAO,aAAa;EAAE;EAAS;CAAO,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,eAAe,KAAK,eAAe,KAAK;AAExD,MAAa,aAAa,YACxB,QAAQ,WAAW,cAAc,OAAO,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Plugin } from "vite-plus";
2
+ import { o as FumxConfig } from "./index-DOfjU43D.mjs";
3
+ declare module "vite" {
4
+ interface UserConfig {
5
+ readonly fumx?: FumxConfig;
6
+ }
7
+ }
8
+ export declare const fumx: () => Plugin;
package/dist/vite.mjs ADDED
@@ -0,0 +1,127 @@
1
+ import { nameLiteral, quoted, renderSegments, text } from "@r_masseater/masseater-utils/mapped-import";
2
+ import { contentImport } from "@r_masseater/masseater-utils/mapped-import/vite";
3
+ import { Array, Effect, Match, Option, Record, Schema, pipe } from "effect";
4
+ import { n as SongSchema } from "./song-BlIPWk7b.mjs";
5
+ import { n as FumxLanguageMetaData, t as readSong } from "./read-song-DW8MLsln.mjs";
6
+ // src/features/build-song-module/model/song-module.ts
7
+ const NAMED_FIELDS = {
8
+ samples: "Sample",
9
+ kits: "Kit",
10
+ instruments: "Instrument",
11
+ buses: "Bus",
12
+ tracks: "Track",
13
+ plugins: "Plugin"
14
+ };
15
+ const SONG_MODULE = "#/app/index.ts";
16
+ const NEVER_SONG = "export declare const song: never;\n";
17
+ const titleSegments = (song, outline) => Option.match(outline.title, {
18
+ onNone: () => [text(quoted(song.title))],
19
+ onSome: ({ start, end }) => [{
20
+ kind: "alias",
21
+ text: quoted(song.title),
22
+ start,
23
+ end
24
+ }]
25
+ });
26
+ const fieldSegments = (song, outline) => ([field, type]) => [
27
+ text(` readonly ${field}: readonly [\n`),
28
+ ...pipe(song[field], Array.flatMap(({ name }) => [
29
+ text(` Song["${field}"][number] & { readonly name: `),
30
+ ...nameLiteral({
31
+ name,
32
+ span: pipe(outline.names, Array.findFirst((found) => found.type === type && found.name === name), Option.map((found) => found.span))
33
+ }),
34
+ text(" },\n")
35
+ ])),
36
+ text(" ];\n")
37
+ ];
38
+ const segmentsOf = (song, outline) => [
39
+ text(`import type { Song } from "${SONG_MODULE}";\n`),
40
+ text("export declare const song: Song & {\n readonly title: "),
41
+ ...titleSegments(song, outline),
42
+ text(";\n"),
43
+ ...pipe(Record.toEntries(NAMED_FIELDS), Array.flatMap(fieldSegments(song, outline))),
44
+ text("};\n")
45
+ ];
46
+ const issueOf = ({ path, outline }) => (issue) => {
47
+ if (issue.path === path) return {
48
+ message: issue.message,
49
+ start: issue.start,
50
+ end: issue.end
51
+ };
52
+ const at = pipe(outline.imports, Array.findFirst((found) => found.path === issue.path), Option.map((found) => found.span), Option.getOrElse(() => ({
53
+ start: 0,
54
+ end: 0
55
+ })));
56
+ return {
57
+ message: `${issue.path}:${String(issue.line)}:${String(issue.column)} ${issue.message}`,
58
+ ...at
59
+ };
60
+ };
61
+ const moduleOf = (path) => (source) => {
62
+ if (source.status === "invalid") return {
63
+ mapped: {
64
+ status: "error",
65
+ fallback: NEVER_SONG,
66
+ issues: pipe(source.issues, Array.map(issueOf({
67
+ path,
68
+ outline: source.outline
69
+ })))
70
+ },
71
+ song: Option.none(),
72
+ files: source.outline.files
73
+ };
74
+ return {
75
+ mapped: {
76
+ status: "ok",
77
+ segments: segmentsOf(source.song, source.outline)
78
+ },
79
+ song: Option.some(source.song),
80
+ files: source.outline.files
81
+ };
82
+ };
83
+ const songModuleOf = ({ path, content, read }) => readSong({
84
+ path,
85
+ read: (target) => {
86
+ if (target === path) return Effect.succeed(content);
87
+ return read(target);
88
+ }
89
+ }).pipe(Effect.map(moduleOf(path)));
90
+ const encodeSong = Schema.encodeEffect(Schema.fromJsonString(SongSchema));
91
+ const songCodeOf = (song) => encodeSong(song).pipe(Effect.orDie, Effect.map((json) => `import { Schema } from "effect";\nimport { SongSchema } from "${SONG_MODULE}";\nexport const song = Schema.decodeSync(Schema.fromJsonString(SongSchema))(${quoted(json)});\n`));
92
+ // src/app/vite.ts
93
+ const [EXTENSION] = FumxLanguageMetaData.fileExtensions;
94
+ const failure = (mapped) => Match.value(mapped).pipe(Match.discriminatorsExhaustive("status")({
95
+ ok: () => "",
96
+ error: ({ issues }) => pipe(issues, Array.map((issue) => issue.message), Array.join("\n"))
97
+ }));
98
+ const declarationOf = (content, mapped) => Match.value(mapped).pipe(Match.discriminatorsExhaustive("status")({
99
+ ok: ({ segments }) => Option.some(renderSegments({
100
+ content,
101
+ segments
102
+ })),
103
+ error: () => Option.none()
104
+ }));
105
+ const fumx = () => contentImport({
106
+ name: "fumx",
107
+ extension: EXTENSION,
108
+ load: ({ id, content, read }) => Effect.gen(function* load() {
109
+ const module = yield* songModuleOf({
110
+ path: id,
111
+ content,
112
+ read
113
+ });
114
+ const song = yield* Option.match(module.song, {
115
+ onNone: () => Effect.die(new Error(failure(module.mapped))),
116
+ onSome: Effect.succeed
117
+ });
118
+ return {
119
+ code: yield* songCodeOf(song),
120
+ declaration: declarationOf(content, module.mapped),
121
+ watchFiles: pipe(module.files, Array.filter((file) => file !== id))
122
+ };
123
+ })
124
+ });
125
+ export { fumx };
126
+
127
+ //# sourceMappingURL=vite.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.mjs","names":["Arr","Rec","Arr"],"sources":["../src/features/build-song-module/model/song-module.ts","../src/app/vite.ts"],"sourcesContent":["import { nameLiteral, quoted, text } from \"@r_masseater/masseater-utils/mapped-import\";\nimport type { Segment } from \"@r_masseater/masseater-utils/mapped-import\";\nimport type { Issue, Mapped } from \"@r_masseater/masseater-utils/mapped-import/mapper\";\nimport { Array as Arr, Effect, Option, Record as Rec, Schema, pipe } from \"effect\";\n\nimport { SongSchema } from \"#/entities/song/index.ts\";\nimport type { Song } from \"#/entities/song/index.ts\";\nimport { readSong } from \"#/features/read-song/@x/build-song-module.ts\";\nimport type {\n Named,\n Outline,\n SongSource,\n SourceIssue,\n} from \"#/features/read-song/@x/build-song-module.ts\";\n\nexport interface SongModuleSource<Failure> {\n readonly path: string;\n readonly content: string;\n readonly read: (path: string) => Effect.Effect<string, Failure>;\n}\n\nexport interface SongModule {\n readonly mapped: Mapped;\n readonly song: Option.Option<Song>;\n readonly files: readonly string[];\n}\n\ntype NamedField = {\n readonly [Field in keyof Song]: Song[Field] extends readonly { readonly name: string }[]\n ? Field\n : never;\n}[keyof Song];\n\nconst NAMED_FIELDS = {\n samples: \"Sample\",\n kits: \"Kit\",\n instruments: \"Instrument\",\n buses: \"Bus\",\n tracks: \"Track\",\n plugins: \"Plugin\",\n} as const satisfies Readonly<Record<NamedField, Named[\"$type\"]>>;\n\nconst SONG_MODULE = \"#/app/index.ts\";\n\nconst NEVER_SONG = \"export declare const song: never;\\n\";\n\nconst titleSegments = (song: Song, outline: Outline): readonly Segment[] =>\n Option.match(outline.title, {\n onNone: () => [text(quoted(song.title))],\n onSome: ({ start, end }): readonly Segment[] => [\n { kind: \"alias\", text: quoted(song.title), start, end },\n ],\n });\n\nconst fieldSegments =\n (song: Song, outline: Outline) =>\n ([field, type]: readonly [NamedField, Named[\"$type\"]]): readonly Segment[] => [\n text(` readonly ${field}: readonly [\\n`),\n ...pipe(\n song[field],\n Arr.flatMap(({ name }) => [\n text(` Song[\"${field}\"][number] & { readonly name: `),\n ...nameLiteral({\n name,\n span: pipe(\n outline.names,\n Arr.findFirst((found) => found.type === type && found.name === name),\n Option.map((found) => found.span),\n ),\n }),\n text(\" },\\n\"),\n ]),\n ),\n text(\" ];\\n\"),\n ];\n\nconst segmentsOf = (song: Song, outline: Outline): readonly Segment[] => [\n text(`import type { Song } from \"${SONG_MODULE}\";\\n`),\n text(\"export declare const song: Song & {\\n readonly title: \"),\n ...titleSegments(song, outline),\n text(\";\\n\"),\n ...pipe(Rec.toEntries(NAMED_FIELDS), Arr.flatMap(fieldSegments(song, outline))),\n text(\"};\\n\"),\n];\n\nconst issueOf =\n ({ path, outline }: Readonly<{ path: string; outline: Outline }>) =>\n (issue: SourceIssue): Issue => {\n if (issue.path === path) {\n return { message: issue.message, start: issue.start, end: issue.end };\n }\n const at = pipe(\n outline.imports,\n Arr.findFirst((found) => found.path === issue.path),\n Option.map((found) => found.span),\n Option.getOrElse(() => ({ start: 0, end: 0 })),\n );\n return {\n message: `${issue.path}:${String(issue.line)}:${String(issue.column)} ${issue.message}`,\n ...at,\n };\n };\n\nconst moduleOf =\n (path: string) =>\n (source: SongSource): SongModule => {\n if (source.status === \"invalid\") {\n return {\n mapped: {\n status: \"error\",\n fallback: NEVER_SONG,\n issues: pipe(source.issues, Arr.map(issueOf({ path, outline: source.outline }))),\n },\n song: Option.none(),\n files: source.outline.files,\n };\n }\n return {\n mapped: { status: \"ok\", segments: segmentsOf(source.song, source.outline) },\n song: Option.some(source.song),\n files: source.outline.files,\n };\n };\n\nexport const songModuleOf = <Failure>({\n path,\n content,\n read,\n}: SongModuleSource<Failure>): Effect.Effect<SongModule> =>\n readSong({\n path,\n read: (target) => {\n if (target === path) {\n return Effect.succeed(content);\n }\n return read(target);\n },\n }).pipe(Effect.map(moduleOf(path)));\n\nconst encodeSong = Schema.encodeEffect(Schema.fromJsonString(SongSchema));\n\nexport const songCodeOf = (song: Song): Effect.Effect<string> =>\n encodeSong(song).pipe(\n Effect.orDie,\n Effect.map(\n (json) =>\n `import { Schema } from \"effect\";\\nimport { SongSchema } from \"${SONG_MODULE}\";\\nexport const song = Schema.decodeSync(Schema.fromJsonString(SongSchema))(${quoted(json)});\\n`,\n ),\n );\n","import { renderSegments } from \"@r_masseater/masseater-utils/mapped-import\";\nimport type { Mapped } from \"@r_masseater/masseater-utils/mapped-import/mapper\";\nimport { contentImport } from \"@r_masseater/masseater-utils/mapped-import/vite\";\nimport { Array as Arr, Effect, Match, Option, pipe } from \"effect\";\nimport type { Plugin } from \"vite-plus\";\n\nimport { songCodeOf, songModuleOf } from \"#/features/build-song-module/index.ts\";\nimport type { FumxConfig } from \"#/features/check-songs/index.ts\";\nimport { FumxLanguageMetaData } from \"#generated/langium/module.ts\";\n\ndeclare module \"vite\" {\n interface UserConfig {\n readonly fumx?: FumxConfig;\n }\n}\n\nconst [EXTENSION] = FumxLanguageMetaData.fileExtensions;\n\nconst failure = (mapped: Mapped): string =>\n Match.value(mapped).pipe(\n Match.discriminatorsExhaustive(\"status\")({\n ok: () => \"\",\n error: ({ issues }) =>\n pipe(\n issues,\n Arr.map((issue) => issue.message),\n Arr.join(\"\\n\"),\n ),\n }),\n );\n\nconst declarationOf = (content: string, mapped: Mapped): Option.Option<string> =>\n Match.value(mapped).pipe(\n Match.discriminatorsExhaustive(\"status\")({\n ok: ({ segments }) => Option.some(renderSegments({ content, segments })),\n error: () => Option.none(),\n }),\n );\n\nexport const fumx = (): Plugin =>\n contentImport({\n name: \"fumx\",\n extension: EXTENSION,\n load: ({ id, content, read }) =>\n Effect.gen(function* load() {\n const module = yield* songModuleOf({ path: id, content, read });\n const song = yield* Option.match(module.song, {\n onNone: () => Effect.die(new Error(failure(module.mapped))),\n onSome: Effect.succeed,\n });\n return {\n code: yield* songCodeOf(song),\n declaration: declarationOf(content, module.mapped),\n watchFiles: pipe(\n module.files,\n Arr.filter((file) => file !== id),\n ),\n };\n }),\n });\n"],"mappings":";;;;;;AAiCA,MAAM,eAAe;CACnB,SAAS;CACT,MAAM;CACN,aAAa;CACb,OAAO;CACP,QAAQ;CACR,SAAS;AACX;AAEA,MAAM,cAAc;AAEpB,MAAM,aAAa;AAEnB,MAAM,iBAAiB,MAAY,YACjC,OAAO,MAAM,QAAQ,OAAO;CAC1B,cAAc,CAAC,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC;CACvC,SAAS,EAAE,OAAO,U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