starry / backend /omr /dist /worker.js
k-l-lambda's picture
fix: guard scrollIntoView for multi-page predict
12d235a
(function(){"use strict";var environment$2={exports:{}},requireFoolWebpack$1=eval("typeof require !== 'undefined' ? require : function (module) { throw new Error('Module \" + module + \" not found.') }"),requireFoolWebpack_1=requireFoolWebpack$1;function Promise$2(e,t){var r=this;if(!(this instanceof Promise$2))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof e)throw new SyntaxError("Function parameter handler(resolve, reject) missing");var n=[],s=[];this.resolved=!1,this.rejected=!1,this.pending=!0;var i=function(e,t){n.push(e),s.push(t)};this.then=function(e,t){return new Promise$2(function(r,n){var s=e?_then(e,r,n):r,o=t?_then(t,r,n):n;i(s,o)},r)};var o=function(e){return r.resolved=!0,r.rejected=!1,r.pending=!1,n.forEach(function(t){t(e)}),i=function(t,r){t(e)},o=a=function(){},r},a=function(e){return r.resolved=!1,r.rejected=!0,r.pending=!1,s.forEach(function(t){t(e)}),i=function(t,r){r(e)},o=a=function(){},r};this.cancel=function(){return t?t.cancel():a(new CancellationError),r},this.timeout=function(e){if(t)t.timeout(e);else{var n=setTimeout(function(){a(new TimeoutError("Promise timed out after "+e+" ms"))},e);r.always(function(){clearTimeout(n)})}return r},e(function(e){o(e)},function(e){a(e)})}function _then(e,t,r){return function(n){try{var s=e(n);s&&"function"==typeof s.then&&"function"==typeof s.catch?s.then(t,r):t(s)}catch(e){r(e)}}}function CancellationError(e){this.message=e||"promise cancelled",this.stack=(new Error).stack}function TimeoutError(e){this.message=e||"timeout exceeded",this.stack=(new Error).stack}!function(e){var t=requireFoolWebpack_1,r=function(e){return void 0!==e&&null!=e.versions&&null!=e.versions.node};e.exports.isNode=r,e.exports.platform="undefined"!=typeof process&&r(process)?"node":"browser";var n=function(e){try{return t(e)}catch(e){return null}}("worker_threads");e.exports.isMainThread="node"===e.exports.platform?(!n||n.isMainThread)&&!process.connected:"undefined"!=typeof Window,e.exports.cpus="browser"===e.exports.platform?self.navigator.hardwareConcurrency:t("os").cpus().length}(environment$2),Promise$2.prototype.catch=function(e){return this.then(null,e)},Promise$2.prototype.always=function(e){return this.then(e,e)},Promise$2.all=function(e){return new Promise$2(function(t,r){var n=e.length,s=[];n?e.forEach(function(e,i){e.then(function(e){s[i]=e,0==--n&&t(s)},function(e){n=0,r(e)})}):t(s)})},Promise$2.defer=function(){var e={};return e.promise=new Promise$2(function(t,r){e.resolve=t,e.reject=r}),e},CancellationError.prototype=new Error,CancellationError.prototype.constructor=Error,CancellationError.prototype.name="CancellationError",Promise$2.CancellationError=CancellationError,TimeoutError.prototype=new Error,TimeoutError.prototype.constructor=Error,TimeoutError.prototype.name="TimeoutError",Promise$2.TimeoutError=TimeoutError;var _Promise=Promise$2,WorkerHandler$1={exports:{}},embeddedWorker='!function(){var __webpack_modules__={577:function(e){e.exports=function(e,r){this.message=e,this.transfer=r}}},__webpack_module_cache__={};function __webpack_require__(e){var r=__webpack_module_cache__[e];return void 0!==r||(r=__webpack_module_cache__[e]={exports:{}},__webpack_modules__[e](r,r.exports,__webpack_require__)),r.exports}var __webpack_exports__={};!function(){var exports=__webpack_exports__,__webpack_unused_export__;function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var Transfer=__webpack_require__(577),requireFoolWebpack=eval("typeof require !== \'undefined\' ? require : function (module) { throw new Error(\'Module \\" + module + \\" not found.\') }"),TERMINATE_METHOD_ID="__workerpool-terminate__",worker={exit:function(){}},WorkerThreads,parentPort;if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(e,r){addEventListener(e,function(e){r(e.data)})},worker.send=function(e){postMessage(e)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");try{WorkerThreads=requireFoolWebpack("worker_threads")}catch(error){if("object"!==_typeof(error)||null===error||"MODULE_NOT_FOUND"!==error.code)throw error}WorkerThreads&&null!==WorkerThreads.parentPort?(parentPort=WorkerThreads.parentPort,worker.send=parentPort.postMessage.bind(parentPort),worker.on=parentPort.on.bind(parentPort)):(worker.on=process.on.bind(process),worker.send=function(e){process.send(e)},worker.on("disconnect",function(){process.exit(1)})),worker.exit=process.exit.bind(process)}function convertError(o){return Object.getOwnPropertyNames(o).reduce(function(e,r){return Object.defineProperty(e,r,{value:o[r],enumerable:!0})},{})}function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}worker.methods={},worker.methods.run=function(e,r){e=new Function("return ("+e+").apply(null, arguments);");return e.apply(e,r)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.terminationHandler=void 0,worker.cleanupAndExit=function(e){function r(){worker.exit(e)}if(!worker.terminationHandler)return r();var o=worker.terminationHandler(e);isPromise(o)?o.then(r,r):r()};var currentRequestId=null;worker.on("message",function(r){if(r===TERMINATE_METHOD_ID)return worker.cleanupAndExit(0);try{var e=worker.methods[r.method];if(!e)throw new Error(\'Unknown method "\'+r.method+\'"\');currentRequestId=r.id;var o=e.apply(e,r.params);isPromise(o)?o.then(function(e){e instanceof Transfer?worker.send({id:r.id,result:e.message,error:null},e.transfer):worker.send({id:r.id,result:e,error:null}),currentRequestId=null}).catch(function(e){worker.send({id:r.id,result:null,error:convertError(e)}),currentRequestId=null}):(o instanceof Transfer?worker.send({id:r.id,result:o.message,error:null},o.transfer):worker.send({id:r.id,result:o,error:null}),currentRequestId=null)}catch(e){worker.send({id:r.id,result:null,error:convertError(e)})}}),worker.register=function(e,r){if(e)for(var o in e)e.hasOwnProperty(o)&&(worker.methods[o]=e[o]);r&&(worker.terminationHandler=r.onTerminate),worker.send("ready")},worker.emit=function(e){currentRequestId&&(e instanceof Transfer?worker.send({id:currentRequestId,isEvent:!0,payload:e.message},e.transfer):worker.send({id:currentRequestId,isEvent:!0,payload:e}))},__webpack_unused_export__=worker.register,worker.emit}()}();',Promise$1=_Promise,environment$1=environment$2.exports,requireFoolWebpack=requireFoolWebpack_1,TERMINATE_METHOD_ID="__workerpool-terminate__";function ensureWorkerThreads(){var e=tryRequireWorkerThreads();if(!e)throw new Error("WorkerPool: workerType = 'thread' is not supported, Node >= 11.7.0 required");return e}function ensureWebWorker(){if("function"!=typeof Worker&&("object"!=typeof Worker||"function"!=typeof Worker.prototype.constructor))throw new Error("WorkerPool: Web Workers not supported")}function tryRequireWorkerThreads(){try{return requireFoolWebpack("worker_threads")}catch(e){if("object"==typeof e&&null!==e&&"MODULE_NOT_FOUND"===e.code)return null;throw e}}function getDefaultWorker(){if("browser"===environment$1.platform){if("undefined"==typeof Blob)throw new Error("Blob not supported by the browser");if(!window.URL||"function"!=typeof window.URL.createObjectURL)throw new Error("URL.createObjectURL not supported by the browser");var e=new Blob([embeddedWorker],{type:"text/javascript"});return window.URL.createObjectURL(e)}return __dirname+"/worker.js"}function setupWorker(e,t){if("web"===t.workerType)return ensureWebWorker(),setupBrowserWorker(e,t.workerOpts,Worker);if("thread"===t.workerType)return setupWorkerThreadWorker(e,r=ensureWorkerThreads(),t.workerThreadOpts);if("process"!==t.workerType&&t.workerType){if("browser"===environment$1.platform)return ensureWebWorker(),setupBrowserWorker(e,t.workerOpts,Worker);var r=tryRequireWorkerThreads();return r?setupWorkerThreadWorker(e,r,t.workerThreadOpts):setupProcessWorker(e,resolveForkOptions(t),requireFoolWebpack("child_process"))}return setupProcessWorker(e,resolveForkOptions(t),requireFoolWebpack("child_process"))}function setupBrowserWorker(e,t,r){var n=new r(e,t);return n.isBrowserWorker=!0,n.on=function(e,t){this.addEventListener(e,function(e){t(e.data)})},n.send=function(e,t){this.postMessage(e,t)},n}function setupWorkerThreadWorker(e,t,r){var n=new t.Worker(e,{stdout:!1,stderr:!1,...r});return n.isWorkerThread=!0,n.send=function(e,t){this.postMessage(e,t)},n.kill=function(){return this.terminate(),!0},n.disconnect=function(){this.terminate()},n}function setupProcessWorker(e,t,r){var n=r.fork(e,t.forkArgs,t.forkOpts),s=n.send;return n.send=function(e){return s.call(n,e)},n.isChildProcess=!0,n}function resolveForkOptions(e){e=e||{};var t=process.execArgv.join(" "),r=-1!==t.indexOf("--inspect"),n=-1!==t.indexOf("--debug-brk"),s=[];return r&&(s.push("--inspect="+e.debugPort),n&&s.push("--debug-brk")),process.execArgv.forEach(function(e){e.indexOf("--max-old-space-size")>-1&&s.push(e)}),Object.assign({},e,{forkArgs:e.forkArgs,forkOpts:Object.assign({},e.forkOpts,{execArgv:(e.forkOpts&&e.forkOpts.execArgv||[]).concat(s)})})}function objectToError(e){for(var t=new Error(""),r=Object.keys(e),n=0;n<r.length;n++)t[r[n]]=e[r[n]];return t}function WorkerHandler(e,t){var r=this,n=t||{};function s(e){for(var t in r.terminated=!0,r.processing)void 0!==r.processing[t]&&r.processing[t].resolver.reject(e);r.processing=Object.create(null)}this.script=e||getDefaultWorker(),this.worker=setupWorker(this.script,n),this.debugPort=n.debugPort,this.forkOpts=n.forkOpts,this.forkArgs=n.forkArgs,this.workerOpts=n.workerOpts,this.workerThreadOpts=n.workerThreadOpts,this.workerTerminateTimeout=n.workerTerminateTimeout,e||(this.worker.ready=!0),this.requestQueue=[],this.worker.on("message",function(e){if(!r.terminated)if("string"==typeof e&&"ready"===e)r.worker.ready=!0,function(){for(const e of r.requestQueue.splice(0))r.worker.send(e.message,e.transfer)}();else{var t=e.id,n=r.processing[t];void 0!==n&&(e.isEvent?n.options&&"function"==typeof n.options.on&&n.options.on(e.payload):(delete r.processing[t],!0===r.terminating&&r.terminate(),e.error?n.resolver.reject(objectToError(e.error)):n.resolver.resolve(e.result)))}});var i=this.worker;this.worker.on("error",s),this.worker.on("exit",function(e,t){var n="Workerpool Worker terminated Unexpectedly\n";n+=" exitCode: `"+e+"`\n",n+=" signalCode: `"+t+"`\n",n+=" workerpool.script: `"+r.script+"`\n",n+=" spawnArgs: `"+i.spawnargs+"`\n",n+=" spawnfile: `"+i.spawnfile+"`\n",n+=" stdout: `"+i.stdout+"`\n",n+=" stderr: `"+i.stderr+"`\n",s(new Error(n))}),this.processing=Object.create(null),this.terminating=!1,this.terminated=!1,this.cleaning=!1,this.terminationHandler=null,this.lastId=0}WorkerHandler.prototype.methods=function(){return this.exec("methods")},WorkerHandler.prototype.exec=function(e,t,r,n){r||(r=Promise$1.defer());var s=++this.lastId;this.processing[s]={id:s,resolver:r,options:n};var i={message:{id:s,method:e,params:t},transfer:n&&n.transfer};this.terminated?r.reject(new Error("Worker is terminated")):this.worker.ready?this.worker.send(i.message,i.transfer):this.requestQueue.push(i);var o=this;return r.promise.catch(function(e){if(e instanceof Promise$1.CancellationError||e instanceof Promise$1.TimeoutError)return delete o.processing[s],o.terminateAndNotify(!0).then(function(){throw e},function(e){throw e});throw e})},WorkerHandler.prototype.busy=function(){return this.cleaning||Object.keys(this.processing).length>0},WorkerHandler.prototype.terminate=function(e,t){var r=this;if(e){for(var n in this.processing)void 0!==this.processing[n]&&this.processing[n].resolver.reject(new Error("Worker terminated"));this.processing=Object.create(null)}if("function"==typeof t&&(this.terminationHandler=t),this.busy())this.terminating=!0;else{var s=function(e){if(r.terminated=!0,r.cleaning=!1,null!=r.worker&&r.worker.removeAllListeners&&r.worker.removeAllListeners("message"),r.worker=null,r.terminating=!1,r.terminationHandler)r.terminationHandler(e,r);else if(e)throw e};if(this.worker){if("function"==typeof this.worker.kill){if(this.worker.killed)return void s(new Error("worker already killed!"));var i=setTimeout(function(){r.worker&&r.worker.kill()},this.workerTerminateTimeout);return this.worker.once("exit",function(){clearTimeout(i),r.worker&&(r.worker.killed=!0),s()}),this.worker.ready?this.worker.send(TERMINATE_METHOD_ID):this.requestQueue.push({message:TERMINATE_METHOD_ID}),void(this.cleaning=!0)}if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate(),this.worker.killed=!0}s()}},WorkerHandler.prototype.terminateAndNotify=function(e,t){var r=Promise$1.defer();return t&&r.promise.timeout(t),this.terminate(e,function(e,t){e?r.reject(e):r.resolve(t)}),r.promise},WorkerHandler$1.exports=WorkerHandler,WorkerHandler$1.exports._tryRequireWorkerThreads=tryRequireWorkerThreads,WorkerHandler$1.exports._setupProcessWorker=setupProcessWorker,WorkerHandler$1.exports._setupBrowserWorker=setupBrowserWorker,WorkerHandler$1.exports._setupWorkerThreadWorker=setupWorkerThreadWorker,WorkerHandler$1.exports.ensureWorkerThreads=ensureWorkerThreads;var worker$1={};function Transfer(e,t){this.message=e,this.transfer=t}var transfer=Transfer;(function(exports){var Transfer=transfer,requireFoolWebpack=eval("typeof require !== 'undefined' ? require : function (module) { throw new Error('Module \" + module + \" not found.') }"),TERMINATE_METHOD_ID="__workerpool-terminate__",worker={exit:function(){}};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(e,t){addEventListener(e,function(e){t(e.data)})},worker.send=function(e){postMessage(e)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");var WorkerThreads;try{WorkerThreads=requireFoolWebpack("worker_threads")}catch(e){if("object"!=typeof e||null===e||"MODULE_NOT_FOUND"!==e.code)throw e}if(WorkerThreads&&null!==WorkerThreads.parentPort){var parentPort=WorkerThreads.parentPort;worker.send=parentPort.postMessage.bind(parentPort),worker.on=parentPort.on.bind(parentPort),worker.exit=process.exit.bind(process)}else worker.on=process.on.bind(process),worker.send=function(e){process.send(e)},worker.on("disconnect",function(){process.exit(1)}),worker.exit=process.exit.bind(process)}function convertError(e){return Object.getOwnPropertyNames(e).reduce(function(t,r){return Object.defineProperty(t,r,{value:e[r],enumerable:!0})},{})}function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}worker.methods={},worker.methods.run=function(e,t){var r=new Function("return ("+e+").apply(null, arguments);");return r.apply(r,t)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.terminationHandler=void 0,worker.cleanupAndExit=function(e){var t=function(){worker.exit(e)};if(!worker.terminationHandler)return t();var r=worker.terminationHandler(e);isPromise(r)?r.then(t,t):t()};var currentRequestId=null;worker.on("message",function(e){if(e===TERMINATE_METHOD_ID)return worker.cleanupAndExit(0);try{var t=worker.methods[e.method];if(!t)throw new Error('Unknown method "'+e.method+'"');currentRequestId=e.id;var r=t.apply(t,e.params);isPromise(r)?r.then(function(t){t instanceof Transfer?worker.send({id:e.id,result:t.message,error:null},t.transfer):worker.send({id:e.id,result:t,error:null}),currentRequestId=null}).catch(function(t){worker.send({id:e.id,result:null,error:convertError(t)}),currentRequestId=null}):(r instanceof Transfer?worker.send({id:e.id,result:r.message,error:null},r.transfer):worker.send({id:e.id,result:r,error:null}),currentRequestId=null)}catch(t){worker.send({id:e.id,result:null,error:convertError(t)})}}),worker.register=function(e,t){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r]);t&&(worker.terminationHandler=t.onTerminate),worker.send("ready")},worker.emit=function(e){if(currentRequestId){if(e instanceof Transfer)return void worker.send({id:currentRequestId,isEvent:!0,payload:e.message},e.transfer);worker.send({id:currentRequestId,isEvent:!0,payload:e})}},exports.add=worker.register,exports.emit=worker.emit})(worker$1);var environment=environment$2.exports,worker=function(e,t){var r=worker$1;r.add(e,t)};environment.platform,environment.isMainThread,environment.cpus;var Sylvester={Matrix:function(){}};Sylvester.Matrix.create=function(e){return(new Sylvester.Matrix).setElements(e)},Sylvester.Matrix.I=function(e){for(var t,r=[],n=e;n--;)for(t=e,r[n]=[];t--;)r[n][t]=n===t?1:0;return Sylvester.Matrix.create(r)},Sylvester.Matrix.prototype={dup:function(){return Sylvester.Matrix.create(this.elements)},isSquare:function(){var e=0===this.elements.length?0:this.elements[0].length;return this.elements.length===e},toRightTriangular:function(){if(0===this.elements.length)return Sylvester.Matrix.create([]);var e,t,r,n,s=this.dup(),i=this.elements.length,o=this.elements[0].length;for(t=0;t<i;t++){if(0===s.elements[t][t])for(r=t+1;r<i;r++)if(0!==s.elements[r][t]){for(e=[],n=0;n<o;n++)e.push(s.elements[t][n]+s.elements[r][n]);s.elements[t]=e;break}if(0!==s.elements[t][t])for(r=t+1;r<i;r++){var a=s.elements[r][t]/s.elements[t][t];for(e=[],n=0;n<o;n++)e.push(n<=t?0:s.elements[r][n]-s.elements[t][n]*a);s.elements[r]=e}}return s},determinant:function(){if(0===this.elements.length)return 1;if(!this.isSquare())return null;for(var e=this.toRightTriangular(),t=e.elements[0][0],r=e.elements.length,n=1;n<r;n++)t*=e.elements[n][n];return t},isSingular:function(){return this.isSquare()&&0===this.determinant()},augment:function(e){if(0===this.elements.length)return this.dup();var t=e.elements||e;void 0===t[0][0]&&(t=Sylvester.Matrix.create(t).elements);var r,n=this.dup(),s=n.elements[0].length,i=n.elements.length,o=t[0].length;if(i!==t.length)return null;for(;i--;)for(r=o;r--;)n.elements[i][s+r]=t[i][r];return n},inverse:function(){if(0===this.elements.length)return null;if(!this.isSquare()||this.isSingular())return null;for(var e,t,r,n,s,i=this.elements.length,o=i,a=this.augment(Sylvester.Matrix.I(i)).toRightTriangular(),c=a.elements[0].length,l=[];o--;){for(r=[],l[o]=[],n=a.elements[o][o],t=0;t<c;t++)s=a.elements[o][t]/n,r.push(s),t>=i&&l[o].push(s);for(a.elements[o]=r,e=o;e--;){for(r=[],t=0;t<c;t++)r.push(a.elements[e][t]-a.elements[o][t]*a.elements[e][o]);a.elements[e]=r}}return Sylvester.Matrix.create(l)},setElements:function(e){var t,r,n=e.elements||e;if(n[0]&&void 0!==n[0][0]){for(t=n.length,this.elements=[];t--;)for(r=n[t].length,this.elements[t]=[];r--;)this.elements[t][r]=n[t][r];return this}var s=n.length;for(this.elements=[],t=0;t<s;t++)this.elements.push([n[t]]);return this}};var matrixInverse=function(e){const t=Sylvester.Matrix.create(e).inverse();return null!==t?t.elements:null},sha1={exports:{}},SemanticType;
/*
* [js-sha1]{@link https://github.com/emn178/js-sha1}
*
* @version 0.6.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
(function(module){(function(){var root="object"==typeof window?window:{},NODE_JS=!root.JS_SHA1_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;NODE_JS&&(root=global);var COMMON_JS=!root.JS_SHA1_NO_COMMON_JS&&module.exports,HEX_CHARS="0123456789abcdef".split(""),EXTRA=[-2147483648,8388608,32768,128],SHIFT=[24,16,8,0],OUTPUT_TYPES=["hex","array","digest","arrayBuffer"],blocks=[],createOutputMethod=function(e){return function(t){return new Sha1(!0).update(t)[e]()}},createMethod=function(){var e=createOutputMethod("hex");NODE_JS&&(e=nodeWrap(e)),e.create=function(){return new Sha1},e.update=function(t){return e.create().update(t)};for(var t=0;t<OUTPUT_TYPES.length;++t){var r=OUTPUT_TYPES[t];e[r]=createOutputMethod(r)}return e},nodeWrap=function(method){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),nodeMethod=function(e){if("string"==typeof e)return crypto.createHash("sha1").update(e,"utf8").digest("hex");if(e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(void 0===e.length)return method(e);return crypto.createHash("sha1").update(new Buffer(e)).digest("hex")};return nodeMethod};function Sha1(e){e?(blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1732584193,this.h1=4023233417,this.h2=2562383102,this.h3=271733878,this.h4=3285377520,this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Sha1.prototype.update=function(e){if(!this.finalized){var t="string"!=typeof e;t&&e.constructor===root.ArrayBuffer&&(e=new Uint8Array(e));for(var r,n,s=0,i=e.length||0,o=this.blocks;s<i;){if(this.hashed&&(this.hashed=!1,o[0]=this.block,o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),t)for(n=this.start;s<i&&n<64;++s)o[n>>2]|=e[s]<<SHIFT[3&n++];else for(n=this.start;s<i&&n<64;++s)(r=e.charCodeAt(s))<128?o[n>>2]|=r<<SHIFT[3&n++]:r<2048?(o[n>>2]|=(192|r>>6)<<SHIFT[3&n++],o[n>>2]|=(128|63&r)<<SHIFT[3&n++]):r<55296||r>=57344?(o[n>>2]|=(224|r>>12)<<SHIFT[3&n++],o[n>>2]|=(128|r>>6&63)<<SHIFT[3&n++],o[n>>2]|=(128|63&r)<<SHIFT[3&n++]):(r=65536+((1023&r)<<10|1023&e.charCodeAt(++s)),o[n>>2]|=(240|r>>18)<<SHIFT[3&n++],o[n>>2]|=(128|r>>12&63)<<SHIFT[3&n++],o[n>>2]|=(128|r>>6&63)<<SHIFT[3&n++],o[n>>2]|=(128|63&r)<<SHIFT[3&n++]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.block=o[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this}},Sha1.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>2]|=EXTRA[3&t],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},Sha1.prototype.hash=function(){var e,t,r=this.h0,n=this.h1,s=this.h2,i=this.h3,o=this.h4,a=this.blocks;for(e=16;e<80;++e)t=a[e-3]^a[e-8]^a[e-14]^a[e-16],a[e]=t<<1|t>>>31;for(e=0;e<20;e+=5)r=(t=(n=(t=(s=(t=(i=(t=(o=(t=r<<5|r>>>27)+(n&s|~n&i)+o+1518500249+a[e]|0)<<5|o>>>27)+(r&(n=n<<30|n>>>2)|~r&s)+i+1518500249+a[e+1]|0)<<5|i>>>27)+(o&(r=r<<30|r>>>2)|~o&n)+s+1518500249+a[e+2]|0)<<5|s>>>27)+(i&(o=o<<30|o>>>2)|~i&r)+n+1518500249+a[e+3]|0)<<5|n>>>27)+(s&(i=i<<30|i>>>2)|~s&o)+r+1518500249+a[e+4]|0,s=s<<30|s>>>2;for(;e<40;e+=5)r=(t=(n=(t=(s=(t=(i=(t=(o=(t=r<<5|r>>>27)+(n^s^i)+o+1859775393+a[e]|0)<<5|o>>>27)+(r^(n=n<<30|n>>>2)^s)+i+1859775393+a[e+1]|0)<<5|i>>>27)+(o^(r=r<<30|r>>>2)^n)+s+1859775393+a[e+2]|0)<<5|s>>>27)+(i^(o=o<<30|o>>>2)^r)+n+1859775393+a[e+3]|0)<<5|n>>>27)+(s^(i=i<<30|i>>>2)^o)+r+1859775393+a[e+4]|0,s=s<<30|s>>>2;for(;e<60;e+=5)r=(t=(n=(t=(s=(t=(i=(t=(o=(t=r<<5|r>>>27)+(n&s|n&i|s&i)+o-1894007588+a[e]|0)<<5|o>>>27)+(r&(n=n<<30|n>>>2)|r&s|n&s)+i-1894007588+a[e+1]|0)<<5|i>>>27)+(o&(r=r<<30|r>>>2)|o&n|r&n)+s-1894007588+a[e+2]|0)<<5|s>>>27)+(i&(o=o<<30|o>>>2)|i&r|o&r)+n-1894007588+a[e+3]|0)<<5|n>>>27)+(s&(i=i<<30|i>>>2)|s&o|i&o)+r-1894007588+a[e+4]|0,s=s<<30|s>>>2;for(;e<80;e+=5)r=(t=(n=(t=(s=(t=(i=(t=(o=(t=r<<5|r>>>27)+(n^s^i)+o-899497514+a[e]|0)<<5|o>>>27)+(r^(n=n<<30|n>>>2)^s)+i-899497514+a[e+1]|0)<<5|i>>>27)+(o^(r=r<<30|r>>>2)^n)+s-899497514+a[e+2]|0)<<5|s>>>27)+(i^(o=o<<30|o>>>2)^r)+n-899497514+a[e+3]|0)<<5|n>>>27)+(s^(i=i<<30|i>>>2)^o)+r-899497514+a[e+4]|0,s=s<<30|s>>>2;this.h0=this.h0+r|0,this.h1=this.h1+n|0,this.h2=this.h2+s|0,this.h3=this.h3+i|0,this.h4=this.h4+o|0},Sha1.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,n=this.h3,s=this.h4;return HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>4&15]+HEX_CHARS[15&e]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[15&t]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[15&r]+HEX_CHARS[n>>28&15]+HEX_CHARS[n>>24&15]+HEX_CHARS[n>>20&15]+HEX_CHARS[n>>16&15]+HEX_CHARS[n>>12&15]+HEX_CHARS[n>>8&15]+HEX_CHARS[n>>4&15]+HEX_CHARS[15&n]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[15&s]},Sha1.prototype.toString=Sha1.prototype.hex,Sha1.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,n=this.h3,s=this.h4;return[e>>24&255,e>>16&255,e>>8&255,255&e,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24&255,r>>16&255,r>>8&255,255&r,n>>24&255,n>>16&255,n>>8&255,255&n,s>>24&255,s>>16&255,s>>8&255,255&s]},Sha1.prototype.array=Sha1.prototype.digest,Sha1.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(20),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),e};var exports=createMethod();COMMON_JS?module.exports=exports:root.sha1=exports})()})(sha1),function(e){e.ClefG="ClefG",e.ClefF="ClefF",e.ClefC="ClefC",e.NoteheadS0="NoteheadS0",e.NoteheadS1="NoteheadS1",e.NoteheadS2="NoteheadS2",e.NoteheadS1stemU="NoteheadS1stemU",e.NoteheadS1stemD="NoteheadS1stemD",e.NoteheadS2stemU="NoteheadS2stemU",e.NoteheadS2stemD="NoteheadS2stemD",e.vline_Stem="vline_Stem",e.Flag3="Flag3",e.BeamLeft="BeamLeft",e.BeamContinue="BeamContinue",e.BeamRight="BeamRight",e.TremoloLeft="TremoloLeft",e.TremoloRight="TremoloRight",e.TremoloMiddle="TremoloMiddle",e.Dot="Dot",e.Rest0="Rest0",e.Rest1="Rest1",e.Rest2="Rest2",e.Rest3="Rest3",e.Rest4="Rest4",e.Rest5="Rest5",e.Rest6="Rest6",e.Rest0W="Rest0W",e.RestM1="RestM1",e.AccNatural="AccNatural",e.AccSharp="AccSharp",e.AccDoublesharp="AccDoublesharp",e.AccFlat="AccFlat",e.AccFlatflat="AccFlatflat",e.vline_VoltaLeft="vline_VoltaLeft",e.vline_VoltaRight="vline_VoltaRight",e.VoltaLeft="VoltaLeft",e.VoltaRight="VoltaRight",e.VoltaAlternativeBegin="VoltaAlternativeBegin",e.BarMeasure="BarMeasure",e.vline_BarMeasure="vline_BarMeasure",e.vline_BarTerminal="vline_BarTerminal",e.vline_BarSegment="vline_BarSegment",e.SlurBegin="SlurBegin",e.SlurEnd="SlurEnd",e.TimesigC44="TimesigC44",e.TimesigC22="TimesigC22",e.TimesigZero="TimesigZero",e.TimesigOne="TimesigOne",e.TimesigTwo="TimesigTwo",e.TimesigThree="TimesigThree",e.TimesigFour="TimesigFour",e.TimesigFive="TimesigFive",e.TimesigSix="TimesigSix",e.TimesigSeven="TimesigSeven",e.TimesigEight="TimesigEight",e.TimesigNine="TimesigNine",e.OctaveShift8va="OctaveShift8va",e.OctaveShift8vb="OctaveShift8vb",e.OctaveShift8="OctaveShift8",e.OctaveShift0="OctaveShift0",e.Zero="Zero",e.One="One",e.Two="Two",e.Three="Three",e.Four="Four",e.Five="Five",e.Six="Six",e.Seven="Seven",e.Eight="Eight",e.Nine="Nine",e.f="f",e.p="p",e.m="m",e.n="n",e.r="r",e.s="s",e.z="z",e.CrescendoBegin="CrescendoBegin",e.CrescendoEnd="CrescendoEnd",e.DecrescendoBegin="DecrescendoBegin",e.DecrescendoEnd="DecrescendoEnd",e.ScriptFermata="ScriptFermata",e.ScriptShortFermata="ScriptShortFermata",e.ScriptSforzato="ScriptSforzato",e.ScriptStaccato="ScriptStaccato",e.ScriptStaccatissimo="ScriptStaccatissimo",e.ScriptTurn="ScriptTurn",e.ScriptTrill="ScriptTrill",e.ScriptSegno="ScriptSegno",e.ScriptCoda="ScriptCoda",e.ScriptArpeggio="ScriptArpeggio",e.ScriptPrall="ScriptPrall",e.ScriptMordent="ScriptMordent",e.ScriptMarcato="ScriptMarcato",e.ScriptTenuto="ScriptTenuto",e.ScriptPortato="ScriptPortato",e.PedalStar="PedalStar",e.PedalPed="PedalPed",e.KeyAcc="KeyAcc",e.TempoNotehead="TempoNotehead",e.GraceNotehead="GraceNotehead",e.SignLined="SignLined",e.SignInterval="SignInterval",e.rect_Text="rect_Text",e.rect_Lyric="rect_Lyric"}(SemanticType||(SemanticType={})),SemanticType.BarMeasure,SemanticType.vline_BarMeasure,SemanticType.vline_BarTerminal,SemanticType.vline_BarSegment,SemanticType.vline_VoltaLeft,SemanticType.vline_VoltaRight,SemanticType.VoltaAlternativeBegin;const st=SemanticType;st.NoteheadS0,st.NoteheadS1,st.NoteheadS2,st.Zero,st.One,st.Two,st.Three,st.Four,st.Five,st.Six,st.Seven,st.Eight,st.Nine,st.ScriptStaccatissimo,st.TimesigZero,st.TimesigOne,st.TimesigTwo,st.TimesigThree,st.TimesigFour,st.TimesigFive,st.TimesigSix,st.TimesigSeven,st.TimesigEight,st.TimesigNine,st.Rest0,st.Rest1,st.Rest2,st.Rest3,st.Rest4,st.Rest5,st.Rest6,st.Rest0W,st.RestM1,st.SignInterval,st.SignLined,st.BeamLeft,st.BeamContinue,st.BeamRight,st.ClefG,st.ClefF,st.ClefC,st.NoteheadS0,st.NoteheadS1,st.NoteheadS2,st.Dot,st.Rest0,st.Rest1,st.Rest2,st.Rest3,st.Rest4,st.Rest5,st.Rest6,st.RestM1,st.AccNatural,st.AccSharp,st.AccDoublesharp,st.AccFlat,st.AccFlatflat,st.TimesigC44,st.TimesigC22,st.TimesigZero,st.TimesigOne,st.TimesigTwo,st.TimesigThree,st.TimesigFour,st.TimesigFive,st.TimesigSix,st.TimesigSeven,st.TimesigEight,st.TimesigNine,st.One,st.Two,st.Three,st.Four,st.Five,st.OctaveShift8,st.OctaveShift0,st.f,st.p,st.m,st.n,st.r,st.s,st.z,st.ScriptFermata,st.ScriptShortFermata,st.ScriptSforzato,st.ScriptStaccato,st.ScriptStaccatissimo,st.ScriptTurn,st.ScriptTrill,st.ScriptSegno,st.ScriptCoda,st.ScriptArpeggio,st.ScriptPrall,st.ScriptMordent,st.ScriptMarcato,st.ScriptTenuto,st.ScriptPortato,st.PedalStar,st.PedalPed;const roundNumber=(e,t,r=-1/0)=>Math.max(Math.round(e/t)*t,r),gcd=(e,t)=>Number.isInteger(e)&&Number.isInteger(t)?0===t?e:gcd(t,e%t):(console.error("non-integer gcd:",e,t),1),frac=(e,t)=>({numerator:e,denominator:t}),reducedFraction=(e,t)=>{e=Math.round(e),t=Math.round(t);const r=0!==e?gcd(e,t):t;return frac(e/r,t/r)},fractionMul=(e,t)=>t?e*t.numerator/t.denominator:e;class DummyLogger{debug(...e){}group(...e){}groupCollapsed(...e){}groupEnd(){}info(...e){}warn(...e){}assert(...e){}}const EOM=-1,GREAT_NUMBER=1920,DURATION_MULTIPLIER=1921920,floatToFrac=e=>{const t=Math.round(e*GREAT_NUMBER);return reducedFraction(t,GREAT_NUMBER)},floatToTimeWarp=e=>1===e?null:floatToFrac(e);var ActionType;!function(e){e[e.PLACE=0]="PLACE",e[e.VERTICAL=1]="VERTICAL",e[e.HORIZONTAL=2]="HORIZONTAL"}(ActionType||(ActionType={}));class Action{constructor(e){Object.assign(this,e)}static P(e){return new Action({type:ActionType.PLACE,e1:e})}static V(e,t,r=1){return new Action({type:ActionType.VERTICAL,e1:r>0?e:t,e2:r>0?t:e})}static H(e,t){return new Action({type:ActionType.HORIZONTAL,e1:e,e2:t})}get id(){switch(this.type){case ActionType.PLACE:return this.e1.toString();case ActionType.VERTICAL:return`${this.e1}|${this.e2}`;case ActionType.HORIZONTAL:return`${this.e1}-${this.e2>=0?this.e2:"."}`}}get events(){return[this.e1,this.e2].filter(Number.isFinite)}}class StageMatrix{static fromNode(e,t){const r=Array(e.stages.length).fill(null).map(()=>Array(e.stages.length).fill(null).map(()=>new Set));e.actions.filter(e=>e.type===ActionType.HORIZONTAL).forEach(t=>{const n=e.stages.findIndex(e=>e.events.includes(t.e1)),s=e.stages.findIndex(e=>e.events.includes(t.e2));console.assert(n>=0&&s>=0,"invalid stages for H action:",e.id,e.stages,t),r[n][s].add(t.e1)}),r[0][e.stages.length-1].add(0);const n=e.stagedEvents,s=t.matrixH[t.matrixH.length-1].filter((e,t)=>!n.has(t)),i=Math.max(0,Math.max(...s)-.01),o=e.actions.filter(e=>e.type===ActionType.HORIZONTAL),a=Object.keys(t.eventMap).map(Number).filter(e=>!o.find(t=>t.e2===e));return e.stages.forEach(n=>{n.events.forEach(s=>{if(s>0){!o.find(e=>e.e1===s)&&t.matrixH[t.matrixH.length-1][s]>=i&&(a.some(e=>t.matrixH[e][s]>0)||r[n.index][e.stages.length-1].add(s))}})}),new StageMatrix({matrix:r})}constructor(e){Object.assign(this,e)}pathOf(e,t,r,n=0){if(this.matrix[e][t].size){const s=[...this.matrix[e][t]][n];if(t===r)return[s];for(let e=t+1;e<=r;++e){const n=this.pathOf(t,e,r);if(n)return[s,...n]}}return null}findDoublePath(e,t){const r=[];for(let n=t;n>=e+1;--n)for(let s=0;s<this.matrix[e][n].size;++s){const i=this.pathOf(e,n,t,s);if(i&&(r.push(i),2===r.length))return[r[0],r[1]]}return null}reducePath(e){this.matrix.forEach(t=>t.forEach(t=>e.forEach(e=>t.delete(e))))}toEquations(e){const t=[];for(let r=1;r<this.matrix.length;r++)for(let n=0;n<this.matrix.length-r;n++){const s=n+r;for(;;){const r=this.findDoublePath(n,s);if(!r)break;{const[n,s]=r,i=Array(e).fill(0);n.forEach(e=>i[e]=1),s.forEach(e=>i[e]=-1),t.push(i),this.reducePath(n.length>s.length?n:s)}}}return t}}class PathNode{constructor(e){Object.assign(this,e),console.assert(this.logger,"logger is null:",e)}get actions(){const e=this.parent?this.parent.actions:[];return this.action?[...e,this.action]:e}get id(){return this.actions.map(e=>e.id).sort().join(" ")}get stagedEvents(){const e=new Set;return this.stages&&this.stages.forEach(t=>t.events.forEach(t=>t>=0&&e.add(t))),e}like(e){return e.split(" ").sort().join(" ")===this.id}constructStages(e){this.stages=[{events:[EOM]}];for(const t of this.actions)switch(t.type){case ActionType.PLACE:this.stages.unshift({events:[t.e1]});break;case ActionType.VERTICAL:{const e=this.stages.find(e=>e.events.includes(t.e1)),r=this.stages.find(e=>e.events.includes(t.e2));console.assert(e||r,"invalid V action:",this.stages,t),e&&r?(e.events.push(...r.events),r.events=null,this.stages=this.stages.filter(e=>e.events)):e?r||e.events.push(t.e2):r.events.unshift(t.e1)}break;case ActionType.HORIZONTAL:{const r=this.stages.find(e=>e.events.includes(t.e1)),n=this.stages.find(e=>e.events.includes(t.e2));console.assert(r||n,"invalid H action:",this.stages,t);const s=r=>{console.assert(e.eventMap[r],"invalid event id:",t.id,r,e.eventMap);const n=e.eventMap[r].x,s=this.stages.find(t=>t.events.some(t=>t>0&&e.eventMap[t].x<=n)&&t.events.some(t=>t>0&&e.eventMap[t].x>=n));if(s)s.events.push(r);else{const t={events:[r]},s=this.stages.findIndex(t=>t.events[0]===EOM||e.eventMap[t.events[0]].x>=n);this.stages.splice(s,0,t)}};r||s(t.e1),n||s(t.e2)}}this.stages.forEach((e,t)=>e.index=t)}constructConstraints(e){const t=Object.keys(e.eventMap).length,r=StageMatrix.fromNode(this,e).toEquations(t),n=Array(t).fill(null).map((t,r)=>e.eventMap[r].duration);this.constraints=r.map(e=>e.map((e,t)=>e*n[t]))}inbalancesConstraints(e){console.assert(this.constraints,"constraints not constructed.");const t=Object.keys(e.eventMap).length,r=Array(t).fill(!0),n=Array(t).fill(!1),s=[];for(const e of this.constraints){const t=e.reduce((e,t)=>e+t,0);if(0!==t){const i=t<0?e.map(e=>-e):e;if(i[0]>0)continue;s.push(i),i.forEach((e,t)=>{n[t]=n[t]||e<0,e&&(r[t]=e<0||n[t])})}}return this.constraints.forEach(e=>{0!==e.reduce((e,t)=>e+t,0)||e[0]||e.some((e,t)=>e&&!r[t])&&(e.forEach((e,t)=>e&&(r[t]=!1)),s.push(e))}),{ones:r,inbalances:s}}solveEquations({ones:e,inbalances:t}){if(!t.length)return e.map(()=>1);const r=e.map((e,t)=>({fixed:e,i:t})).filter(({fixed:e})=>!e).map(({i:e})=>e).filter(e=>t.some(t=>0!==t[e]));if(!r.length)return e.map(()=>1);const n=r.map(e=>Math.abs(t.find(t=>0!==t[e])[e])),s=new Map;let i=!1;const o=t.map(e=>({line:e.filter((e,t)=>r.includes(t)),bias:-e.reduce((e,t,n)=>e+(r.includes(n)?0:t),0)})).filter(({line:e,bias:t})=>{if(e.every(e=>0===e))return!1;const r=e.join(",");return s.has(r)?(i=s.get(r)!==t,!1):(s.set(r,t),!0)});if(i)return null;const a=o.slice(0,r.length),c=o.slice(r.length);if(a.length<r.length){const e=[];for(let t=0;t<r.length-1;++t){const s=t+1,i={line:r.map((e,r)=>r===t?1:r===s?-1:0),bias:0,prior:(n[t]+n[s])/DURATION_MULTIPLIER};a.some(e=>e.line[t]&&e.line[s])&&(i.prior-=10),a.some(e=>1===e.line.filter(Number).length&&(e.line[t]||e.line[s]))&&(i.prior+=1),e.push(i)}e.sort((e,t)=>e.prior-t.prior),a.push(...e.slice(0,r.length-a.length))}const l=a.map(({line:e})=>e),u=a.map(({bias:e})=>e),h=matrixInverse(l);if(!h)return this.logger.warn("null invert:",l),null;const d=h.map(e=>e.reduce((e,t,r)=>e+t*u[r],0));if(c.length&&c.some(e=>Math.abs(e.line.reduce((e,t,r)=>e+t*d[r],0))>.001))return null;const f=e.map(()=>1);return r.forEach((e,t)=>f[e]=d[t]),f}optimallySolve(e){const{ones:t,inbalances:r}=this.inbalancesConstraints(e),n=t.map((t,r)=>t?-1:roundNumber(e.eventMap[r].shrinkness,.01)).reduce((e,t,r)=>(t>=0&&(e[t]=e[t]||[],e[t].push(r)),e),{}),s=Object.entries(n).sort((e,t)=>Number(t[0])-Number(e[0])).map(e=>e[1]);for(let n=1;n<s.length;++n){const i=[].concat(...s.slice(0,n)),o=t.map((e,t)=>!i.includes(t)),a=this.solveEquations({ones:o,inbalances:r});if(a&&a.every((t,r)=>t<=1&&t>e.eventMap[r].lowWarp))return a}return this.solveEquations({ones:t,inbalances:r})}isConflicted(e){const{ones:t,inbalances:r}=this.inbalancesConstraints(e);for(const n of r){if(n.reduce((r,n,s)=>r+n*(t[s]||n<=0?1:e.eventMap[s].lowWarp),0)>=0)return n.forEach((t,r)=>{t&&(e.eventTendencies[r]+=t>0?1:-1)}),!0}if(!r.length)return!1;const n=this.solveEquations({ones:t,inbalances:r});return!n||!n.every((t,r)=>t>e.eventMap[r].lowWarp&&t<=1)}getSolution(e){const t=t=>e.eventMap[t.e2]?e.eventMap[t.e2].x+.06*Math.abs(e.eventMap[t.e2].x-e.eventMap[t.e1].x):e.eventMap[t.e1].x+1e4,r=this.actions.filter(e=>e.type===ActionType.HORIZONTAL).sort((e,r)=>t(e)-t(r)),n=r.reduce((e,t)=>({...e,[t.e1]:t.e2}),{}),s=new Set([...Object.keys(n)].map(Number));r.forEach(e=>s.delete(e.e2)),this.stages[0].events.forEach(e=>e>0&&s.add(e));let i=[...s].map(e=>{const t=[e];let r=e;for(;n[r]&&(r=n[r],!(r<0||t.includes(r)));)t.push(r);return t});const o=Object.values(e.eventMap).filter(e=>e.id>0).map(e=>({id:e.id,tick:null,endTick:null,tickGroup:null,timeWarp:null})),a=o.filter(e=>i.some(t=>t.includes(e.id))||r.some(t=>[t.e1,t.e2].includes(e.id))).reduce((e,t)=>({...e,[t.id]:t}),{});this.stages.forEach((e,t)=>e.events.forEach(e=>a[e]&&(a[e].tickGroup=t))),this.stages[0].tick=0,this.stages[0].events.forEach(e=>a[e]&&(a[e].tick=0));const c=this.optimallySolve(e);o.forEach(e=>e.timeWarp=floatToTimeWarp(c[e.id]));const l=this.stages.slice(0,this.stages.length-1),u=()=>{if(l.every(e=>Number.isFinite(e.tick)))return!1;let t=!1;return r.forEach(r=>{const n=this.stages.find(e=>e.events.includes(r.e1)),s=this.stages.find(e=>e.events.includes(r.e2));Number.isFinite(n.tick)&&!Number.isFinite(s.tick)&&(s.tick=n.tick+fractionMul(e.eventMap[r.e1].duration,a[r.e1].timeWarp),s.events.forEach(e=>a[e]&&(a[e].tick=s.tick)),t=!0)}),[...r].reverse().forEach(r=>{const n=this.stages.find(e=>e.events.includes(r.e1)),s=this.stages.find(e=>e.events.includes(r.e2));!Number.isFinite(n.tick)&&Number.isFinite(s.tick)&&(n.tick=s.tick-fractionMul(e.eventMap[r.e1].duration,a[r.e1].timeWarp),n.events.forEach(e=>a[e]&&(a[e].tick=n.tick)),t=!0)}),t};for(;u(););console.assert(l.every(e=>Number.isFinite(e.tick)),"stage ticks not all solved:",this.stages,this.id),o.filter(e=>Number.isFinite(e.tick)).forEach(t=>t.endTick=t.tick+fractionMul(e.eventMap[t.id].duration,t.timeWarp));const h=e.eventMap[0].duration;i.forEach(e=>{const t=e.findIndex(e=>a[e].endTick>h);if(t>=0){e.splice(t,e.length-t).forEach(e=>{a[e].tick=null,a[e].endTick=null})}}),i=i.filter(e=>e.length);const d=Math.max(0,...o.map(e=>e.endTick).filter(Number.isFinite));return this.logger.debug(String.fromCodePoint(127822),this.id,c),{voices:i,events:o,duration:d,actions:this.actions.map(e=>e.id).join(" ")}}deduce(e,t){this.stages||this.constructStages(e);const r=e.actionAccessing.get(this.id)||{times:0};if(++r.times,e.actionAccessing.set(this.id,r),this.constructConstraints(e),this.isConflicted(e))return r.closed=!0,this.logger.info(this.action.id,"❌"),null;if(this.logger.group(this.action&&this.action.id),t.credits>0){if(--t.credits,this.children||this.expand(e),this.children=this.children.filter(t=>!e.actionAccessing.get(t.id)||!e.actionAccessing.get(t.id).closed),this.children.length){const r=t=>t.possibility/((e.actionAccessing.get(t.id)||{times:0}).times+1);this.children.sort((e,t)=>r(t)-r(e));for(const r of this.children){const n=r.deduce(e,t);if(n)return this.logger.groupEnd(),n;if(t.credits<=0)break}}}else this.logger.debug("quota exhausted.");return this.logger.groupEnd(),r.closed=!0,this.getSolution(e)}expand(e){this.constructStages(e);const{eventMap:t,matrixV:r,matrixH:n}=e,s=this.stagedEvents,i=[],o=e=>{if(!this.actions.some(t=>t.id===e.action.id)&&!i.some(t=>t.action.id===e.action.id)){const t=this.stages.find(t=>t.events.includes(e.action.e1)),n=this.stages.find(t=>t.events.includes(e.action.e2));if(t===n||t&&n&&t.index>=n.index)return;if(t&&n)if(e.action.type===ActionType.VERTICAL){if(n.index-t.index>1)return;if(this.actions.some(e=>t.events.includes(e.e1)&&n.events.includes(e.e2)))return}else if(e.action.type===ActionType.HORIZONTAL&&t.index>n.index)return;if(e.action.type===ActionType.HORIZONTAL&&this.actions.some(t=>t.type===ActionType.HORIZONTAL&&(t.e1===e.action.e1||t.e2===e.action.e2||t.e1===e.action.e2&&t.e2===e.action.e1)))return;if(e.action.type===ActionType.VERTICAL){if(t&&(e.possibility=Math.min(e.possibility,...t.events.map(t=>r[e.action.e2][t])),e.possibility<=0))return;if(n&&(e.possibility=Math.min(e.possibility,...n.events.map(t=>r[t][e.action.e1])),e.possibility<=0))return}i.push(e)}};for(const e of s)e<0||(r[e].forEach((t,r)=>{t>0&&e!==r&&o({action:Action.V(r,e),possibility:t})}),r.forEach((t,r)=>{const n=t[e];n>0&&o({action:Action.V(e,r),possibility:n})}),n[e].forEach((t,r)=>{t>0&&o({action:Action.H(r,e),possibility:t})}),n.forEach((r,n)=>{n=n>=Object.keys(t).length?-1:n;const s=r[e];s>0&&o({action:Action.H(e,n),possibility:s})}));i.some(e=>[ActionType.HORIZONTAL,ActionType.PLACE].includes(e.action.type)||!s.has(e.action.e1)||!s.has(e.action.e2))?this.children=i.map(e=>new PathNode({logger:this.logger,parent:this,...e})):this.children=[]}}class Solver{constructor(e,{quota:t=1e3,logger:r=new DummyLogger}={}){this.quota=t,this.logger=r;const n={id:0,x:0,confidence:1,shrinkness:e.measureShrinkness,duration:e.expectedDuration,lowWarp:0};this.events=[n,...e.events.map(e=>({id:e.id,x:e.x,confidence:e.confidence,shrinkness:e.shrinkness,staff:e.staff,duration:e.duration,lowWarp:.5}))],this.eventMap=this.events.reduce((e,t)=>({...e,[t.id]:t}),{}),this.matrixH=e.matrixH,this.matrixV=e.matrixV,this.xSpan=e.endX-Math.min(e.endX-1,...e.events.map(e=>e.x)),this.actionAccessing=new Map}solve(){this.pathRoot=new PathNode({logger:this.logger,action:null}),this.pathRoot.children=this.events.slice(1).map(e=>new PathNode({logger:this.logger,parent:this.pathRoot,action:Action.P(e.id),possibility:this.matrixV[e.id].reduce((e,t)=>e+t,0)}));let e=null;this.logger.groupCollapsed("solve");const t=Array(this.events.length).fill(0),r={credits:this.quota,times:0};for(;r.credits>0;){++r.times;const n={eventMap:this.eventMap,matrixH:this.matrixH,matrixV:this.matrixV,actionAccessing:this.actionAccessing,eventTendencies:t},s=this.pathRoot.deduce(n,r);if(s.credits=this.quota-r.credits,s.times=r.times,this.evaluateSolution(s),this.logger.debug("loss:",s.loss),e=!e||s.loss<e.loss?s:e,!e.loss)break;if(this.actionAccessing.get("").closed)break}return this.logger.groupEnd(),this.logger.debug("solution",e&&e.loss,e),this.logger.debug("cost:",this.quota-r.credits),this.logger.debug("eventTendencies:",t.map(e=>e/r.times)),e}evaluateSolution(e){e.loss=0;const t=e.events.reduce((e,t)=>({...e,[t.id]:{...t,...this.eventMap[t.id]}}),{}),r=e.events.filter(e=>Number.isFinite(e.tick)).map(e=>t[e.id]),n=r.reduce((e,t)=>(e[t.staff]=e[t.staff]||[],e[t.staff].push(t),e),{});Object.values(n).forEach(t=>{t.sort((e,t)=>e.x-t.x).slice(0,t.length-1).forEach((r,n)=>{t[n+1].tick<r.tick&&(e.loss+=1e3)})});const s=new Map;e.events.forEach(r=>{if(Number.isFinite(r.tick)&&!e.voices.every(e=>!e.includes(r.id))||(e.loss+=100*t[r.id].confidence),r.timeWarp){const{numerator:e,denominator:n}=r.timeWarp,i=t[r.id].shrinkness;s.set(e,Math.max(s.get(e)||0,1-i)),s.set(n,Math.max(s.get(n)||0,1-i))}});const i=reducedFraction(e.duration,this.eventMap[0].duration);s.set(i.numerator,Math.max(s.get(i.numerator)||0,1-this.eventMap[0].shrinkness)),s.set(i.denominator,Math.max(s.get(i.denominator)||0,1-this.eventMap[0].shrinkness));for(const[t,r]of s.entries())t>1&&(e.loss+=Math.log(t)*r);let o=0,a=0;e.voices.forEach(r=>{console.assert(t[r[0]],"invalid voice:",r,Object.keys(t));const n=Math.abs(t[r[0]].tick),s=t[r[r.length-1]].endTick;o+=Math.max(0,n+e.duration-s);let i=null;r.forEach(e=>{const r=t[e];r.staff!==i&&(null!==i&&++a,i=r.staff)})}),e.loss+=10*o/DURATION_MULTIPLIER,e.loss+=5**a-1;const c=[...r].sort((e,t)=>e.x-t.x),l=c.slice(1).map((t,r)=>{const n=c[r],s=t.x-n.x,i=t.tick-n.tick;if(!i)return s/this.xSpan;return(4*Math.atan2(i/e.duration,s/this.xSpan)/Math.PI-1)**2}),u=Math.max(...l,0);e.loss+=u**2,console.assert(e.loss>=0,"Invalid solution loss!!!",e.loss,s,o,a),e.loss<0&&(e.loss=1/0)}}const solveStaffGroup=(e,t)=>{if(!e.events.length)return{events:[],voices:[],duration:0};return new Solver(e,t).solve()};worker({solveStaffGroup:solveStaffGroup}),console.info("%cstarry-omr%c v1.0.0 2026-02-20T12:54:03.964Z","color:#fff; background-color: #555;padding: 5px;border-radius: 3px 0 0 3px;","color: #fff; background-color: #007dc6;padding: 5px;border-radius: 0 3px 3px 0;")})();
//# sourceMappingURL=worker.js.map