flat-embed
Advanced tools
Comparing version 1.3.0 to 1.4.0
# Changelog | ||
## v1.3.0 | ||
## 2021-04-28: v1.4.0 | ||
* Update `loadFlatScore` to support `sharingKey` | ||
* Add methods to dynamically set audio tracks: `setTrack`, `useTrack` and `seekTrackTo` | ||
## 2020-05-06: Available with all previous SDKs since 0.4.0 | ||
* new options for `getPNG` | ||
* `layout` with `track` or `page` (default: `track`) | ||
* `dpi` | ||
## 2020-02-24: v1.3.0 | ||
* Add methods: | ||
@@ -24,15 +35,15 @@ * `getMasterVolume` | ||
## v1.2.0 | ||
## 2020-01-07: v1.2.0 | ||
* Add methods: `getParts`, `getDisplayedParts` and `setDisplayedParts` | ||
## v1.1.0 | ||
## 2019-05-13: v1.1.0 | ||
* Support for MIDI Output | ||
## v1.0.0 | ||
## 2019-05-05: v1.0.0 | ||
* Host on our CDN (`https://prod.flat-cdn.com/embed-js/${VERSION}/embed.min.js`) | ||
## v0.11.0 | ||
## 2018-11-29: v0.11.0 | ||
@@ -43,3 +54,3 @@ * Add `getMIDI` update | ||
## v0.10.0 | ||
## 2018-11-23: v0.10.0 | ||
@@ -51,7 +62,7 @@ * Update for the embed release | ||
## v0.9.0 | ||
## 2017-11-10: v0.9.0 | ||
* Add method: `mute` | ||
## v0.8.0 | ||
## 2017-10-19: v0.8.0 | ||
@@ -61,11 +72,11 @@ * Switch from babel-preset-es2015 to babel-preset-env | ||
## v0.7.0 | ||
## 2017-08-08: v0.7.0 | ||
* Add method: `setNoteColor` | ||
## v0.6.0 | ||
## 2017-08-03: v0.6.0 | ||
* Add methods: `getCursorPosition` and `setCursorPosition` | ||
## v0.5.0 | ||
## 2017-07-07: v0.5.0 | ||
@@ -75,7 +86,7 @@ * Add method: `focusScore` | ||
## v0.4.0 | ||
## 2017-07-05: v0.4.0 | ||
* Add method: `getPNG` | ||
## v0.3.0 | ||
## 2017-05-03: v0.3.0 | ||
@@ -85,3 +96,3 @@ * Add methods: `getEmbedConfig`, `setEditorConfig`, `edit` | ||
## v0.2.0 | ||
## 2017-04-21: v0.2.0 | ||
@@ -92,4 +103,4 @@ * Add methods: `getAutoZoom`, `setAutoZoom`, `loadMusicXML`, `getMusicXML` | ||
## v0.1.0 | ||
## 2017-04-21: v0.1.0 | ||
* Initial release |
@@ -1,9 +0,11 @@ | ||
/*! flat-embed v1.3.0 | (c) 2020 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */ | ||
/*! flat-embed v1.3.0 | (c) 2021 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, (global.Flat = global.Flat || {}, global.Flat.Embed = factory())); | ||
}(this, function () { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (global.Flat = global.Flat || {}, global.Flat.Embed = factory())); | ||
}(this, (function () { 'use strict'; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
@@ -129,3 +131,3 @@ _typeof = function (obj) { | ||
if (!embed.element.contentWindow || !embed.element.contentWindow.postMessage) { | ||
throw new Error('No `contentWindow` or `contentWindow.postMessage` avaialble on the element'); | ||
throw new Error('No `contentWindow` or `contentWindow.postMessage` available on the element'); | ||
} | ||
@@ -154,5 +156,3 @@ | ||
var EmbedCallback = | ||
/*#__PURE__*/ | ||
function () { | ||
var EmbedCallback = /*#__PURE__*/function () { | ||
function EmbedCallback(embed) { | ||
@@ -288,5 +288,3 @@ _classCallCheck(this, EmbedCallback); | ||
var Embed = | ||
/*#__PURE__*/ | ||
function () { | ||
var Embed = /*#__PURE__*/function () { | ||
/** | ||
@@ -413,4 +411,3 @@ * Create a new Flat Embed | ||
* | ||
* @param {string} score The unique identifier of the score | ||
* @param {string} [revision] The unique identifier of the revision | ||
* @param {string|object} score The unique identifier of the score or an object with { score, sharingKey } | ||
* @return {Promise} | ||
@@ -422,7 +419,10 @@ * @reject {ApiError} Unable to load the score | ||
key: "loadFlatScore", | ||
value: function loadFlatScore(score, revision) { | ||
return this.call('loadFlatScore', { | ||
score: score, | ||
revision: revision | ||
}); | ||
value: function loadFlatScore(score) { | ||
if (typeof score === 'string') { | ||
score = { | ||
score: score | ||
}; | ||
} | ||
return this.call('loadFlatScore', score); | ||
} | ||
@@ -760,2 +760,35 @@ /** | ||
/** | ||
* Configure a new audio or video track | ||
* | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: "setTrack", | ||
value: function setTrack(parameters) { | ||
return this.call('setTrack', parameters); | ||
} | ||
/** | ||
* Enabled a previously configured track | ||
* | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: "useTrack", | ||
value: function useTrack(parameters) { | ||
return this.call('useTrack', parameters); | ||
} | ||
/** | ||
* Seek the audio track to a specified duration | ||
* | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: "seekTrackTo", | ||
value: function seekTrackTo(parameters) { | ||
return this.call('seekTrackTo', parameters); | ||
} | ||
/** | ||
* Print the score | ||
@@ -924,4 +957,4 @@ * | ||
})); | ||
}))); | ||
//# sourceMappingURL=embed.js.map |
@@ -1,2 +0,2 @@ | ||
/*! flat-embed v1.3.0 | (c) 2020 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e=e||self).Flat=e.Flat||{},e.Flat.Embed=t())}(this,function(){"use strict";function o(e){return(o="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)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function e(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}if(void 0===window.postMessage)throw new Error("The Flat Embed JS API is not supported in this browser");function i(e,t){var n=function(e){var t=e.baseUrl||"https://flat-embed.com";t+="/"+(e.score||"blank");var n=Object.assign({jsapi:!0},e.embedParams);return t+"?"+Object.keys(n).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n[e]))}).join("&")}(t),r=document.createElement("iframe");return r.setAttribute("src",n),r.setAttribute("width",t.width||"100%"),r.setAttribute("height",t.height||"100%"),r.setAttribute("allowfullscreen",!0),r.setAttribute("allow","midi"),r.setAttribute("frameborder","0"),e.appendChild(r),r}function a(e,t,n){if(!e.element.contentWindow||!e.element.contentWindow.postMessage)throw new Error("No `contentWindow` or `contentWindow.postMessage` avaialble on the element");var r={method:t,parameters:n};e.element.contentWindow.postMessage(r,e.origin)}var s=function(){function t(e){return n(this,t),this.embed=e,this.promises={},this.eventCallbacks={},this}return e(t,[{key:"pushCall",value:function(e,t,n){this.promises[e]=this.promises[e]||[],this.promises[e].push({resolve:t,reject:n})}},{key:"subscribeEvent",value:function(e,t){return this.eventCallbacks[e]=this.eventCallbacks[e]||[],this.eventCallbacks[e].push(t),1===this.eventCallbacks[e].length}},{key:"unsubscribeEvent",value:function(e,t){if(!this.eventCallbacks[e])return!1;if(t){var n=this.eventCallbacks[e].indexOf(t);0<=n&&this.eventCallbacks[e].splice(n,1)}else this.eventCallbacks[e]=[];return!t||0===this.eventCallbacks[e].length}},{key:"process",value:function(e){e.method?this.processMethodResponse(e):e.event&&this.processEvent(e)}},{key:"processMethodResponse",value:function(e){if(this.promises[e.method]){var t=this.promises[e.method].shift();t&&(e.error?t.reject(e.error):t.resolve(e.response))}}},{key:"processEvent",value:function(t){var n=this;this.eventCallbacks[t.event]&&0!==this.eventCallbacks[t.event].length&&this.eventCallbacks[t.event].forEach(function(e){e.call(n.embed,t.parameters)})}}]),t}(),u=new WeakMap,l=new WeakMap;return function(){function Embed(r){var o=this,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(n(this,Embed),r=function(e){if(window.jQuery&&e instanceof window.jQuery&&(e=e[0]),"string"==typeof e&&(e=document.getElementById(e)),!(e instanceof window.HTMLElement))throw new TypeError("The first parameter must be an existing DOM element or an identifier.");if("IFRAME"!==e.nodeName){var t=e.querySelector("iframe");t&&(e=t)}return e}(r),u.has(r))return u.get(r);"IFRAME"!==r.nodeName&&(r=i(r,e)),this.origin="*",this.element=r,this.embedCallback=new s;var t=new Promise(function(n){window.addEventListener("message",function(e){if(r.contentWindow===e.source){"*"===o.origin&&(o.origin=e.origin);var t=function(e){return"string"==typeof e&&(e=JSON.parse(e)),e}(e.data);"ready"!==t.event&&"ping"!==t.method?o.embedCallback.process(t):n()}},!1),a(o,"ping")});return u.set(this.element,this),l.set(this,t),this}return e(Embed,[{key:"ready",value:function(){return Promise.resolve(l.get(this))}},{key:"call",value:function(n){var r=this,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(e,t){return r.ready().then(function(){r.embedCallback.pushCall(n,e,t),a(r,n,o)})})}},{key:"on",value:function(e,t){if("string"!=typeof e)throw new TypeError("An event name (string) is required");if("function"!=typeof t)throw new TypeError("An callback (function) is required");this.embedCallback.subscribeEvent(e,t)&&this.call("addEventListener",e).catch(function(){})}},{key:"off",value:function(e,t){if("string"!=typeof e)throw new TypeError("An event name (string) is required");this.embedCallback.unsubscribeEvent(e,t)&&this.call("removeEventListener",e).catch(function(){})}},{key:"loadFlatScore",value:function(e,t){return this.call("loadFlatScore",{score:e,revision:t})}},{key:"loadMusicXML",value:function(e){return this.call("loadMusicXML",e)}},{key:"loadJSON",value:function(e){return this.call("loadJSON",e)}},{key:"getJSON",value:function(){return this.call("getJSON")}},{key:"getMusicXML",value:function(n){var r=this;return new Promise(function(t,e){if("object"!==o(n=n||{}))return e(new TypeError("Options must be an object"));r.call("getMusicXML",n).then(function(e){return t("string"==typeof e?e:new Uint8Array(e))}).catch(e)})}},{key:"getPNG",value:function(n){var r=this;return new Promise(function(t,e){if("object"!==o(n=n||{}))return e(new TypeError("Options must be an object"));r.call("getPNG",n).then(function(e){return t("string"==typeof e?e:new Uint8Array(e))}).catch(e)})}},{key:"getMIDI",value:function(){return this.call("getMIDI").then(function(e){return new Uint8Array(e)})}},{key:"getFlatScoreMetadata",value:function(){return this.call("getFlatScoreMetadata")}},{key:"getEmbedConfig",value:function(){return this.call("getEmbedConfig")}},{key:"setEditorConfig",value:function(e){return this.call("setEditorConfig",e)}},{key:"fullscreen",value:function(e){return this.call("fullscreen",e)}},{key:"play",value:function(){return this.call("play")}},{key:"pause",value:function(){return this.call("pause")}},{key:"stop",value:function(){return this.call("stop")}},{key:"mute",value:function(){return this.call("mute")}},{key:"getMasterVolume",value:function(){return this.call("getMasterVolume")}},{key:"setMasterVolume",value:function(e){return this.call("getMasterVolume",e)}},{key:"getPartVolume",value:function(e){return this.call("getPartVolume",e)}},{key:"setPartVolume",value:function(e){return this.call("setPartVolume",e)}},{key:"mutePart",value:function(e){return this.call("mutePart",e)}},{key:"unmutePart",value:function(e){return this.call("unmutePart",e)}},{key:"setPartSoloMode",value:function(e){return this.call("setPartSoloMode",e)}},{key:"unsetPartSoloMode",value:function(e){return this.call("unsetPartSoloMode",e)}},{key:"getPartSoloMode",value:function(e){return this.call("getPartSoloMode",e)}},{key:"getPartReverb",value:function(e){return this.call("getPartReverb",e)}},{key:"setPartReverb",value:function(e){return this.call("setPartReverb",e)}},{key:"print",value:function(){return this.call("print")}},{key:"getZoom",value:function(){return this.call("getZoom")}},{key:"setZoom",value:function(e){return this.call("setZoom",e)}},{key:"getAutoZoom",value:function(){return this.call("getAutoZoom")}},{key:"setAutoZoom",value:function(e){return this.call("setAutoZoom",e)}},{key:"focusScore",value:function(){return this.call("focusScore")}},{key:"getCursorPosition",value:function(){return this.call("getCursorPosition")}},{key:"setCursorPosition",value:function(e){return this.call("setCursorPosition",e)}},{key:"getParts",value:function(){return this.call("getParts")}},{key:"getDisplayedParts",value:function(){return this.call("getDisplayedParts")}},{key:"setDisplayedParts",value:function(e){return this.call("setDisplayedParts",e)}},{key:"getMeasureDetails",value:function(){return this.call("getMeasureDetails")}},{key:"getNoteDetails",value:function(){return this.call("getNoteDetails")}}]),Embed}()}); | ||
/*! flat-embed v1.3.0 | (c) 2021 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).Flat=e.Flat||{},e.Flat.Embed=t())}(this,function(){"use strict";function o(e){return(o="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)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function e(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}if(void 0===window.postMessage)throw new Error("The Flat Embed JS API is not supported in this browser");function t(e,t){var n=function(e){var t=e.baseUrl||"https://flat-embed.com";t+="/"+(e.score||"blank");var n=Object.assign({jsapi:!0},e.embedParams);return t+"?"+Object.keys(n).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n[e]))}).join("&")}(t),r=document.createElement("iframe");return r.setAttribute("src",n),r.setAttribute("width",t.width||"100%"),r.setAttribute("height",t.height||"100%"),r.setAttribute("allowfullscreen",!0),r.setAttribute("allow","midi"),r.setAttribute("frameborder","0"),e.appendChild(r),r}function a(e,t,n){if(!e.element.contentWindow||!e.element.contentWindow.postMessage)throw new Error("No `contentWindow` or `contentWindow.postMessage` available on the element");e.element.contentWindow.postMessage({method:t,parameters:n},e.origin)}var s=function(){function t(e){return i(this,t),this.embed=e,this.promises={},this.eventCallbacks={},this}return e(t,[{key:"pushCall",value:function(e,t,n){this.promises[e]=this.promises[e]||[],this.promises[e].push({resolve:t,reject:n})}},{key:"subscribeEvent",value:function(e,t){return this.eventCallbacks[e]=this.eventCallbacks[e]||[],this.eventCallbacks[e].push(t),1===this.eventCallbacks[e].length}},{key:"unsubscribeEvent",value:function(e,t){return!!this.eventCallbacks[e]&&(t?0<=(n=this.eventCallbacks[e].indexOf(t))&&this.eventCallbacks[e].splice(n,1):this.eventCallbacks[e]=[],!t||0===this.eventCallbacks[e].length);var n}},{key:"process",value:function(e){e.method?this.processMethodResponse(e):e.event&&this.processEvent(e)}},{key:"processMethodResponse",value:function(e){var t;!this.promises[e.method]||(t=this.promises[e.method].shift())&&(e.error?t.reject(e.error):t.resolve(e.response))}},{key:"processEvent",value:function(t){var n=this;this.eventCallbacks[t.event]&&0!==this.eventCallbacks[t.event].length&&this.eventCallbacks[t.event].forEach(function(e){e.call(n.embed,t.parameters)})}}]),t}(),u=new WeakMap,l=new WeakMap;return function(){function Embed(n){var r=this,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(i(this,Embed),n=function(e){if(!((e="string"==typeof(e=window.jQuery&&e instanceof window.jQuery?e[0]:e)?document.getElementById(e):e)instanceof window.HTMLElement))throw new TypeError("The first parameter must be an existing DOM element or an identifier.");var t;return"IFRAME"===e.nodeName||(t=e.querySelector("iframe"))&&(e=t),e}(n),u.has(n))return u.get(n);"IFRAME"!==n.nodeName&&(n=t(n,e)),this.origin="*",this.element=n,this.embedCallback=new s;e=new Promise(function(t){window.addEventListener("message",function(e){n.contentWindow===e.source&&("*"===r.origin&&(r.origin=e.origin),"ready"!==(e=e="string"==typeof(e=e.data)?JSON.parse(e):e).event&&"ping"!==e.method?r.embedCallback.process(e):t())},!1),a(r,"ping")});return u.set(this.element,this),l.set(this,e),this}return e(Embed,[{key:"ready",value:function(){return Promise.resolve(l.get(this))}},{key:"call",value:function(n){var r=this,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(e,t){return r.ready().then(function(){r.embedCallback.pushCall(n,e,t),a(r,n,o)})})}},{key:"on",value:function(e,t){if("string"!=typeof e)throw new TypeError("An event name (string) is required");if("function"!=typeof t)throw new TypeError("An callback (function) is required");this.embedCallback.subscribeEvent(e,t)&&this.call("addEventListener",e).catch(function(){})}},{key:"off",value:function(e,t){if("string"!=typeof e)throw new TypeError("An event name (string) is required");this.embedCallback.unsubscribeEvent(e,t)&&this.call("removeEventListener",e).catch(function(){})}},{key:"loadFlatScore",value:function(e){return this.call("loadFlatScore",e="string"==typeof e?{score:e}:e)}},{key:"loadMusicXML",value:function(e){return this.call("loadMusicXML",e)}},{key:"loadJSON",value:function(e){return this.call("loadJSON",e)}},{key:"getJSON",value:function(){return this.call("getJSON")}},{key:"getMusicXML",value:function(n){var r=this;return new Promise(function(t,e){if("object"!==o(n=n||{}))return e(new TypeError("Options must be an object"));r.call("getMusicXML",n).then(function(e){return t("string"==typeof e?e:new Uint8Array(e))}).catch(e)})}},{key:"getPNG",value:function(n){var r=this;return new Promise(function(t,e){if("object"!==o(n=n||{}))return e(new TypeError("Options must be an object"));r.call("getPNG",n).then(function(e){return t("string"==typeof e?e:new Uint8Array(e))}).catch(e)})}},{key:"getMIDI",value:function(){return this.call("getMIDI").then(function(e){return new Uint8Array(e)})}},{key:"getFlatScoreMetadata",value:function(){return this.call("getFlatScoreMetadata")}},{key:"getEmbedConfig",value:function(){return this.call("getEmbedConfig")}},{key:"setEditorConfig",value:function(e){return this.call("setEditorConfig",e)}},{key:"fullscreen",value:function(e){return this.call("fullscreen",e)}},{key:"play",value:function(){return this.call("play")}},{key:"pause",value:function(){return this.call("pause")}},{key:"stop",value:function(){return this.call("stop")}},{key:"mute",value:function(){return this.call("mute")}},{key:"getMasterVolume",value:function(){return this.call("getMasterVolume")}},{key:"setMasterVolume",value:function(e){return this.call("getMasterVolume",e)}},{key:"getPartVolume",value:function(e){return this.call("getPartVolume",e)}},{key:"setPartVolume",value:function(e){return this.call("setPartVolume",e)}},{key:"mutePart",value:function(e){return this.call("mutePart",e)}},{key:"unmutePart",value:function(e){return this.call("unmutePart",e)}},{key:"setPartSoloMode",value:function(e){return this.call("setPartSoloMode",e)}},{key:"unsetPartSoloMode",value:function(e){return this.call("unsetPartSoloMode",e)}},{key:"getPartSoloMode",value:function(e){return this.call("getPartSoloMode",e)}},{key:"getPartReverb",value:function(e){return this.call("getPartReverb",e)}},{key:"setPartReverb",value:function(e){return this.call("setPartReverb",e)}},{key:"setTrack",value:function(e){return this.call("setTrack",e)}},{key:"useTrack",value:function(e){return this.call("useTrack",e)}},{key:"seekTrackTo",value:function(e){return this.call("seekTrackTo",e)}},{key:"print",value:function(){return this.call("print")}},{key:"getZoom",value:function(){return this.call("getZoom")}},{key:"setZoom",value:function(e){return this.call("setZoom",e)}},{key:"getAutoZoom",value:function(){return this.call("getAutoZoom")}},{key:"setAutoZoom",value:function(e){return this.call("setAutoZoom",e)}},{key:"focusScore",value:function(){return this.call("focusScore")}},{key:"getCursorPosition",value:function(){return this.call("getCursorPosition")}},{key:"setCursorPosition",value:function(e){return this.call("setCursorPosition",e)}},{key:"getParts",value:function(){return this.call("getParts")}},{key:"getDisplayedParts",value:function(){return this.call("getDisplayedParts")}},{key:"setDisplayedParts",value:function(e){return this.call("setDisplayedParts",e)}},{key:"getMeasureDetails",value:function(){return this.call("getMeasureDetails")}},{key:"getNoteDetails",value:function(){return this.call("getNoteDetails")}}]),Embed}()}); |
{ | ||
"name": "flat-embed", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Interact and get events from Flat's Sheet Music Embed", | ||
@@ -41,18 +41,18 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"chokidar": "^3.0.0", | ||
"eslint": "^6.2.1", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
"chokidar": "^3.3.1", | ||
"eslint": "^7.4.0", | ||
"jquery": "^3.4.1", | ||
"karma": "^4.1.0", | ||
"karma-chrome-launcher": "^3.0.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma": "6.3.2", | ||
"karma-chrome-launcher": "3.1.0", | ||
"karma-mocha": "2.0.1", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"mocha": "^7.0.0", | ||
"rollup": "^1.11.3", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.0", | ||
"uglify-js": "^3.5.12" | ||
"mocha": "^8.0.1", | ||
"rollup": "^2.3.3", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"uglify-js": "^3.8.1" | ||
} | ||
} |
164
README.md
# Flat Sheet Music Embed Client | ||
[![Build Status](https://travis-ci.org/FlatIO/embed-client.svg?branch=master)](https://travis-ci.org/FlatIO/embed-client) | ||
[![Build Status](https://github.com/FlatIO/embed-client/actions/workflows/tests.yml/badge.svg)](https://github.com/FlatIO/embed-client/actions) | ||
[![NPM Version](https://img.shields.io/npm/v/flat-embed.svg?style=flat)](https://www.npmjs.org/package/flat-embed) | ||
@@ -24,3 +24,3 @@ | ||
```html | ||
<script src="https://prod.flat-cdn.com/embed-js/v1.3.0/embed.min.js"></script> | ||
<script src="https://prod.flat-cdn.com/embed-js/v1.4.0/embed.min.js"></script> | ||
``` | ||
@@ -34,3 +34,3 @@ | ||
<div id="embed-container"></div> | ||
<script src="https://prod.flat-cdn.com/embed-js/v1.3.0/embed.min.js"></script> | ||
<script src="https://prod.flat-cdn.com/embed-js/v1.4.0/embed.min.js"></script> | ||
<script> | ||
@@ -65,2 +65,6 @@ var container = document.getElementById('embed-container'); | ||
### ✨ Demos | ||
**Some demos of this Embed API are available in a dedicated repository: [https://github.com/FlatIO/embed-examples](https://github.com/FlatIO/embed-examples).** | ||
### App ID | ||
@@ -103,3 +107,3 @@ | ||
* [`getEmbedConfig`](#getembedconfig-promiseobject-error): Get the global config of the embed | ||
* [`loadFlatScore`](#loadflatscoreid-string-promisevoid-apierror): Load a score hosted on Flat | ||
* [`loadFlatScore`](#loadflatscorescore-mixed-promisevoid-apierror): Load a score hosted on Flat | ||
* [`loadMusicXML`](#loadmusicxmlscore-mixed-promisevoid-error): Load MusicXML file (compressed or not) | ||
@@ -118,12 +122,15 @@ * [`loadJSON`](#loadjsonscore-object-promisevoid-error): Load Flat JSON file | ||
* [`getMasterVolume`](#getmastervolume-promisenumber-error): Get the master volume | ||
* [`setMasterVolume`](#setmastervolume-volume-number-promisevoid-error): Set the master volume | ||
* [`getPartVolume`](#getpartvolume-partuuid-string-promisenumber-error): Get a part volume | ||
* [`setPartVolume`](#setpartvolume-partuuid-string-volume-number-promisevoid-error): Set a part volume | ||
* [`mutePart`](#mutepart-partuuid-string-promisevoid-error): Mute a part | ||
* [`unmutePart`](#unmutepart-partuuid-string-promisevoid-error): Unmute a part | ||
* [`setPartSoloMode`](#setpartsolomode-partuuid-string-promisevoid-error): Enable the solo mode for a part | ||
* [`unsetPartSoloMode`](#unsetpartsolomode-partuuid-string-promisevoid-error): Disable the solo mode for a part | ||
* [`getPartSoloMode`](#getpartsolomode-partuuid-string-promiseboolean-error): Get the state of the solo mode of a part | ||
* [`getPartReverb`](#getpartreverb-partuuid-string-promisenumber-error): Get a part reverberation | ||
* [`setPartReverb`](#setpartreverb-partuuid-string-reverberation-number-promisevoid-error): Set a part reverberation | ||
* [`setMasterVolume`](#setmastervolume-volume-number--promisevoid-error): Set the master volume | ||
* [`getPartVolume`](#getpartvolume-partuuid-string--promisenumber-error): Get a part volume | ||
* [`setPartVolume`](#setpartvolume-partuuid-string-volume-number--promisevoid-error): Set a part volume | ||
* [`mutePart`](#mutepart-partuuid-string--promisevoid-error): Mute a part | ||
* [`unmutePart`](#unmutepart-partuuid-string--promisevoid-error): Unmute a part | ||
* [`setPartSoloMode`](#setpartsolomode-partuuid-string--promisevoid-error): Enable the solo mode for a part | ||
* [`unsetPartSoloMode`](#unsetpartsolomode-partuuid-string--promisevoid-error): Disable the solo mode for a part | ||
* [`getPartSoloMode`](#getpartsolomode-partuuid-string--promiseboolean-error): Get the state of the solo mode of a part | ||
* [`getPartReverb`](#getpartreverb-partuuid-string--promisenumber-error): Get a part reverberation | ||
* [`setPartReverb`](#setpartreverb-partuuid-string-reverberation-number--promisevoid-error): Set a part reverberation | ||
* [`setTrack`](#settrackobject-promisevoid-error): Configure an new audio track to use | ||
* [`useTrack`](#usetrack-id--promisevoid-error): Use a configured audio track | ||
* [`seekTrackTo`](#seektrackto-time--promisevoid-error): Seek the audio track to a specified duration | ||
* [`print`](#print-promisevoid-error): Print the score | ||
@@ -220,3 +227,3 @@ * [`getZoom`](#getzoom-promisenumber-error): Get the current display zoom ratio | ||
### `loadFlatScore(id: string): Promise<void, ApiError>` | ||
### `loadFlatScore(score: mixed): Promise<void, ApiError>` | ||
@@ -233,7 +240,23 @@ Load a score hosted on Flat using its identifier. For example to load `https://flat.io/score/56ae21579a127715a02901a6-house-of-the-rising-sun`, you can call: | ||
If the score has a private sharing link ([`privateLink`](https://flat.io/developers/api/reference/#operation/editScore)), you can pass an object with the `sharingKey` property: | ||
```js | ||
embed.loadFlatScore({ | ||
score: '5ce56f7c019fd41f5b17b72d', | ||
sharingKey: '3f70cc5ecf5e4248055bbe7502a9514cfe619c53b4e248144e470bb5f08c5ecf880cf3eda5679c6b19f646a98ec0bd06d892ee1fd6896e20de0365ed0a42fc00' | ||
}).then(function () { | ||
// Score loaded in the embed | ||
}).catch(function (error) { | ||
// Unable to load the score | ||
}); | ||
``` | ||
### `loadMusicXML(score: mixed): Promise<void, Error>` | ||
Load a MusicXML score, compressed (MXL) or not (plain XML): | ||
Load a MusicXML score, compressed (MXL) or not (plain XML). The compressed files (.mxl) must be passed as `ArrayBuffer`, and the plain XML (.xml/.musicxml) as `String`. | ||
Example to load a compressed MXL file: | ||
```js | ||
// Loading any MXL file here, for example a file from a public Flat score | ||
fetch('https://api.flat.io/v2/scores/56ae21579a127715a02901a6/revisions/last/mxl') | ||
@@ -244,2 +267,3 @@ .then(function (response) { | ||
.then(function (mxl) { | ||
// Got the compressed score as an `ArrayBuffer`, load it in the embed | ||
return embed.loadMusicXML(mxl); | ||
@@ -255,2 +279,22 @@ }) | ||
Example to load a plain XML file: | ||
```js | ||
// Loading any plain XML file here, for a file example from a public Flat score | ||
fetch('https://api.flat.io/v2/scores/56ae21579a127715a02901a6/revisions/last/xml') | ||
.then(function (response) { | ||
return response.text(); | ||
}) | ||
.then(function (mxl) { | ||
// Got the plain XML score as an `String`, load it in the embed | ||
return embed.loadMusicXML(mxl); | ||
}) | ||
.then(function () { | ||
// Score loaded in the embed | ||
}) | ||
.catch(function (error) { | ||
// Unable to load the score | ||
}); | ||
``` | ||
### `loadJSON(score: object): Promise<void, Error>` | ||
@@ -323,4 +367,8 @@ | ||
Get the currently displayed score as a PNG file | ||
Get the currently displayed score as a PNG file. This API method accepts the following options: | ||
* `result`: Choose how the PNG file is returned, either `dataURL` or `Uint8Array`. Default value is `Uint8Array`. | ||
* `layout`: The score can either exported as one horizontal system (`track`), or the first page (`page`). Default value is `track` | ||
* `dpi`: The dpi used to export the PNG, between `50` and `300`. Default value is `150`. | ||
```js | ||
@@ -336,4 +384,8 @@ // PNG | ||
// PNG | ||
embed.getPNG({result: 'dataURL'}).then(function (png) { | ||
// PNG file as a DataURL | ||
embed.getPNG({ | ||
result: 'dataURL', | ||
layout: 'layout', | ||
dpi: 300 | ||
}).then(function (png) { | ||
// 300 DPI PNG with the score as a page, returned as a DataURL | ||
console.log(png); | ||
@@ -530,4 +582,64 @@ }); | ||
### `print(): Promise<void, Error> | ||
### `setTrack(object): Promise<void, Error>` | ||
Configure a new video or audio track for the current embedded score. This method uses the same system as [our audio tracks manager in our editor app](https://flat.io/help/en/music-notation-software/synchronize-external-recording.html), but allows you to dynamically configure any track or connect an external player to an embedded score. | ||
This method takes the following options: | ||
* `id` **(required)**: An unique identifier for the configuration, that can be used later for the method [`useTrack`](#usetrack-id--promisevoid-error). | ||
* `type` **(required)**: The type of track to configure, using one of the following types: `youtube`, `soundcloud`, `vimeo`, `audio`, `external` | ||
* `url` **(required for `soundcloud` and `audio`)**: the URL of the Souncloud or the audio file to load | ||
* `mediaId` **(required for `youtube`, `vimeo`)**: the video identifier to embed | ||
* `totalTime` **(required for `external`)**: the total time of the media played | ||
* `synchronizationPoints` **(required)**: the list of synchronization points to use. Each point can have the following information: | ||
* `type`: `measure` or `end` of the score | ||
* `time` in seconds, the position of the synchronization point | ||
* `location.measureIdx`: for `measure` point, the index of the score where the point is located. | ||
Once a track is configured, you must call the method [`useTrack`](#usetrack-id--promisevoid-error) to enable it. | ||
Two implementation examples are available in our example repository: | ||
* [📺 YouTube synced player with a MusicXML loaded locally](https://github.com/FlatIO/embed-examples#-youtube-synced-player-with-a-musicxml-loaded-locally) | ||
* [🎧 External player with a MusicXML loaded locally](https://github.com/FlatIO/embed-examples#-external-player-with-a-musicxml-loaded-locally) | ||
The `synchronizationPoints` also use the same formats as our REST API. If you previously configured some tracks using our web editor, [you can fetch their configuration using our REST API](https://flat.io/developers/api/reference/#operation/getScoreTrack). | ||
```js | ||
embed.setTrack({ | ||
id: 'yt-cucaracha', | ||
type: 'youtube', | ||
mediaId: 'jp9vFhyhNd8', | ||
synchronizationPoints: [ | ||
{ type: 'measure', time: 0, location: { measureIdx: 0 }}, | ||
{ type: 'end', time: 19 } | ||
], | ||
}).then(function () { | ||
// The track is configured | ||
}); | ||
``` | ||
### `useTrack({ id }): Promise<void, Error>` | ||
Enable a previously configured audio or video track. The `id` can be an identifier chosen from a track configured using [`setTrack`](#settrackobject-promisevoid-error) or from [Flat's REST API](https://flat.io/developers/api/reference/#operation/getScoreTrack). | ||
```js | ||
embed.useTrack({ | ||
id: 'yt-cucaracha', | ||
}).then(function () { | ||
// The track is enabled | ||
}); | ||
``` | ||
### `seekTrackTo({ time }): Promise<void, Error>` | ||
Seek the current played track to a provided `time`, in seconds. | ||
```js | ||
embed.useTrack({ | ||
time: 5 | ||
}); | ||
``` | ||
### `print(): Promise<void, Error>` | ||
Print the score | ||
@@ -715,2 +827,8 @@ | ||
// }, | ||
// "tempo": { | ||
// "qpm": 80, | ||
// "bpm": 80, | ||
// "durationType": "quarter", | ||
// "nbDots": 0 | ||
// }, | ||
// "transpose": { | ||
@@ -860,2 +978,8 @@ // "chromatic": "0" | ||
}, | ||
"tempo": { | ||
"qpm": 80, | ||
"bpm": 80, | ||
"durationType": "quarter", | ||
"nbDots": 0 | ||
}, | ||
"transpose": { | ||
@@ -862,0 +986,0 @@ "chromatic": "0" |
@@ -119,9 +119,11 @@ import './lib/compatibility'; | ||
* | ||
* @param {string} score The unique identifier of the score | ||
* @param {string} [revision] The unique identifier of the revision | ||
* @param {string|object} score The unique identifier of the score or an object with { score, sharingKey } | ||
* @return {Promise} | ||
* @reject {ApiError} Unable to load the score | ||
*/ | ||
loadFlatScore(score, revision) { | ||
return this.call('loadFlatScore', {score, revision}); | ||
loadFlatScore(score) { | ||
if (typeof score === 'string') { | ||
score = { score }; | ||
} | ||
return this.call('loadFlatScore', score); | ||
} | ||
@@ -398,2 +400,29 @@ | ||
/** | ||
* Configure a new audio or video track | ||
* | ||
* @return {Promise} | ||
*/ | ||
setTrack(parameters) { | ||
return this.call('setTrack', parameters); | ||
} | ||
/** | ||
* Enabled a previously configured track | ||
* | ||
* @return {Promise} | ||
*/ | ||
useTrack(parameters) { | ||
return this.call('useTrack', parameters); | ||
} | ||
/** | ||
* Seek the audio track to a specified duration | ||
* | ||
* @return {Promise} | ||
*/ | ||
seekTrackTo(parameters) { | ||
return this.call('seekTrackTo', parameters); | ||
} | ||
/** | ||
* Print the score | ||
@@ -400,0 +429,0 @@ * |
@@ -10,3 +10,3 @@ /** | ||
if (!embed.element.contentWindow || !embed.element.contentWindow.postMessage) { | ||
throw new Error('No `contentWindow` or `contentWindow.postMessage` avaialble on the element'); | ||
throw new Error('No `contentWindow` or `contentWindow.postMessage` available on the element'); | ||
} | ||
@@ -13,0 +13,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138762
1520
1079