"use strict"; var Xml_1 = require("./../Common/FileIO/Xml"); var VexFlowMusicSheetCalculator_1 = require("./../MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator"); var MusicSheetReader_1 = require("./../MusicalScore/ScoreIO/MusicSheetReader"); var GraphicalMusicSheet_1 = require("./../MusicalScore/Graphical/GraphicalMusicSheet"); var VexFlowMusicSheetDrawer_1 = require("./../MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer"); var Cursor_1 = require("./Cursor"); var Mxl_1 = require("../Common/FileIO/Mxl"); //import {Promise} from "es6-promise"; var ResizeHandler_1 = require("./ResizeHandler"); var OSMD = (function () { /** * The easy way of displaying a MusicXML sheet music file * @param container is either the ID, or the actual "div" element which will host the music sheet * @autoResize automatically resize the sheet to full page width on window resize */ function OSMD(container, autoResize) { if (autoResize === void 0) { autoResize = false; } this.zoom = 1.0; // Store container element if (typeof container === "string") { // ID passed this.container = document.getElementById(container); } else if (container && "appendChild" in container) { // Element passed this.container = container; } if (!this.container) { throw new Error("Please pass a valid div container to OSMD"); } // Create the elements inside the container this.heading = document.createElement("div"); this.canvas = document.createElement("canvas"); this.canvas.style.zIndex = "0"; var inner = document.createElement("div"); inner.style.position = "relative"; this.container.appendChild(this.heading); inner.appendChild(this.canvas); this.container.appendChild(inner); // Create the drawer this.drawer = new VexFlowMusicSheetDrawer_1.VexFlowMusicSheetDrawer(this.heading, this.canvas); // Create the cursor this.cursor = new Cursor_1.Cursor(inner, this); if (autoResize) { this.autoResize(); } } /** * Load a MusicXML file * @param content is either the url of a file, or the root node of a MusicXML document, or the string content of a .xml/.mxl file */ OSMD.prototype.load = function (content) { // Warning! This function is asynchronous! No error handling is done here. // FIXME TODO Refactor with Promises this.reset(); var path = "Unknown path"; if (typeof content === "string") { var str = content; if (str.substr(0, 4) === "http") { // Retrieve the file at the url path = str; this.openURL(path); return; } if (str.substr(0, 4) === "\x04\x03\x4b\x50") { // This is a zip file, unpack it first Mxl_1.openMxl(str).then(this.load, function (err) { throw new Error("OSMD: Invalid MXL file"); }); return; } if (str.substr(0, 5) === "