hyperbook 0.94.0 → 0.95.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.
- package/dist/assets/codemirror/codemirror.bundle.js +26 -0
- package/dist/assets/directive-abc-music/client.js +42 -42
- package/dist/assets/directive-abc-music/style.css +6 -0
- package/dist/assets/directive-openscad/client.js +350 -219
- package/dist/assets/directive-openscad/style.css +59 -4
- package/dist/assets/directive-openscad/worker.js +310 -0
- package/dist/assets/directive-p5/client.js +27 -26
- package/dist/assets/directive-p5/style.css +12 -6
- package/dist/assets/directive-pyide/client.js +37 -40
- package/dist/assets/directive-pyide/style.css +12 -6
- package/dist/assets/directive-typst/client.js +20 -55
- package/dist/assets/directive-typst/style.css +12 -6
- package/dist/assets/directive-webide/client.js +45 -79
- package/dist/assets/directive-webide/style.css +12 -6
- package/dist/index.js +37 -71
- package/dist/locales/de.json +1 -0
- package/dist/locales/en.json +1 -0
- package/package.json +4 -4
- package/dist/assets/code-input/auto-close-brackets.min.js +0 -1
- package/dist/assets/code-input/code-input.min.css +0 -1
- package/dist/assets/code-input/code-input.min.js +0 -12
- package/dist/assets/code-input/indent.min.js +0 -1
|
@@ -7,34 +7,41 @@
|
|
|
7
7
|
* @see hyperbook.store
|
|
8
8
|
*/
|
|
9
9
|
hyperbook.abc = (function () {
|
|
10
|
-
window.codeInput?.registerTemplate(
|
|
11
|
-
"abc-highlighted",
|
|
12
|
-
codeInput.templates.prism(window.Prism, [
|
|
13
|
-
new codeInput.plugins.Indent(true, 2),
|
|
14
|
-
])
|
|
15
|
-
);
|
|
16
|
-
|
|
17
10
|
const initABC = async (el) => {
|
|
18
11
|
const tuneEl = el.getElementsByClassName("tune")[0];
|
|
19
12
|
const playerEl = el.getElementsByClassName("player")[0];
|
|
20
13
|
|
|
21
14
|
const tune = atob(el.getAttribute("data-tune"));
|
|
22
|
-
const
|
|
15
|
+
const isEditor = el.getAttribute("data-editor") === "true";
|
|
23
16
|
|
|
24
|
-
if (
|
|
25
|
-
/**
|
|
26
|
-
* @type {HTMLTextAreaElement}
|
|
27
|
-
*/
|
|
17
|
+
if (isEditor) {
|
|
28
18
|
const editorEl = el.getElementsByClassName("editor")[0];
|
|
29
|
-
const id = editorEl.id;
|
|
19
|
+
const id = el.getAttribute("data-id") || editorEl.id;
|
|
30
20
|
|
|
31
21
|
const copyEl = el.getElementsByClassName("copy")[0];
|
|
32
22
|
const resetEl = el.getElementsByClassName("reset")[0];
|
|
33
23
|
const downloadEl = el.getElementsByClassName("download")[0];
|
|
34
24
|
|
|
25
|
+
// Restore saved tune or use default
|
|
26
|
+
const storeResult = await hyperbook.store.db.abcMusic
|
|
27
|
+
.where("id")
|
|
28
|
+
.equals(id)
|
|
29
|
+
.first();
|
|
30
|
+
const initialTune = storeResult?.tune || tune;
|
|
31
|
+
|
|
32
|
+
editorEl.textContent = "";
|
|
33
|
+
const cm = HyperbookCM.create(editorEl, {
|
|
34
|
+
lang: "default",
|
|
35
|
+
value: initialTune,
|
|
36
|
+
onChange: (code) => {
|
|
37
|
+
hyperbook.store.db.abcMusic.put({ id, tune: code });
|
|
38
|
+
renderAndPlay(code);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
35
42
|
copyEl?.addEventListener("click", async () => {
|
|
36
43
|
try {
|
|
37
|
-
await navigator.clipboard.writeText(
|
|
44
|
+
await navigator.clipboard.writeText(cm.getValue());
|
|
38
45
|
} catch (error) {
|
|
39
46
|
console.error(error.message);
|
|
40
47
|
}
|
|
@@ -47,43 +54,36 @@ hyperbook.abc = (function () {
|
|
|
47
54
|
|
|
48
55
|
downloadEl?.addEventListener("click", () => {
|
|
49
56
|
const a = document.createElement("a");
|
|
50
|
-
const blob = new Blob([
|
|
57
|
+
const blob = new Blob([cm.getValue()], { type: "text/plain" });
|
|
51
58
|
a.href = URL.createObjectURL(blob);
|
|
52
59
|
a.download = `tones-${id}.abc`;
|
|
53
60
|
a.click();
|
|
54
61
|
});
|
|
55
62
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
el
|
|
67
|
-
options: {
|
|
63
|
+
// Render initial notation + player
|
|
64
|
+
const renderAndPlay = (abcText) => {
|
|
65
|
+
const visualObj = ABCJS.renderAbc(tuneEl, abcText, {
|
|
66
|
+
responsive: "resize",
|
|
67
|
+
selectTypes: false,
|
|
68
|
+
selectionColor: "currentColor",
|
|
69
|
+
})[0];
|
|
70
|
+
if (ABCJS.synth.supportsAudio()) {
|
|
71
|
+
if (!el._synthControl) {
|
|
72
|
+
el._synthControl = new ABCJS.synth.SynthController();
|
|
73
|
+
el._synthControl.load(playerEl, null, {
|
|
68
74
|
displayRestart: true,
|
|
69
75
|
displayPlay: true,
|
|
70
76
|
displayProgress: true,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
el._synthControl.setTune(visualObj, false);
|
|
80
|
+
} else {
|
|
81
|
+
playerEl.innerHTML =
|
|
82
|
+
"<div class='audio-error'>Audio is not supported in this browser.</div>";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
hyperbook.store.db.abcMusic.put({
|
|
82
|
-
id: editorEl.id,
|
|
83
|
-
tune: editorEl.value,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
86
|
+
renderAndPlay(initialTune);
|
|
87
87
|
} else {
|
|
88
88
|
const visualObj = ABCJS.renderAbc(tuneEl, tune, {
|
|
89
89
|
responsive: "resize",
|