Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate verovio prod and dev #1228

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
440 changes: 440 additions & 0 deletions assets/js/verovio-toolkit-wasm.js

Large diffs are not rendered by default.

303 changes: 0 additions & 303 deletions assets/js/verovio-toolkit.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"scripts": {
"start": "http-server deployment/server/",
"build": "./setup-verovio && rm -rf deployment/server/Neon-gh && webpack --config webpack.config.js && cp -R assets src/workers deployment/server/Neon-gh",
"bundle:pages": "./setup-verovio && rm -rf dist/Neon/Neon-gh && webpack --config webpack.pages-config.js && cp -R assets src/workers dist/Neon/Neon-gh",
"build": "rm -rf deployment/server/Neon-gh && webpack --config webpack.config.js && cp -R assets src/workers deployment/server/Neon-gh",
"bundle:pages": "rm -rf dist/Neon/Neon-gh && webpack --config webpack.pages-config.js && cp -R assets src/workers dist/Neon/Neon-gh",
"dev": "webpack --config webpack.dev.config.js",
"doc": "typedoc --out ./doc --mode modules ./src",
"cypress:open": "cypress open",
Expand Down Expand Up @@ -94,7 +94,6 @@
"typedoc": "^0.18.0",
"typescript": "4.6.4",
"uuid": "^8.3.0",
"verovio-dev": "file:./verovio-util/verovio-dev",
"webpack": "^4.12.0",
"webpack-command": "^0.5.0",
"webpack-dev-server": "^4.9.0",
Expand Down
13 changes: 0 additions & 13 deletions setup-verovio

This file was deleted.

20 changes: 15 additions & 5 deletions src/VerovioWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import { VerovioMessage } from './Types';


/**
* A wrapper around the verovio web worker to permit mocking in tests.
*/
export default class VerovioWrapper {
verovioWorker: Worker;
constructor () {
this.verovioWorker = new Worker(__ASSET_PREFIX__ + 'workers/VerovioWorker.js');
constructor() {
if (process.env.NODE_ENV === 'production') {
this.verovioWorker = new Worker(
__ASSET_PREFIX__ + 'workers/VerovioWorker.js'
);
} else {
this.verovioWorker = new Worker(
__ASSET_PREFIX__ + 'workers/VerovioWorker-dev.js'
);
}
}

/**
* Set an event listener onto the actual web worker.
*/
addEventListener (type: string, handler: EventListenerOrEventListenerObject): void {
addEventListener(
type: string,
handler: EventListenerOrEventListenerObject
): void {
return this.verovioWorker.addEventListener(type, handler);
}

/**
* Send a message to the actual web worker.
*/
postMessage (message: VerovioMessage): void {
postMessage(message: VerovioMessage): void {
return this.verovioWorker.postMessage(message);
}
}
69 changes: 69 additions & 0 deletions src/workers/VerovioWorker-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
importScripts('../assets/js/verovio-toolkit-wasm.js');

let toolkit;
const backlog = [];

/**
* Parse and respond to messages sent by NeonCore.
* @param {MessageEvent} evt
*/
function handleNeonEvent (evt) {
const data = evt.data;
const result = {
id: data.id
};

switch (data.action) {
case 'renderData':
result.svg = toolkit.renderData(data.mei, {});
break;
case 'getElementAttr':
result.attributes = toolkit.getElementAttr(data.elementId);
break;
case 'edit':
result.result = toolkit.edit(data.editorAction);
break;
case 'getMEI':
result.mei = toolkit.getMEI({
pageNo: 0,
scoreBased: true
});
break;
case 'editInfo':
result.info = toolkit.editInfo();
break;
case 'renderToSVG':
result.svg = toolkit.renderToSVG(1);
break;
default:
break;
}
postMessage(result);
}


verovio.module.onRuntimeInitialized = function () {

toolkit = new verovio.toolkit();
toolkit.setOptions({
inputFrom: 'mei',
footer: 'none',
header: 'none',
pageMarginLeft: 0,
pageMarginTop: 0,
font: 'Bravura',
useFacsimile: false,
});
console.debug('READY');
onmessage = handleNeonEvent;
for (const message of backlog) {
handleNeonEvent(message);
}
}


function tempHandler (evt) {
backlog.push(evt);
}

onmessage = tempHandler;
2 changes: 1 addition & 1 deletion test/VerovioWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VerovioMessage, VerovioResponse } from '../src/Types';
import * as verovio from 'verovio-dev';
import verovio from '../assets/js/verovio-toolkit-wasm.js'

/**
* Wrapper to be used during tests when Web Workers are not available.
Expand Down
309 changes: 0 additions & 309 deletions verovio-util/verovio-dev/index.js

This file was deleted.

27 changes: 0 additions & 27 deletions verovio-util/verovio-dev/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions verovio-util/verovio-js-start.js

This file was deleted.

6 changes: 0 additions & 6 deletions verovio-util/verovio-npm-end.js

This file was deleted.

2 changes: 0 additions & 2 deletions verovio-util/verovio-npm-start.js

This file was deleted.

Loading
Loading