@chordproject/editor 1.0.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.
- package/LICENSE +661 -0
- package/README.md +136 -0
- package/dist/index.cjs +836 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +825 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Compartment, EditorState as EditorState2 } from "@codemirror/state";
|
|
3
|
+
import { EditorView as EditorView5 } from "@codemirror/view";
|
|
4
|
+
|
|
5
|
+
// src/autocomplete/index.ts
|
|
6
|
+
import {
|
|
7
|
+
autocompletion,
|
|
8
|
+
completeFromList,
|
|
9
|
+
startCompletion
|
|
10
|
+
} from "@codemirror/autocomplete";
|
|
11
|
+
|
|
12
|
+
// src/autocomplete/chordVocabulary.ts
|
|
13
|
+
var ROOTS = ["A", "A#", "Bb", "B", "C", "C#", "Db", "D", "D#", "Eb", "E", "F", "F#", "Gb", "G", "G#", "Ab"];
|
|
14
|
+
var QUALITIES = ["", "m", "7", "m7", "maj7", "sus2", "sus4", "6", "m6", "9", "add9", "dim", "dim7", "aug", "m7b5"];
|
|
15
|
+
var CHORD_VOCABULARY = ROOTS.flatMap((root) => QUALITIES.map((quality) => root + quality));
|
|
16
|
+
|
|
17
|
+
// src/autocomplete/chords.ts
|
|
18
|
+
var CHORD_TOKEN = /\[([A-G](?:#|b)?(?:min|mi|m(?!aj)|-)?[^\]\s-]*(?:\/[A-G](?:#|b)?)?)\]/g;
|
|
19
|
+
var FREQUENCY_BOOST = 100;
|
|
20
|
+
var TRANSITION_BOOST = 1e3;
|
|
21
|
+
var PATTERN_BOOST = 1e4;
|
|
22
|
+
function countUsedChords(state) {
|
|
23
|
+
const counts = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const { name: chord } of getChordOccurrences(state.doc.toString())) {
|
|
25
|
+
counts.set(chord, (counts.get(chord) ?? 0) + 1);
|
|
26
|
+
}
|
|
27
|
+
return counts;
|
|
28
|
+
}
|
|
29
|
+
function getChordOccurrences(content) {
|
|
30
|
+
return [...content.matchAll(CHORD_TOKEN)].flatMap((match) => {
|
|
31
|
+
return match.index === void 0 ? [] : [{ name: match[1], from: match.index }];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function getChordCompletionPriorities(content, cursor) {
|
|
35
|
+
const history2 = getChordOccurrences(content).filter((occurrence) => occurrence.from < cursor - 1).map((occurrence) => occurrence.name);
|
|
36
|
+
const priorities = /* @__PURE__ */ new Map();
|
|
37
|
+
for (let index = 0; index < history2.length; index++) {
|
|
38
|
+
const candidate = history2[index];
|
|
39
|
+
if (index > 0 && history2[index - 1] === history2.at(-1)) {
|
|
40
|
+
priorities.set(candidate, (priorities.get(candidate) ?? 0) + TRANSITION_BOOST);
|
|
41
|
+
}
|
|
42
|
+
if (index > 1 && history2[index - 2] === history2.at(-2) && history2[index - 1] === history2.at(-1)) {
|
|
43
|
+
priorities.set(candidate, (priorities.get(candidate) ?? 0) + PATTERN_BOOST);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return priorities;
|
|
47
|
+
}
|
|
48
|
+
function applyChord(view, completion, from, to) {
|
|
49
|
+
const insert = completion.label;
|
|
50
|
+
const hasClosingBracket = view.state.sliceDoc(to, to + 1) === "]";
|
|
51
|
+
const cursor = from + insert.length + 1;
|
|
52
|
+
view.dispatch({
|
|
53
|
+
changes: hasClosingBracket ? { from, to, insert } : { from, to, insert: `${insert}]` },
|
|
54
|
+
selection: { anchor: cursor }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function buildOptions(used, priorities) {
|
|
58
|
+
const options = /* @__PURE__ */ new Map();
|
|
59
|
+
const rankedUsedChords = [...used.entries()].sort(([leftChord, leftCount], [rightChord, rightCount]) => {
|
|
60
|
+
const priorityDifference = (priorities.get(rightChord) ?? 0) - (priorities.get(leftChord) ?? 0);
|
|
61
|
+
return priorityDifference || rightCount - leftCount || leftChord.localeCompare(rightChord);
|
|
62
|
+
});
|
|
63
|
+
for (const [chord, count] of rankedUsedChords) {
|
|
64
|
+
options.set(chord, {
|
|
65
|
+
label: chord,
|
|
66
|
+
type: "chord-used",
|
|
67
|
+
boost: FREQUENCY_BOOST + count + (priorities.get(chord) ?? 0),
|
|
68
|
+
apply: applyChord
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
for (const chord of CHORD_VOCABULARY) {
|
|
72
|
+
if (!options.has(chord)) options.set(chord, { label: chord, type: "chord", apply: applyChord });
|
|
73
|
+
}
|
|
74
|
+
return [...options.values()];
|
|
75
|
+
}
|
|
76
|
+
function chordCompletionSource(context) {
|
|
77
|
+
const match = context.matchBefore(/\[[^\]\n]*/);
|
|
78
|
+
if (!match || match.from === match.to && !context.explicit) return null;
|
|
79
|
+
return {
|
|
80
|
+
from: match.from + 1,
|
|
81
|
+
options: buildOptions(
|
|
82
|
+
countUsedChords(context.state),
|
|
83
|
+
getChordCompletionPriorities(context.state.doc.toString(), match.from + 1)
|
|
84
|
+
),
|
|
85
|
+
validFor: /^[^\]\n]*$/
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/autocomplete/snippets.ts
|
|
90
|
+
import { snippetCompletion } from "@codemirror/autocomplete";
|
|
91
|
+
var CHORDPRO_SNIPPETS = [
|
|
92
|
+
snippetCompletion("{album: ${value}}", { label: "album", type: "directive" }),
|
|
93
|
+
snippetCompletion("{arranger: ${value}}", { label: "arranger", type: "directive" }),
|
|
94
|
+
snippetCompletion("{artist: ${value}}", { label: "artist", type: "directive" }),
|
|
95
|
+
snippetCompletion("{artist: ${value}}", { label: "a", type: "directive", detail: "artist" }),
|
|
96
|
+
snippetCompletion("{capo: ${5}}", { label: "capo", type: "directive" }),
|
|
97
|
+
snippetCompletion("{composer: ${value}}", { label: "composer", type: "directive" }),
|
|
98
|
+
snippetCompletion("{copyright: ${value}}", { label: "copyright", type: "directive" }),
|
|
99
|
+
snippetCompletion("{duration: ${4}:${00}}", { label: "duration", type: "directive" }),
|
|
100
|
+
snippetCompletion("{key: ${Am}}", { label: "key", type: "directive" }),
|
|
101
|
+
snippetCompletion("{key: ${Am}}", { label: "k", type: "directive", detail: "key" }),
|
|
102
|
+
snippetCompletion("{lyricist: ${value}}", { label: "lyricist", type: "directive" }),
|
|
103
|
+
snippetCompletion("{tempo: ${120}}", { label: "tempo", type: "directive" }),
|
|
104
|
+
snippetCompletion("{time: ${4}/${4}}", { label: "time", type: "directive" }),
|
|
105
|
+
snippetCompletion("{title: ${value}}", { label: "title", type: "directive" }),
|
|
106
|
+
snippetCompletion("{title: ${value}}", { label: "t", type: "directive", detail: "title" }),
|
|
107
|
+
snippetCompletion("{subtitle: ${value}}", { label: "subtitle", type: "directive" }),
|
|
108
|
+
snippetCompletion("{subtitle: ${value}}", { label: "st", type: "directive", detail: "subtitle" }),
|
|
109
|
+
snippetCompletion("{year: ${2020}}", { label: "year", type: "directive" }),
|
|
110
|
+
snippetCompletion("{meta: ${label} ${value}}", { label: "meta", type: "directive" }),
|
|
111
|
+
snippetCompletion("{comment: ${value}}", { label: "comment", type: "directive" }),
|
|
112
|
+
snippetCompletion("{comment: ${value}}", { label: "c", type: "directive", detail: "comment" }),
|
|
113
|
+
snippetCompletion("{start_of_chorus: ${Chorus}}\n${lyrics}\n{end_of_chorus}", {
|
|
114
|
+
label: "chorus",
|
|
115
|
+
type: "directive"
|
|
116
|
+
}),
|
|
117
|
+
snippetCompletion("{start_of_chorus}", { label: "soc", type: "directive", detail: "start_of_chorus" }),
|
|
118
|
+
snippetCompletion("{end_of_chorus}", { label: "eoc", type: "directive", detail: "end_of_chorus" }),
|
|
119
|
+
snippetCompletion("{start_of_verse: ${Verse} ${1}}\n${lyrics}\n{end_of_verse}", {
|
|
120
|
+
label: "verse",
|
|
121
|
+
type: "directive"
|
|
122
|
+
}),
|
|
123
|
+
snippetCompletion("{start_of_verse}", { label: "sov", type: "directive", detail: "start_of_verse" }),
|
|
124
|
+
snippetCompletion("{end_of_verse}", { label: "eov", type: "directive", detail: "end_of_verse" }),
|
|
125
|
+
snippetCompletion("{start_of_bridge: ${Bridge}}\n${lyrics}\n{end_of_bridge}", {
|
|
126
|
+
label: "bridge",
|
|
127
|
+
type: "directive"
|
|
128
|
+
}),
|
|
129
|
+
snippetCompletion("{start_of_bridge}", { label: "sob", type: "directive", detail: "start_of_bridge" }),
|
|
130
|
+
snippetCompletion("{end_of_bridge}", { label: "eob", type: "directive", detail: "end_of_bridge" }),
|
|
131
|
+
snippetCompletion(
|
|
132
|
+
"{start_of_tab}\ne|-${1}--------------------------------|\nB|----------------------------------|\nG|----------------------------------|\nD|----------------------------------|\nA|----------------------------------|\nE|----------------------------------|\n{end_of_tab}",
|
|
133
|
+
{ label: "tab", type: "directive" }
|
|
134
|
+
),
|
|
135
|
+
snippetCompletion("{start_of_tab}", { label: "sot", type: "directive", detail: "start_of_tab" }),
|
|
136
|
+
snippetCompletion("{end_of_tab}", { label: "eot", type: "directive", detail: "end_of_tab" }),
|
|
137
|
+
snippetCompletion("{define: ${Am} base-fret ${1} frets ${0 0 0 0 0 0} fingers ${0 0 0 0 0 0}}", {
|
|
138
|
+
label: "define",
|
|
139
|
+
type: "directive"
|
|
140
|
+
}),
|
|
141
|
+
snippetCompletion("{define: ${Am} base-fret ${1} frets ${0 0 0 0 0 0} fingers ${0 0 0 0 0 0}}", {
|
|
142
|
+
label: "d",
|
|
143
|
+
type: "directive",
|
|
144
|
+
detail: "define"
|
|
145
|
+
}),
|
|
146
|
+
snippetCompletion("[${Am}]", { label: "[", type: "chord", detail: "insert a chord" }),
|
|
147
|
+
snippetCompletion(
|
|
148
|
+
"{title: ${value}}\n{artist: ${value}}\n{key: ${C}}\n\n${lyrics}\n{start_of_chorus}\n${lyrics}\n{end_of_chorus}",
|
|
149
|
+
{ label: "!", type: "directive", detail: "new song template" }
|
|
150
|
+
)
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
// src/autocomplete/index.ts
|
|
154
|
+
var completeSnippets = completeFromList(CHORDPRO_SNIPPETS);
|
|
155
|
+
function chordProCompletionSource(context) {
|
|
156
|
+
const chordCompletions = chordCompletionSource(context);
|
|
157
|
+
if (chordCompletions) return chordCompletions;
|
|
158
|
+
return context.explicit ? completeSnippets(context) : null;
|
|
159
|
+
}
|
|
160
|
+
function chordProAutocomplete() {
|
|
161
|
+
return autocompletion({ override: [chordProCompletionSource], activateOnTyping: true });
|
|
162
|
+
}
|
|
163
|
+
function openCompletionList(view) {
|
|
164
|
+
view.focus();
|
|
165
|
+
return startCompletion(view);
|
|
166
|
+
}
|
|
167
|
+
function insertChord(view) {
|
|
168
|
+
const range = view.state.selection.main;
|
|
169
|
+
const selected = view.state.sliceDoc(range.from, range.to);
|
|
170
|
+
view.dispatch({
|
|
171
|
+
changes: { from: range.from, to: range.to, insert: `[${selected}]` },
|
|
172
|
+
selection: { anchor: range.from + 1 + selected.length }
|
|
173
|
+
});
|
|
174
|
+
view.focus();
|
|
175
|
+
startCompletion(view);
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/extensions.ts
|
|
180
|
+
import { EditorState } from "@codemirror/state";
|
|
181
|
+
import {
|
|
182
|
+
EditorView,
|
|
183
|
+
keymap,
|
|
184
|
+
highlightActiveLine,
|
|
185
|
+
highlightSpecialChars,
|
|
186
|
+
drawSelection
|
|
187
|
+
} from "@codemirror/view";
|
|
188
|
+
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
|
189
|
+
import { bracketMatching, foldGutter, foldKeymap } from "@codemirror/language";
|
|
190
|
+
import { lintGutter, lintKeymap } from "@codemirror/lint";
|
|
191
|
+
import {
|
|
192
|
+
acceptCompletion,
|
|
193
|
+
closeBrackets,
|
|
194
|
+
closeBracketsKeymap,
|
|
195
|
+
completionKeymap,
|
|
196
|
+
completionStatus,
|
|
197
|
+
startCompletion as startCompletion2
|
|
198
|
+
} from "@codemirror/autocomplete";
|
|
199
|
+
function isInsideChordBrackets(view) {
|
|
200
|
+
const pos = view.state.selection.main.head;
|
|
201
|
+
const line = view.state.doc.lineAt(pos);
|
|
202
|
+
return /\[[^\]]*$/.test(line.text.slice(0, pos - line.from));
|
|
203
|
+
}
|
|
204
|
+
function chordAwareCompletion(view) {
|
|
205
|
+
return isInsideChordBrackets(view) ? startCompletion2(view) : insertChord(view);
|
|
206
|
+
}
|
|
207
|
+
var chordBracketInputHandler = EditorView.inputHandler.of((view, from, to, text) => {
|
|
208
|
+
if (text !== "[") return false;
|
|
209
|
+
const selected = view.state.sliceDoc(from, to);
|
|
210
|
+
view.dispatch({
|
|
211
|
+
changes: { from, to, insert: `[${selected}]` },
|
|
212
|
+
selection: { anchor: from + 1 + selected.length }
|
|
213
|
+
});
|
|
214
|
+
startCompletion2(view);
|
|
215
|
+
return true;
|
|
216
|
+
});
|
|
217
|
+
function basicSetup() {
|
|
218
|
+
return [
|
|
219
|
+
foldGutter(),
|
|
220
|
+
lintGutter(),
|
|
221
|
+
highlightSpecialChars(),
|
|
222
|
+
highlightActiveLine(),
|
|
223
|
+
history(),
|
|
224
|
+
drawSelection(),
|
|
225
|
+
bracketMatching(),
|
|
226
|
+
closeBrackets(),
|
|
227
|
+
chordBracketInputHandler,
|
|
228
|
+
EditorState.allowMultipleSelections.of(true),
|
|
229
|
+
keymap.of([
|
|
230
|
+
// Insert a complete ChordPro token before opening suggestions so an unfinished "["
|
|
231
|
+
// is never momentarily interpreted as invalid song content.
|
|
232
|
+
{ key: "[", run: insertChord },
|
|
233
|
+
...closeBracketsKeymap,
|
|
234
|
+
...defaultKeymap,
|
|
235
|
+
...historyKeymap,
|
|
236
|
+
...foldKeymap,
|
|
237
|
+
...lintKeymap,
|
|
238
|
+
// Override completionKeymap's Ctrl-Space/Option-`/Option-i (same keys, listed first so
|
|
239
|
+
// they take precedence) to be chord-aware instead of plain startCompletion.
|
|
240
|
+
{ key: "Ctrl-Space", run: chordAwareCompletion },
|
|
241
|
+
{ mac: "Cmd-Shift-Space", run: chordAwareCompletion },
|
|
242
|
+
{ mac: "Alt-`", run: chordAwareCompletion },
|
|
243
|
+
{ mac: "Alt-i", run: chordAwareCompletion },
|
|
244
|
+
...completionKeymap,
|
|
245
|
+
// Tab accepts a completion/snippet field when the popup is open.
|
|
246
|
+
{
|
|
247
|
+
key: "Tab",
|
|
248
|
+
preventDefault: true,
|
|
249
|
+
run: (view) => completionStatus(view.state) ? acceptCompletion(view) : false
|
|
250
|
+
}
|
|
251
|
+
])
|
|
252
|
+
];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/folding.ts
|
|
256
|
+
import { foldService } from "@codemirror/language";
|
|
257
|
+
var START_RE = /\{(so(?<name>v|b|c|t)|start_of_(?<longname>[^\s:}]+))(?:[: ][^}]*)?\}/i;
|
|
258
|
+
var END_RE = /\{(eo(?<name>v|b|c|t)|end_of_(?<longname>[^\s:}]+))\}/i;
|
|
259
|
+
var SHORT_TO_LONG = { v: "verse", b: "bridge", c: "chorus", t: "tab" };
|
|
260
|
+
function blockName(match) {
|
|
261
|
+
const name = match.groups?.name ?? match.groups?.longname;
|
|
262
|
+
if (!name) return null;
|
|
263
|
+
return (SHORT_TO_LONG[name.toLowerCase()] ?? name.toLowerCase()).replace(/s$/, "");
|
|
264
|
+
}
|
|
265
|
+
var chordProFolding = foldService.of((state, lineStart, lineEnd) => {
|
|
266
|
+
const startMatch = state.doc.sliceString(lineStart, lineEnd).match(START_RE);
|
|
267
|
+
if (!startMatch) return null;
|
|
268
|
+
const name = blockName(startMatch);
|
|
269
|
+
if (!name) return null;
|
|
270
|
+
let pos = lineEnd;
|
|
271
|
+
while (pos < state.doc.length) {
|
|
272
|
+
const line = state.doc.lineAt(pos + 1);
|
|
273
|
+
const endMatch = line.text.match(END_RE);
|
|
274
|
+
if (endMatch && blockName(endMatch) === name) {
|
|
275
|
+
return line.to > lineEnd ? { from: lineEnd, to: line.to } : null;
|
|
276
|
+
}
|
|
277
|
+
pos = line.to;
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// src/language/index.ts
|
|
283
|
+
import { LanguageSupport } from "@codemirror/language";
|
|
284
|
+
|
|
285
|
+
// src/language/chordproStream.ts
|
|
286
|
+
import { StreamLanguage } from "@codemirror/language";
|
|
287
|
+
import { tags as t } from "@lezer/highlight";
|
|
288
|
+
|
|
289
|
+
// src/language/tokens.ts
|
|
290
|
+
var PREAMBLE_DIRECTIVES = /^(new_song|ns)$/i;
|
|
291
|
+
var META_DIRECTIVES = /^(title|t|sorttitle|subtitle|st|artist|sortartist|composer|arranger|lyricist|copyright|album|year|key|time|tempo|duration|capo|tag|meta)$/i;
|
|
292
|
+
var FORMATTING_DIRECTIVES = /^(comment|c|highlight|comment_italic|ci|comment_box|cb|image)$/i;
|
|
293
|
+
var ENV_DIRECTIVES = /^(start_of_chorus|soc|end_of_chorus|eoc|chorus|start_of_verse|sov|end_of_verse|eov|start_of_bridge|sob|end_of_bridge|eob|start_of_tab|sot|end_of_tab|eot|start_of_grid|sog|end_of_grid|eog)$/i;
|
|
294
|
+
var DELEGATED_ENV_DIRECTIVES = /^(start_of_abc|end_of_abc|start_of_ly|end_of_ly|start_of_svg|end_of_svg|start_of_textblock|end_of_textblock)$/i;
|
|
295
|
+
var CHORD_DIAGRAM_DIRECTIVES = /^define$/i;
|
|
296
|
+
var CUSTOM_EXTENSION_DIRECTIVE = /^x_[\w]+$/i;
|
|
297
|
+
var KNOWN_DIRECTIVE_LISTS = [
|
|
298
|
+
PREAMBLE_DIRECTIVES,
|
|
299
|
+
META_DIRECTIVES,
|
|
300
|
+
FORMATTING_DIRECTIVES,
|
|
301
|
+
ENV_DIRECTIVES,
|
|
302
|
+
DELEGATED_ENV_DIRECTIVES,
|
|
303
|
+
CHORD_DIAGRAM_DIRECTIVES
|
|
304
|
+
];
|
|
305
|
+
var TAB_START_DIRECTIVES = /^(start_of_tab|sot)$/i;
|
|
306
|
+
var DEFINE_DIRECTIVE = /^define$/i;
|
|
307
|
+
var DIRECTIVE_NAME = /^[A-Za-z_][\w]*(?:-[\w!]+)?/;
|
|
308
|
+
var DEFINE_KEYWORD = /^(fingers|frets|base-fret)\b/i;
|
|
309
|
+
function baseDirectiveName(name) {
|
|
310
|
+
return name.replace(/-[\w!]+$/, "");
|
|
311
|
+
}
|
|
312
|
+
function isKnownDirective(name) {
|
|
313
|
+
const base = baseDirectiveName(name);
|
|
314
|
+
if (CUSTOM_EXTENSION_DIRECTIVE.test(base)) return true;
|
|
315
|
+
return KNOWN_DIRECTIVE_LISTS.some((re) => re.test(base));
|
|
316
|
+
}
|
|
317
|
+
var CHORD_TEXT = /^(\*.+|[A-G](?:#{1,2}|b{1,2}|x)?[^\]]*)/i;
|
|
318
|
+
|
|
319
|
+
// src/language/chordproStream.ts
|
|
320
|
+
function startState() {
|
|
321
|
+
return { mode: "default", pendingName: "" };
|
|
322
|
+
}
|
|
323
|
+
function copyState(state) {
|
|
324
|
+
return { ...state };
|
|
325
|
+
}
|
|
326
|
+
function token(stream, state) {
|
|
327
|
+
if (state.mode === "tab") {
|
|
328
|
+
if (stream.match(/^\{\s*(end_of_tab|eot)\s*\}/i)) {
|
|
329
|
+
state.mode = "default";
|
|
330
|
+
return "directiveBrace";
|
|
331
|
+
}
|
|
332
|
+
if (stream.match(/^-+/)) return "tabDash";
|
|
333
|
+
if (stream.match(/^\|+/)) return "tabChar";
|
|
334
|
+
if (stream.match(/^[A-Ga-g][b#]?/)) return "tabString";
|
|
335
|
+
if (stream.match(/^[0-9]+/)) return "tabNumber";
|
|
336
|
+
stream.next();
|
|
337
|
+
return "tabText";
|
|
338
|
+
}
|
|
339
|
+
if (state.mode === "define") {
|
|
340
|
+
if (stream.match(/^\}/)) {
|
|
341
|
+
state.mode = "default";
|
|
342
|
+
return "directiveBrace";
|
|
343
|
+
}
|
|
344
|
+
if (stream.eatSpace()) return null;
|
|
345
|
+
if (stream.match(/^[0-9]+/)) return "defineNumber";
|
|
346
|
+
if (stream.match(DEFINE_KEYWORD)) return "defineKeyword";
|
|
347
|
+
stream.match(/^[^\s0-9}]+/) || stream.next();
|
|
348
|
+
return "defineValue";
|
|
349
|
+
}
|
|
350
|
+
if (state.mode === "directiveValue") {
|
|
351
|
+
if (stream.match(/^\}/)) {
|
|
352
|
+
state.mode = "default";
|
|
353
|
+
return "directiveBrace";
|
|
354
|
+
}
|
|
355
|
+
stream.match(/^(\\.|[^\\}])+/) || stream.next();
|
|
356
|
+
return "directiveValue";
|
|
357
|
+
}
|
|
358
|
+
if (state.mode === "directiveName") {
|
|
359
|
+
stream.eatSpace();
|
|
360
|
+
const match = stream.match(DIRECTIVE_NAME);
|
|
361
|
+
if (match) {
|
|
362
|
+
const name = match[0];
|
|
363
|
+
state.pendingName = name;
|
|
364
|
+
state.mode = "afterName";
|
|
365
|
+
return isKnownDirective(name) ? "directiveName" : "directiveNameInvalid";
|
|
366
|
+
}
|
|
367
|
+
state.mode = "default";
|
|
368
|
+
if (stream.match(/^\}/)) return "directiveBrace";
|
|
369
|
+
stream.next();
|
|
370
|
+
return "directiveNameInvalid";
|
|
371
|
+
}
|
|
372
|
+
if (state.mode === "afterName") {
|
|
373
|
+
const name = baseDirectiveName(state.pendingName);
|
|
374
|
+
if (stream.match(/^:/)) {
|
|
375
|
+
state.mode = DEFINE_DIRECTIVE.test(name) ? "define" : "directiveValue";
|
|
376
|
+
return "directiveColon";
|
|
377
|
+
}
|
|
378
|
+
if (stream.match(/^\}/)) {
|
|
379
|
+
state.mode = TAB_START_DIRECTIVES.test(name) ? "tab" : "default";
|
|
380
|
+
return "directiveBrace";
|
|
381
|
+
}
|
|
382
|
+
if (stream.eatSpace()) {
|
|
383
|
+
state.mode = DEFINE_DIRECTIVE.test(name) ? "define" : "directiveValue";
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
state.mode = "default";
|
|
387
|
+
stream.next();
|
|
388
|
+
return "directiveNameInvalid";
|
|
389
|
+
}
|
|
390
|
+
if (state.mode === "chord" || state.mode === "afterChord" || state.mode === "afterChordInvalid") {
|
|
391
|
+
if (stream.eat("]")) {
|
|
392
|
+
state.mode = "default";
|
|
393
|
+
return "chordBracket";
|
|
394
|
+
}
|
|
395
|
+
if (state.mode === "chord") {
|
|
396
|
+
const match = stream.match(CHORD_TEXT);
|
|
397
|
+
state.mode = match ? "afterChord" : "afterChordInvalid";
|
|
398
|
+
if (!match) stream.match(/^[^\]]+/);
|
|
399
|
+
return match ? "chord" : "chordInvalid";
|
|
400
|
+
}
|
|
401
|
+
stream.match(/^[^\]]+/);
|
|
402
|
+
return "chordInvalid";
|
|
403
|
+
}
|
|
404
|
+
if (stream.sol() && stream.match(/^#.*/)) return "comment";
|
|
405
|
+
if (stream.match(/^\{/)) {
|
|
406
|
+
state.mode = "directiveName";
|
|
407
|
+
return "directiveBrace";
|
|
408
|
+
}
|
|
409
|
+
if (stream.eat("[")) {
|
|
410
|
+
state.mode = "chord";
|
|
411
|
+
return "chordBracket";
|
|
412
|
+
}
|
|
413
|
+
stream.match(/^[^{[]+/) || stream.next();
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
var tokenTable = {
|
|
417
|
+
directiveBrace: t.meta,
|
|
418
|
+
directiveName: t.attributeName,
|
|
419
|
+
directiveNameInvalid: t.invalid,
|
|
420
|
+
directiveColon: t.punctuation,
|
|
421
|
+
directiveValue: t.string,
|
|
422
|
+
defineKeyword: t.keyword,
|
|
423
|
+
defineNumber: t.number,
|
|
424
|
+
defineValue: t.string,
|
|
425
|
+
chordBracket: t.character,
|
|
426
|
+
chord: t.keyword,
|
|
427
|
+
chordInvalid: t.invalid,
|
|
428
|
+
comment: t.lineComment,
|
|
429
|
+
tabDash: t.comment,
|
|
430
|
+
tabChar: t.character,
|
|
431
|
+
tabString: t.string,
|
|
432
|
+
tabNumber: t.number,
|
|
433
|
+
tabText: t.comment
|
|
434
|
+
};
|
|
435
|
+
var chordProLanguage = StreamLanguage.define({
|
|
436
|
+
startState,
|
|
437
|
+
copyState,
|
|
438
|
+
token,
|
|
439
|
+
tokenTable,
|
|
440
|
+
languageData: {
|
|
441
|
+
commentTokens: { line: "#" }
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// src/language/index.ts
|
|
446
|
+
function chordPro() {
|
|
447
|
+
return new LanguageSupport(chordProLanguage);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/linting.ts
|
|
451
|
+
import { linter } from "@codemirror/lint";
|
|
452
|
+
import { ChordProParser } from "@chordproject/parser";
|
|
453
|
+
|
|
454
|
+
// src/chordNotation.ts
|
|
455
|
+
var CHORD_TOKEN2 = /\[([A-G](?:#|b)?)([^/\]\s]*)(\/[A-G](?:#|b)?)?\]/g;
|
|
456
|
+
var CHORD_TYPE_ALIASES = {
|
|
457
|
+
sus: { canonical: "sus4", reason: '"sus" se interpreta como sus4; escr\xEDbelo expl\xEDcitamente.' },
|
|
458
|
+
"2": { canonical: "sus2", reason: '"sus2" identifica el acorde suspendido de segunda.' },
|
|
459
|
+
"+": { canonical: "aug", reason: '"aug" es la notaci\xF3n expl\xEDcita para quinta aumentada.' },
|
|
460
|
+
M7: { canonical: "maj7", reason: '"maj7" identifica expl\xEDcitamente la s\xE9ptima mayor.' },
|
|
461
|
+
Maj7: { canonical: "maj7", reason: '"maj7" identifica expl\xEDcitamente la s\xE9ptima mayor.' }
|
|
462
|
+
};
|
|
463
|
+
function findChordNotationReplacements(content) {
|
|
464
|
+
const replacements = [];
|
|
465
|
+
for (const match of content.matchAll(CHORD_TOKEN2)) {
|
|
466
|
+
const alias = CHORD_TYPE_ALIASES[match[2]];
|
|
467
|
+
if (!alias || match.index === void 0) continue;
|
|
468
|
+
const replacement = `${match[1]}${alias.canonical}${match[3] ?? ""}`;
|
|
469
|
+
replacements.push({
|
|
470
|
+
from: match.index,
|
|
471
|
+
to: match.index + match[0].length,
|
|
472
|
+
original: match[0].slice(1, -1),
|
|
473
|
+
replacement,
|
|
474
|
+
reason: alias.reason
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return replacements;
|
|
478
|
+
}
|
|
479
|
+
function getChordNotationSuggestions(content) {
|
|
480
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
481
|
+
for (const replacement of findChordNotationReplacements(content)) {
|
|
482
|
+
const key = `${replacement.original}\0${replacement.replacement}`;
|
|
483
|
+
const suggestion = grouped.get(key);
|
|
484
|
+
if (suggestion) {
|
|
485
|
+
suggestion.occurrences++;
|
|
486
|
+
} else {
|
|
487
|
+
grouped.set(key, {
|
|
488
|
+
original: replacement.original,
|
|
489
|
+
replacement: replacement.replacement,
|
|
490
|
+
occurrences: 1,
|
|
491
|
+
reason: replacement.reason
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return [...grouped.values()];
|
|
496
|
+
}
|
|
497
|
+
function normalizeChordNotationText(content) {
|
|
498
|
+
const replacements = findChordNotationReplacements(content);
|
|
499
|
+
const normalizedContent = [...replacements].reverse().reduce((result, replacement) => {
|
|
500
|
+
return `${result.slice(0, replacement.from)}[${replacement.replacement}]${result.slice(replacement.to)}`;
|
|
501
|
+
}, content);
|
|
502
|
+
return {
|
|
503
|
+
content: normalizedContent,
|
|
504
|
+
suggestions: getChordNotationSuggestions(content)
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// src/linting.ts
|
|
509
|
+
var SINGULAR_DIRECTIVES = {
|
|
510
|
+
title: "title",
|
|
511
|
+
t: "title",
|
|
512
|
+
subtitle: "subtitle",
|
|
513
|
+
st: "subtitle",
|
|
514
|
+
year: "year",
|
|
515
|
+
copyright: "copyright",
|
|
516
|
+
key: "key",
|
|
517
|
+
capo: "capo",
|
|
518
|
+
duration: "duration",
|
|
519
|
+
tempo: "tempo",
|
|
520
|
+
time: "time"
|
|
521
|
+
};
|
|
522
|
+
var DIRECTIVE_LINE = /^\s*\{\s*([A-Za-z_][\w]*)\b/;
|
|
523
|
+
var duplicateDirectiveLinter = linter((view) => {
|
|
524
|
+
const diagnostics = [];
|
|
525
|
+
const firstSeenAtLine = /* @__PURE__ */ new Map();
|
|
526
|
+
for (let lineNumber = 1; lineNumber <= view.state.doc.lines; lineNumber++) {
|
|
527
|
+
const line = view.state.doc.line(lineNumber);
|
|
528
|
+
const match = line.text.match(DIRECTIVE_LINE);
|
|
529
|
+
if (!match) continue;
|
|
530
|
+
const canonical = SINGULAR_DIRECTIVES[match[1].toLowerCase()];
|
|
531
|
+
if (!canonical) continue;
|
|
532
|
+
const firstLine = firstSeenAtLine.get(canonical);
|
|
533
|
+
if (firstLine === void 0) {
|
|
534
|
+
firstSeenAtLine.set(canonical, lineNumber);
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
diagnostics.push({
|
|
538
|
+
from: line.from,
|
|
539
|
+
to: line.from + match[0].length,
|
|
540
|
+
severity: "warning",
|
|
541
|
+
message: `"${canonical}" ya se defini\xF3 en la l\xEDnea ${firstLine}; este valor la reemplaza.`
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
return diagnostics;
|
|
545
|
+
});
|
|
546
|
+
var parserWarningLinter = linter((view) => {
|
|
547
|
+
const parser = new ChordProParser();
|
|
548
|
+
parser.parse(view.state.doc.toString());
|
|
549
|
+
return parser.warnings.flatMap((warning) => {
|
|
550
|
+
if (warning.lineNumber < 1 || warning.lineNumber > view.state.doc.lines) {
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
const line = view.state.doc.line(warning.lineNumber);
|
|
554
|
+
return [{
|
|
555
|
+
from: line.from,
|
|
556
|
+
to: line.to,
|
|
557
|
+
severity: "warning",
|
|
558
|
+
message: warning.message
|
|
559
|
+
}];
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
var chordNotationLinter = linter((view) => {
|
|
563
|
+
const diagnostics = [];
|
|
564
|
+
for (const replacement of findChordNotationReplacements(view.state.doc.toString())) {
|
|
565
|
+
diagnostics.push({
|
|
566
|
+
from: replacement.from,
|
|
567
|
+
to: replacement.to,
|
|
568
|
+
severity: "info",
|
|
569
|
+
message: `Usa "${replacement.replacement}". ${replacement.reason}`,
|
|
570
|
+
actions: [{
|
|
571
|
+
name: `Reemplazar por ${replacement.replacement}`,
|
|
572
|
+
apply: (targetView, actionFrom, actionTo) => {
|
|
573
|
+
targetView.dispatch({ changes: { from: actionFrom, to: actionTo, insert: `[${replacement.replacement}]` } });
|
|
574
|
+
}
|
|
575
|
+
}]
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
return diagnostics;
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// src/themes/base.ts
|
|
582
|
+
import { EditorView as EditorView2 } from "@codemirror/view";
|
|
583
|
+
var baseTheme = EditorView2.baseTheme({
|
|
584
|
+
"&": {
|
|
585
|
+
height: "100%"
|
|
586
|
+
},
|
|
587
|
+
".cm-scroller": {
|
|
588
|
+
flex: "1",
|
|
589
|
+
overflow: "auto"
|
|
590
|
+
},
|
|
591
|
+
".cm-lintRange-info": {
|
|
592
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important'
|
|
593
|
+
},
|
|
594
|
+
".cm-lintRange-warning": {
|
|
595
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23d97706" fill="none" stroke-width="1"/></svg>") !important'
|
|
596
|
+
},
|
|
597
|
+
".cm-lintRange-error": {
|
|
598
|
+
backgroundImage: 'url("data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="6" height="3"><path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/></svg>") !important'
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// src/themes/dark.ts
|
|
603
|
+
import { EditorView as EditorView3 } from "@codemirror/view";
|
|
604
|
+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
605
|
+
import { tags as t2 } from "@lezer/highlight";
|
|
606
|
+
var editorTheme = EditorView3.theme(
|
|
607
|
+
{
|
|
608
|
+
"&": {
|
|
609
|
+
backgroundColor: "var(--color-neutral-900, #18181b)",
|
|
610
|
+
color: "var(--color-neutral-100, #f4f4f5)"
|
|
611
|
+
},
|
|
612
|
+
".cm-content": {
|
|
613
|
+
caretColor: "var(--color-neutral-100, #f4f4f5)"
|
|
614
|
+
},
|
|
615
|
+
".cm-cursor, .cm-dropCursor": {
|
|
616
|
+
borderLeftColor: "var(--color-neutral-100, #f4f4f5)"
|
|
617
|
+
},
|
|
618
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
619
|
+
backgroundColor: "color-mix(in oklch, var(--color-primary-400, #60a5fa) 88%, transparent) !important"
|
|
620
|
+
},
|
|
621
|
+
"&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
|
|
622
|
+
backgroundColor: "color-mix(in oklch, var(--color-primary-400, #60a5fa) 54%, transparent) !important",
|
|
623
|
+
color: "inherit !important"
|
|
624
|
+
},
|
|
625
|
+
".cm-selectionLayer .cm-selectionBackground": {
|
|
626
|
+
boxShadow: "inset 0 -2px 0 var(--color-primary-200, #bfdbfe)"
|
|
627
|
+
},
|
|
628
|
+
".cm-activeLine": {
|
|
629
|
+
backgroundColor: "var(--color-neutral-800, #27272a)"
|
|
630
|
+
},
|
|
631
|
+
".cm-gutters": {
|
|
632
|
+
backgroundColor: "var(--color-neutral-900, #18181b)",
|
|
633
|
+
color: "var(--color-neutral-400, #a1a1aa)",
|
|
634
|
+
border: "none"
|
|
635
|
+
},
|
|
636
|
+
".cm-activeLineGutter": {
|
|
637
|
+
backgroundColor: "var(--color-neutral-800, #27272a)"
|
|
638
|
+
},
|
|
639
|
+
".cm-completionIcon-chord-used + .cm-completionLabel": {
|
|
640
|
+
color: "var(--color-primary-300, #93c5fd)",
|
|
641
|
+
fontWeight: "600"
|
|
642
|
+
},
|
|
643
|
+
'.cm-tooltip-autocomplete > ul > li[aria-selected="true"] .cm-completionIcon-chord-used + .cm-completionLabel': {
|
|
644
|
+
color: "var(--color-white, #ffffff)"
|
|
645
|
+
},
|
|
646
|
+
".cm-lintRange-info": {
|
|
647
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23f87171" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
648
|
+
backgroundSize: "6px 3px",
|
|
649
|
+
backgroundPosition: "left bottom",
|
|
650
|
+
backgroundRepeat: "no-repeat"
|
|
651
|
+
},
|
|
652
|
+
".cm-lintRange-warning": {
|
|
653
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23fcd34d" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
654
|
+
backgroundSize: "6px 3px",
|
|
655
|
+
backgroundPosition: "left bottom",
|
|
656
|
+
backgroundRepeat: "no-repeat"
|
|
657
|
+
},
|
|
658
|
+
".cm-lintRange-error": {
|
|
659
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23f87171" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
660
|
+
backgroundSize: "6px 3px",
|
|
661
|
+
backgroundPosition: "left bottom",
|
|
662
|
+
backgroundRepeat: "no-repeat"
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
{ dark: true }
|
|
666
|
+
);
|
|
667
|
+
var highlightStyle = HighlightStyle.define([
|
|
668
|
+
{ tag: t2.keyword, color: "var(--color-error-400, #f87171)" },
|
|
669
|
+
{ tag: [t2.meta, t2.attributeName], color: "var(--color-primary-300, #93c5fd)" },
|
|
670
|
+
{ tag: [t2.constant(t2.name), t2.character, t2.number], color: "var(--color-neutral-400, #a1a1aa)" },
|
|
671
|
+
{ tag: t2.invalid, color: "var(--color-error-200, #fecaca)", backgroundColor: "color-mix(in oklch, var(--color-error-600, #dc2626) 30%, transparent)" },
|
|
672
|
+
{ tag: t2.string, color: "var(--color-neutral-300, #d4d4d8)" },
|
|
673
|
+
{ tag: [t2.comment, t2.lineComment], fontStyle: "italic", color: "#79c98d" },
|
|
674
|
+
{ tag: t2.heading, color: "var(--color-primary-300, #93c5fd)" }
|
|
675
|
+
]);
|
|
676
|
+
var darkTheme = [editorTheme, syntaxHighlighting(highlightStyle)];
|
|
677
|
+
|
|
678
|
+
// src/themes/light.ts
|
|
679
|
+
import { EditorView as EditorView4 } from "@codemirror/view";
|
|
680
|
+
import { HighlightStyle as HighlightStyle2, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
681
|
+
import { tags as t3 } from "@lezer/highlight";
|
|
682
|
+
var editorTheme2 = EditorView4.theme(
|
|
683
|
+
{
|
|
684
|
+
"&": {
|
|
685
|
+
backgroundColor: "var(--color-white, #ffffff)",
|
|
686
|
+
color: "var(--color-neutral-950, #09090b)"
|
|
687
|
+
},
|
|
688
|
+
".cm-content": {
|
|
689
|
+
caretColor: "var(--color-neutral-950, #09090b)"
|
|
690
|
+
},
|
|
691
|
+
".cm-cursor, .cm-dropCursor": {
|
|
692
|
+
borderLeftColor: "var(--color-neutral-950, #09090b)"
|
|
693
|
+
},
|
|
694
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
695
|
+
backgroundColor: "color-mix(in oklch, var(--color-primary-500, #3b82f6) 78%, transparent) !important"
|
|
696
|
+
},
|
|
697
|
+
"&.cm-focused .cm-content:focus::selection, &.cm-focused .cm-content .cm-line::selection": {
|
|
698
|
+
backgroundColor: "color-mix(in oklch, var(--color-primary-500, #3b82f6) 52%, transparent) !important",
|
|
699
|
+
color: "inherit !important"
|
|
700
|
+
},
|
|
701
|
+
".cm-selectionLayer .cm-selectionBackground": {
|
|
702
|
+
boxShadow: "inset 0 -2px 0 var(--color-primary-700, #1d4ed8)"
|
|
703
|
+
},
|
|
704
|
+
".cm-activeLine": {
|
|
705
|
+
backgroundColor: "var(--color-neutral-100, #f4f4f5)"
|
|
706
|
+
},
|
|
707
|
+
".cm-gutters": {
|
|
708
|
+
backgroundColor: "var(--color-neutral-50, #fafafa)",
|
|
709
|
+
color: "var(--color-neutral-500, #71717a)",
|
|
710
|
+
border: "none"
|
|
711
|
+
},
|
|
712
|
+
".cm-activeLineGutter": {
|
|
713
|
+
backgroundColor: "var(--color-neutral-100, #f4f4f5)"
|
|
714
|
+
},
|
|
715
|
+
".cm-completionIcon-chord-used + .cm-completionLabel": {
|
|
716
|
+
color: "var(--color-primary-700, #1d4ed8)",
|
|
717
|
+
fontWeight: "600"
|
|
718
|
+
},
|
|
719
|
+
'.cm-tooltip-autocomplete > ul > li[aria-selected="true"] .cm-completionIcon-chord-used + .cm-completionLabel': {
|
|
720
|
+
color: "var(--color-white, #ffffff)"
|
|
721
|
+
},
|
|
722
|
+
".cm-lintRange-info": {
|
|
723
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
724
|
+
backgroundSize: "6px 3px",
|
|
725
|
+
backgroundPosition: "left bottom",
|
|
726
|
+
backgroundRepeat: "no-repeat"
|
|
727
|
+
},
|
|
728
|
+
".cm-lintRange-warning": {
|
|
729
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23d97706" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
730
|
+
backgroundSize: "6px 3px",
|
|
731
|
+
backgroundPosition: "left bottom",
|
|
732
|
+
backgroundRepeat: "no-repeat"
|
|
733
|
+
},
|
|
734
|
+
".cm-lintRange-error": {
|
|
735
|
+
backgroundImage: 'url("data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="6" height="3"%3E%3Cpath d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="%23dc2626" fill="none" stroke-width="1"/%3E%3C/svg%3E") !important',
|
|
736
|
+
backgroundSize: "6px 3px",
|
|
737
|
+
backgroundPosition: "left bottom",
|
|
738
|
+
backgroundRepeat: "no-repeat"
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
{ dark: false }
|
|
742
|
+
);
|
|
743
|
+
var highlightStyle2 = HighlightStyle2.define([
|
|
744
|
+
{ tag: t3.keyword, color: "var(--color-error-600, #dc2626)" },
|
|
745
|
+
{ tag: [t3.meta, t3.attributeName], color: "var(--color-primary-600, #2563eb)" },
|
|
746
|
+
{ tag: [t3.constant(t3.name), t3.character, t3.number], color: "var(--color-neutral-600, #52525b)" },
|
|
747
|
+
{ tag: t3.invalid, color: "var(--color-error-700, #b91c1c)", backgroundColor: "var(--color-error-100, #fee2e2)" },
|
|
748
|
+
{ tag: t3.string, color: "var(--color-neutral-700, #3f3f46)" },
|
|
749
|
+
{ tag: [t3.comment, t3.lineComment], fontStyle: "italic", color: "#4d9f68" },
|
|
750
|
+
{ tag: t3.heading, color: "var(--color-primary-600, #2563eb)" }
|
|
751
|
+
]);
|
|
752
|
+
var lightTheme = [editorTheme2, syntaxHighlighting2(highlightStyle2)];
|
|
753
|
+
|
|
754
|
+
// src/themes/index.ts
|
|
755
|
+
function themeExtension(name) {
|
|
756
|
+
return [baseTheme, ...name === "dark" ? darkTheme : lightTheme];
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/index.ts
|
|
760
|
+
function createChordProEditor(options) {
|
|
761
|
+
const themeCompartment = new Compartment();
|
|
762
|
+
const updateListener = EditorView5.updateListener.of((update) => {
|
|
763
|
+
if (update.docChanged) {
|
|
764
|
+
options.onChange?.(update.state.doc.toString());
|
|
765
|
+
}
|
|
766
|
+
if (update.focusChanged) {
|
|
767
|
+
(update.view.hasFocus ? options.onFocus : options.onBlur)?.();
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
const state = EditorState2.create({
|
|
771
|
+
doc: options.doc ?? "",
|
|
772
|
+
extensions: [
|
|
773
|
+
basicSetup(),
|
|
774
|
+
chordPro(),
|
|
775
|
+
chordProFolding,
|
|
776
|
+
duplicateDirectiveLinter,
|
|
777
|
+
parserWarningLinter,
|
|
778
|
+
chordNotationLinter,
|
|
779
|
+
chordProAutocomplete(),
|
|
780
|
+
themeCompartment.of(themeExtension(options.theme ?? "light")),
|
|
781
|
+
updateListener,
|
|
782
|
+
...options.extensions ?? []
|
|
783
|
+
]
|
|
784
|
+
});
|
|
785
|
+
const view = new EditorView5({ state, parent: options.parent });
|
|
786
|
+
return {
|
|
787
|
+
view,
|
|
788
|
+
getValue: () => view.state.doc.toString(),
|
|
789
|
+
setValue: (value) => {
|
|
790
|
+
view.dispatch({
|
|
791
|
+
changes: { from: 0, to: view.state.doc.length, insert: value }
|
|
792
|
+
});
|
|
793
|
+
},
|
|
794
|
+
setTheme: (theme) => {
|
|
795
|
+
view.dispatch({ effects: themeCompartment.reconfigure(themeExtension(theme)) });
|
|
796
|
+
},
|
|
797
|
+
insertChord: () => {
|
|
798
|
+
insertChord(view);
|
|
799
|
+
},
|
|
800
|
+
openCompletionList: () => {
|
|
801
|
+
openCompletionList(view);
|
|
802
|
+
},
|
|
803
|
+
getChordNotationSuggestions: () => getChordNotationSuggestions(view.state.doc.toString()),
|
|
804
|
+
normalizeChordNotation: () => {
|
|
805
|
+
const content = view.state.doc.toString();
|
|
806
|
+
const normalization = normalizeChordNotationText(content);
|
|
807
|
+
const replacements = findChordNotationReplacements(content);
|
|
808
|
+
if (replacements.length > 0) {
|
|
809
|
+
view.dispatch({
|
|
810
|
+
changes: replacements.map(({ from, to, replacement }) => ({ from, to, insert: `[${replacement}]` }))
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
return normalization.suggestions;
|
|
814
|
+
},
|
|
815
|
+
focus: () => view.focus(),
|
|
816
|
+
destroy: () => view.destroy()
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
export {
|
|
820
|
+
createChordProEditor,
|
|
821
|
+
getChordCompletionPriorities,
|
|
822
|
+
getChordNotationSuggestions,
|
|
823
|
+
normalizeChordNotationText
|
|
824
|
+
};
|
|
825
|
+
//# sourceMappingURL=index.js.map
|