Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flat-embed

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat-embed - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

342

dist/embed.js

@@ -1,2 +0,2 @@

/*! flat-embed v1.4.1 | (c) 2022 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */
/*! flat-embed v1.5.0 | (c) 2023 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */
(function (global, factory) {

@@ -17,3 +17,2 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :

}
function _classCallCheck(instance, Constructor) {

@@ -24,3 +23,2 @@ if (!(instance instanceof Constructor)) {

}
function _defineProperties(target, props) {

@@ -32,6 +30,5 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {

@@ -45,2 +42,16 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps);

}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -60,19 +71,18 @@ if (typeof window.postMessage === 'undefined') {

element = element[0];
} // Find an element by identifier
}
// Find an element by identifier
if (typeof element === 'string') {
element = document.getElementById(element);
} // Check if a DOM element
}
// Check if a DOM element
if (!(element instanceof window.HTMLElement)) {
throw new TypeError('The first parameter must be an existing DOM element or an identifier.');
} // The element is not an embed iframe?
}
// The element is not an embed iframe?
if (element.nodeName !== 'IFRAME') {
// check if already present in the element
var iframe = element.querySelector('iframe');
if (iframe) {

@@ -82,3 +92,2 @@ element = iframe;

}
return element;

@@ -93,6 +102,8 @@ }

function buildIframeUrl(parameters) {
var url = parameters.baseUrl || 'https://flat-embed.com'; // Score id or blank embed
var url = parameters.baseUrl || 'https://flat-embed.com';
url += '/' + (parameters.score || 'blank'); // Build qs parameters
// Score id or blank embed
url += '/' + (parameters.score || 'blank');
// Build qs parameters
var urlParameters = Object.assign({

@@ -106,2 +117,3 @@ jsapi: true

}
/**

@@ -113,3 +125,2 @@ * Create an iframe inside a specified element

*/
function createEmbedIframe(element, parameters) {

@@ -139,3 +150,2 @@ var url = buildIframeUrl(parameters);

}
var message = {

@@ -147,2 +157,3 @@ method: method,

}
/**

@@ -154,3 +165,2 @@ * Parse a message received from postMessage

*/
function parseMessage(data) {

@@ -160,3 +170,2 @@ if (typeof data === 'string') {

}
return data;

@@ -168,3 +177,2 @@ }

_classCallCheck(this, EmbedCallback);
this.embed = embed;

@@ -175,3 +183,2 @@ this.promises = {};

}
_createClass(EmbedCallback, [{

@@ -186,2 +193,3 @@ key: "pushCall",

}
/**

@@ -194,3 +202,2 @@ * Register a callback for a specified event

*/
}, {

@@ -203,2 +210,3 @@ key: "subscribeEvent",

}
/**

@@ -211,3 +219,2 @@ * Unregister a callback for a specified event

*/
}, {

@@ -219,18 +226,18 @@ key: "unsubscribeEvent",

return false;
} // If a callback is specified, unsub this one
}
// If a callback is specified, unsub this one
if (callback) {
var idx = this.eventCallbacks[event].indexOf(callback);
if (idx >= 0) {
this.eventCallbacks[event].splice(idx, 1);
}
} // Unsub all
}
// Unsub all
else {
this.eventCallbacks[event] = [];
}
return !callback || this.eventCallbacks[event].length === 0;
}
/**

@@ -241,3 +248,2 @@ * Process a message received from postMessage

*/
}, {

@@ -252,2 +258,3 @@ key: "process",

}
/**

@@ -258,3 +265,2 @@ * Process a method response

*/
}, {

@@ -266,9 +272,6 @@ key: "processMethodResponse",

}
var promise = this.promises[data.method].shift();
if (!promise) {
return;
}
if (data.error) {

@@ -280,2 +283,3 @@ promise.reject(data.error);

}
/**

@@ -286,3 +290,2 @@ * Process a receieved event

*/
}, {

@@ -292,7 +295,5 @@ key: "processEvent",

var _this = this;
if (!this.eventCallbacks[data.event] || this.eventCallbacks[data.event].length === 0) {
return;
}
this.eventCallbacks[data.event].forEach(function (callback) {

@@ -303,3 +304,2 @@ callback.call(_this.embed, data.parameters);

}]);
return EmbedCallback;

@@ -310,3 +310,2 @@ }();

var embedsReady = new WeakMap();
var Embed = /*#__PURE__*/function () {

@@ -322,18 +321,15 @@ /**

var _this = this;
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Embed);
element = normalizeElement(element);
element = normalizeElement(element); // Keep a single object instance per iframe
// Keep a single object instance per iframe
if (embeds.has(element)) {
return embeds.get(element);
} // Create new element iframe if needed
}
// Create new element iframe if needed
if (element.nodeName !== 'IFRAME') {
element = createEmbedIframe(element, params);
}
this.origin = '*';

@@ -348,19 +344,18 @@ this.element = element;

}
if (_this.origin === '*') {
_this.origin = event.origin;
} // Parse inbound message
}
// Parse inbound message
var data = parseMessage(event.data);
var data = parseMessage(event.data); // Mark the embed as ready
// Mark the embed as ready
if (data.event === 'ready' || data.method === 'ping') {
resolve();
return;
} // Process regular messages from the embed
}
// Process regular messages from the embed
_this.embedCallback.process(data);
};
window.addEventListener('message', onMessage, false);

@@ -373,3 +368,2 @@ postMessage(_this, 'ping');

}
_createClass(Embed, [{

@@ -384,3 +378,2 @@ key: "ready",

var _this2 = this;
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -390,3 +383,2 @@ return new Promise(function (resolve, reject) {

_this2.embedCallback.pushCall(method, resolve, reject);
postMessage(_this2, method, parameters);

@@ -396,2 +388,3 @@ });

}
/**

@@ -403,3 +396,2 @@ * Subscribe to a specific event

*/
}, {

@@ -411,7 +403,5 @@ key: "on",

}
if (typeof callback !== 'function') {
throw new TypeError('An callback (function) is required');
}
if (this.embedCallback.subscribeEvent(event, callback)) {

@@ -421,2 +411,3 @@ this.call('addEventListener', event).catch(function () {});

}
/**

@@ -428,3 +419,2 @@ * Unsubscribe to a specific event

*/
}, {

@@ -436,3 +426,2 @@ key: "off",

}
if (this.embedCallback.unsubscribeEvent(event, callback)) {

@@ -442,2 +431,3 @@ this.call('removeEventListener', event).catch(function () {});

}
/**

@@ -450,3 +440,2 @@ * Load a score hosted on Flat

*/
}, {

@@ -460,5 +449,5 @@ key: "loadFlatScore",

}
return this.call('loadFlatScore', score);
}
/**

@@ -471,3 +460,2 @@ * Load a MusicXML score

*/
}, {

@@ -478,2 +466,3 @@ key: "loadMusicXML",

}
/**

@@ -486,3 +475,2 @@ * Load a Flat JSON score

*/
}, {

@@ -493,2 +481,3 @@ key: "loadJSON",

}
/**

@@ -500,3 +489,2 @@ * Get the score in Flat JSON format

*/
}, {

@@ -507,2 +495,3 @@ key: "getJSON",

}
/**

@@ -516,3 +505,2 @@ * Convert the displayed score in MusicXML

*/
}, {

@@ -522,10 +510,7 @@ key: "getMusicXML",

var _this3 = this;
return new Promise(function (resolve, reject) {
options = options || {};
if (_typeof(options) !== 'object') {
return reject(new TypeError('Options must be an object'));
}
_this3.call('getMusicXML', options).then(function (data) {

@@ -535,5 +520,4 @@ // Plain XML

return resolve(data);
} // Compressed, re-create Uint8Array
}
// Compressed, re-create Uint8Array
return resolve(new Uint8Array(data));

@@ -543,2 +527,3 @@ }).catch(reject);

}
/**

@@ -551,3 +536,2 @@ * Convert the displayed score in PNG

*/
}, {

@@ -557,10 +541,7 @@ key: "getPNG",

var _this4 = this;
return new Promise(function (resolve, reject) {
options = options || {};
if (_typeof(options) !== 'object') {
return reject(new TypeError('Options must be an object'));
}
_this4.call('getPNG', options).then(function (data) {

@@ -570,3 +551,2 @@ if (typeof data === 'string') {

}
return resolve(new Uint8Array(data));

@@ -576,2 +556,3 @@ }).catch(reject);

}
/**

@@ -584,3 +565,2 @@ * Convert the displayed score in MIDI

*/
}, {

@@ -593,2 +573,3 @@ key: "getMIDI",

}
/**

@@ -600,3 +581,2 @@ * Get the metadata of the score (for scores hosted on Flat)

*/
}, {

@@ -607,2 +587,3 @@ key: "getFlatScoreMetadata",

}
/**

@@ -614,3 +595,2 @@ * Get the whole embed config

*/
}, {

@@ -621,2 +601,3 @@ key: "getEmbedConfig",

}
/**

@@ -631,3 +612,2 @@ * Set a config for the embed mode

*/
}, {

@@ -638,2 +618,3 @@ key: "setEditorConfig",

}
/**

@@ -645,3 +626,2 @@ * Toggle fullscreen state

*/
}, {

@@ -652,2 +632,3 @@ key: "fullscreen",

}
/**

@@ -658,3 +639,2 @@ * Start the playback

*/
}, {

@@ -665,2 +645,3 @@ key: "play",

}
/**

@@ -671,3 +652,2 @@ * Pause the playback

*/
}, {

@@ -678,2 +658,3 @@ key: "pause",

}
/**

@@ -684,3 +665,2 @@ * Stop the playback

*/
}, {

@@ -691,2 +671,3 @@ key: "stop",

}
/**

@@ -697,3 +678,2 @@ * Mute playback

*/
}, {

@@ -704,2 +684,3 @@ key: "mute",

}
/**

@@ -710,3 +691,2 @@ * Get the current master volume

*/
}, {

@@ -717,8 +697,8 @@ key: "getMasterVolume",

}
/**
* Get the current master volume
* Set the current master volume
*
* @return {Promise}
*/
}, {

@@ -729,2 +709,3 @@ key: "setMasterVolume",

}
/**

@@ -735,3 +716,2 @@ * Get the volume of a part

*/
}, {

@@ -742,2 +722,3 @@ key: "getPartVolume",

}
/**

@@ -748,3 +729,2 @@ * Set the volume of a part

*/
}, {

@@ -755,2 +735,3 @@ key: "setPartVolume",

}
/**

@@ -761,3 +742,2 @@ * Mute a part

*/
}, {

@@ -768,2 +748,3 @@ key: "mutePart",

}
/**

@@ -774,3 +755,2 @@ * Mute a part

*/
}, {

@@ -781,2 +761,3 @@ key: "unmutePart",

}
/**

@@ -787,3 +768,2 @@ * Enable the solo mode for a part

*/
}, {

@@ -794,2 +774,3 @@ key: "setPartSoloMode",

}
/**

@@ -800,3 +781,2 @@ * Disable the solo mode for a part

*/
}, {

@@ -807,2 +787,3 @@ key: "unsetPartSoloMode",

}
/**

@@ -813,3 +794,2 @@ * Get the state of the solo mode of a part

*/
}, {

@@ -820,2 +800,3 @@ key: "getPartSoloMode",

}
/**

@@ -826,3 +807,2 @@ * Get the volume of a part

*/
}, {

@@ -833,2 +813,3 @@ key: "getPartReverb",

}
/**

@@ -839,3 +820,2 @@ * Set the volume of a part

*/
}, {

@@ -846,2 +826,3 @@ key: "setPartReverb",

}
/**

@@ -852,3 +833,2 @@ * Configure a new audio or video track

*/
}, {

@@ -859,2 +839,3 @@ key: "setTrack",

}
/**

@@ -865,3 +846,2 @@ * Enabled a previously configured track

*/
}, {

@@ -872,2 +852,3 @@ key: "useTrack",

}
/**

@@ -878,3 +859,2 @@ * Seek the audio track to a specified duration

*/
}, {

@@ -885,2 +865,3 @@ key: "seekTrackTo",

}
/**

@@ -891,3 +872,2 @@ * Print the score

*/
}, {

@@ -898,2 +878,3 @@ key: "print",

}
/**

@@ -905,3 +886,2 @@ * Get the current zoom ratio

*/
}, {

@@ -912,2 +892,3 @@ key: "getZoom",

}
/**

@@ -920,3 +901,2 @@ * Set a new zoom ratio (this will disable the zoom auto if set)

*/
}, {

@@ -927,2 +907,3 @@ key: "setZoom",

}
/**

@@ -934,3 +915,2 @@ * Get the auto-zoom

*/
}, {

@@ -941,2 +921,3 @@ key: "getAutoZoom",

}
/**

@@ -949,3 +930,2 @@ * Enable or disable the auto-zoom

*/
}, {

@@ -956,2 +936,3 @@ key: "setAutoZoom",

}
/**

@@ -962,3 +943,2 @@ * Set the focus to the score

*/
}, {

@@ -969,2 +949,3 @@ key: "focusScore",

}
/**

@@ -976,3 +957,2 @@ * Get cursor position

*/
}, {

@@ -983,2 +963,3 @@ key: "getCursorPosition",

}
/**

@@ -991,3 +972,2 @@ * Set cursor position

*/
}, {

@@ -998,2 +978,3 @@ key: "setCursorPosition",

}
/**

@@ -1005,3 +986,2 @@ * Get all the parts information

*/
}, {

@@ -1012,2 +992,3 @@ key: "getParts",

}
/**

@@ -1019,3 +1000,2 @@ * Get the displayed parts

*/
}, {

@@ -1026,2 +1006,3 @@ key: "getDisplayedParts",

}
/**

@@ -1033,3 +1014,2 @@ * Choose the parts to display

*/
}, {

@@ -1040,3 +1020,28 @@ key: "setDisplayedParts",

}
/**
* Get the number of measures in the score.
*
* @return {Promise}
* @fullfill {Number} The number of measures in the score
*/
}, {
key: "getNbMeasures",
value: function getNbMeasures() {
return this.call('getNbMeasures');
}
/**
* Get the measures uuids of the score
*
* @return {Promise}
* @fullfill {Array} The list of measures uuids.
*/
}, {
key: "getMeasuresUuids",
value: function getMeasuresUuids() {
return this.call('getMeasuresUuids');
}
/**
* Get all the parts information

@@ -1047,3 +1052,2 @@ *

*/
}, {

@@ -1054,2 +1058,3 @@ key: "getMeasureDetails",

}
/**

@@ -1061,3 +1066,2 @@ * Get all the parts information

*/
}, {

@@ -1068,4 +1072,112 @@ key: "getNoteDetails",

}
/**
* Move the cursor to the next left item in the score (grace note, note or rest).
*
* @param {Boolean} mute false to play the note the cursor is moving to
* @return {Promise}
* @fullfill {Promise}
*/
}, {
key: "goLeft",
value: function goLeft() {
var mute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
return this.call('goLeft', {
mute: mute
});
}
/**
* Move the cursor to the next right item in the score (grace note, note or rest).
*
* @param {Boolean} mute false to play the note the cursor is moving to
* @return {Promise}
* @fullfill {Promise}
*/
}, {
key: "goRight",
value: function goRight() {
var mute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
return this.call('goRight', {
mute: mute
});
}
/**
* Get the current metronome mode
*
* @returns {Promise}
* @fullfill {Number} The metronome mode
*/
}, {
key: "getMetronomeMode",
value: function getMetronomeMode() {
return this.call('getMetronomeMode');
}
/**
* Sett the metronome mode.
*
* Mode is defined as:
* ``` javascript
* const METRONOME_MODES = {
* COUNT_IN: 0,
* CONTINUOUS: 1,
* DISABLED: 2,
* };
* ```
*
* @param {Number} mode the new metronome mode
* @return {Promise}
*/
}, {
key: "setMetronomeMode",
value: function setMetronomeMode(mode) {
return this.call('setMetronomeMode', {
mode: mode
});
}
/**
* Get the current metronome mode
*
* @returns {Promise}
* @fullfill {Number} The Playback speed
*/
}, {
key: "getPlaybackSpeed",
value: function getPlaybackSpeed() {
return this.call('getPlaybackSpeed');
}
/**
* Set the playback speed.
*
* 1 is the normal value, then it is a value between 0.2 and 2.
*
* @param {Number} speed the new playback speed
* @return {Promise}
*/
}, {
key: "setPlaybackSpeed",
value: function setPlaybackSpeed(speed) {
return this.call('setPlaybackSpeed', {
speed: speed
});
}
/**
* Scroll to the cursor position in the score.
*
* The scrolling is done asynchronously, so it is not guaranteed that it will be complete
* by the time the callback is called.
*
* @return {Promise}
*/
}, {
key: "scrollToCursor",
value: function scrollToCursor() {
return this.call('scrollToCursor');
}
}]);
return Embed;

@@ -1072,0 +1184,0 @@ }();

@@ -1,2 +0,2 @@

/*! flat-embed v1.4.1 | (c) 2022 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){t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1})}if(void 0===window.postMessage)throw new Error("The Flat Embed JS API is not supported in this browser");function t(e,t){r=t.baseUrl||"https://flat-embed.com",r+="/"+(t.score||"blank"),n=Object.assign({jsapi:!0},t.embedParams);var n,r=r+"?"+Object.keys(n).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n[e]))}).join("&"),o=document.createElement("iframe");return o.setAttribute("src",r),o.setAttribute("width",t.width||"100%"),o.setAttribute("height",t.height||"100%"),o.setAttribute("allowfullscreen",!0),o.setAttribute("allow","midi"),o.setAttribute("frameborder","0"),e.appendChild(o),o}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}(),l=new WeakMap,u=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)return e="IFRAME"!==e.nodeName&&(t=e.querySelector("iframe"))?t:e;var t;throw new TypeError("The first parameter must be an existing DOM element or an identifier.")}(n),l.has(n))return l.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?t():r.embedCallback.process(e))},!1),a(r,"ping")});return l.set(this.element,this),u.set(this.element,e),this}return e(Embed,[{key:"ready",value:function(){return u.get(this.element)}},{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}()});
/*! flat-embed v1.5.0 | (c) 2023 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,function(e){e=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"==typeof e?e:String(e)}(r.key),r)}}function e(e,t,n){t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1})}if(void 0===window.postMessage)throw new Error("The Flat Embed JS API is not supported in this browser");function t(e,t){r=t.baseUrl||"https://flat-embed.com",r+="/"+(t.score||"blank"),n=Object.assign({jsapi:!0},t.embedParams);var n,r=r+"?"+Object.keys(n).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n[e]))}).join("&"),o=document.createElement("iframe");return o.setAttribute("src",r),o.setAttribute("width",t.width||"100%"),o.setAttribute("height",t.height||"100%"),o.setAttribute("allowfullscreen",!0),o.setAttribute("allow","midi"),o.setAttribute("frameborder","0"),e.appendChild(o),o}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 u=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){var n;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)}},{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}(),l=new WeakMap,s=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){var t;if((e="string"==typeof(e=window.jQuery&&e instanceof window.jQuery?e[0]:e)?document.getElementById(e):e)instanceof window.HTMLElement)return e="IFRAME"!==e.nodeName&&(t=e.querySelector("iframe"))?t:e;throw new TypeError("The first parameter must be an existing DOM element or an identifier.")}(n),l.has(n))return l.get(n);"IFRAME"!==n.nodeName&&(n=t(n,e)),this.origin="*",this.element=n,this.embedCallback=new u;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?t():r.embedCallback.process(e))},!1),a(r,"ping")});return l.set(this.element,this),s.set(this.element,e),this}return e(Embed,[{key:"ready",value:function(){return s.get(this.element)}},{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:"getNbMeasures",value:function(){return this.call("getNbMeasures")}},{key:"getMeasuresUuids",value:function(){return this.call("getMeasuresUuids")}},{key:"getMeasureDetails",value:function(){return this.call("getMeasureDetails")}},{key:"getNoteDetails",value:function(){return this.call("getNoteDetails")}},{key:"goLeft",value:function(){return this.call("goLeft",{mute:0<arguments.length&&void 0!==arguments[0]&&arguments[0]})}},{key:"goRight",value:function(){return this.call("goRight",{mute:0<arguments.length&&void 0!==arguments[0]&&arguments[0]})}},{key:"getMetronomeMode",value:function(){return this.call("getMetronomeMode")}},{key:"setMetronomeMode",value:function(e){return this.call("setMetronomeMode",{mode:e})}},{key:"getPlaybackSpeed",value:function(){return this.call("getPlaybackSpeed")}},{key:"setPlaybackSpeed",value:function(e){return this.call("setPlaybackSpeed",{speed:e})}},{key:"scrollToCursor",value:function(){return this.call("scrollToCursor")}}]),Embed}()});
{
"name": "flat-embed",
"version": "1.4.1",
"version": "1.5.0",
"description": "Interact and get events from Flat's Sheet Music Embed",

@@ -46,7 +46,7 @@ "license": "Apache-2.0",

"jquery": "^3.6.0",
"karma": "6.3.19",
"karma": "6.4.1",
"karma-chrome-launcher": "3.1.1",
"karma-mocha": "2.0.1",
"karma-mocha-reporter": "^2.2.3",
"mocha": "^9.2.1",
"mocha": "^10.0.0",
"rollup": "^2.68.0",

@@ -53,0 +53,0 @@ "rollup-plugin-babel": "^4.4.0",

@@ -14,6 +14,7 @@ # Flat Sheet Music Embed Client

You can install our Embed Client using [npm](https://www.npmjs.com/package/flat-embed) or [yarn](https://yarnpkg.com/en/package/flat-embed):
You can install our Embed Client using [npm](https://www.npmjs.com/package/flat-embed), pnpm, or [yarn](https://yarnpkg.com/en/package/flat-embed):
```bash
npm install flat-embed
pnpm add flat-embed
yarn add flat-embed

@@ -25,3 +26,3 @@ ```

```html
<script src="https://prod.flat-cdn.com/embed-js/v1.4.0/embed.min.js"></script>
<script src="https://prod.flat-cdn.com/embed-js/v1.5.0/embed.min.js"></script>
```

@@ -35,3 +36,3 @@

<div id="embed-container"></div>
<script src="https://prod.flat-cdn.com/embed-js/v1.4.0/embed.min.js"></script>
<script src="https://prod.flat-cdn.com/embed-js/v1.5.0/embed.min.js"></script>
<script>

@@ -131,2 +132,7 @@ var container = document.getElementById('embed-container');

* [`setPartReverb`](#setpartreverb-partuuid-string-reverberation-number--promisevoid-error): Set a part reverberation
* [`getMetronomeMode`](#getMetronomeMode-promisenumber-error): Get the mode of the metronome counting
* [`setMetronomeMode`](#setMetronomeMode-number--promisevoid-error): Set the mode of the metronome counting
* [`getPlaybackSpeed`](#getPlaybackSpeed-promisenumber-error): Get the playback speed
* [`setPlaybackSpeed`](#setPlaybackSpeed-number--promisevoid-error): Set the playback speed
* [`scrollToCursor`](#scrollToCursor-promisevoid-error): Scroll to the cursor position in the score
* [`setTrack`](#settrackobject-promisevoid-error): Configure an new audio track to use

@@ -148,2 +154,6 @@ * [`useTrack`](#usetrack-id--promisevoid-error): Use a configured audio track

* [`getNoteDetails`](#getnotedetails-promiseobject-error): Get details about the current note
* [`getNbMeasures`](#getnbmeasures-promisenumber-error): Get the number of measures in the score
* [`getMeasuresUuids`](#getmeasuresuuids-promisearray-error): Get the list of measures uuids of the score
* [`goLeft`](#play-promisevoid-error): Move the cursor the previous note/rest
* [`goRight`](#play-promisevoid-error): Move the cursor the next note/rest
* [Editor API](#editor-api)

@@ -576,2 +586,62 @@ * [Events API](#events-api)

### `getMetronomeMode(): Promise<Number, Error>`
Get the value of the metronome count-in mode.
Mode is defined as:
```js
const METRONOME_MODES = {
COUNT_IN: 0,// Count in at the beginning of the playback
CONTINUOUS: 1,// Always on
DISABLED: 2,
};
```
```js
embed.getMetronomeMode().then(function (metronomeMode) {
assert.strictEqual(metronomeMode, METRONOME_MODES.COUNT_IN);
assert.strictEqual(metronomeMode, 0);
});
```
### `setMetronomeMode(number): Promise<void, Error>`
Set the metronome count-in mode.
```js
embed.setMetronomeMode(1).then(function () {
// The metronome mode is set
});
```
### `getPlaybackSpeed(): Promise<Number, Error>`
Get the playback speed.
```js
embed.getPlaybackSpeed().then(function (playbackSpeed) {
assert.strictEqual(playbackSpeed, 1);
});
```
### `setPlaybackSpeed(number): Promise<void, Error>`
Set the playback speed. Normal value is 1. The value can be between 0.2 and 2.
```js
embed.setPlaybackSpeed(1.5).then(function () {
// The playback speed is set
});
```
### `scrollToCursor(): Promise<void, Error>`
For the display to scroll at the position of the cursor in the score
```js
embed.scrollToCursor().then(function () {
// The scrolling is done asynchronously, it is not guarenteed that it will be completed here.
});
```
### `setTrack(object): Promise<void, Error>`

@@ -885,2 +955,47 @@

### `getNbMeasures(): Promise(<number, Error>)`
Get the number of measures within the score
```js
embed.getNoteDetails().then(function (nbMeasures) {
assert.strictEqual(nbMeasures, 5);
});
```
### `getMeasuresUuids(): Promise(<array, Error>)`
Get the number of measures within the score
```js
embed.getMeasuresUuids().then(function (measuresUuids) {
assert.strictEqual(measuresUuids, [
'05a4daec-bc78-5987-81e4-2467e234dfb2',
'08b9110b-82bb-11e5-f57c-7b0f47a6a69a',
'3c176017-31ff-cc91-7ad6-a2ea4a510200',
'833ca409-04e9-0b76-52db-105777bd7a56',
]);
});
```
### `goLeft(): Promise(<void, Error>)`
Get the number of measures within the score
```js
embed.goLeft().then(function () {
// The cursor is moved to the previous item on the left
});
```
### `goRight(): Promise(<void, Error>)`
Get the number of measures within the score
```js
embed.goRight().then(function () {
// The cursor is moved to the next item on the right
});
```
## Editor API

@@ -887,0 +1002,0 @@

@@ -74,3 +74,3 @@ import './lib/compatibility';

call(method, parameters={}) {
call(method, parameters = {}) {
return new Promise((resolve, reject) => {

@@ -98,3 +98,3 @@ return this.ready().then(() => {

if (this.embedCallback.subscribeEvent(event, callback)) {
this.call('addEventListener', event).catch(() => {});
this.call('addEventListener', event).catch(() => { });
}

@@ -114,3 +114,3 @@ }

if (this.embedCallback.unsubscribeEvent(event, callback)) {
this.call('removeEventListener', event).catch(() => {});
this.call('removeEventListener', event).catch(() => { });
}

@@ -197,16 +197,16 @@ }

*/
getPNG(options) {
return new Promise((resolve, reject) => {
options = options || {};
if (typeof options !== 'object') {
return reject(new TypeError('Options must be an object'));
}
this.call('getPNG', options).then((data) => {
if (typeof data === 'string') {
return resolve(data);
}
return resolve(new Uint8Array(data));
}).catch(reject);
});
}
getPNG(options) {
return new Promise((resolve, reject) => {
options = options || {};
if (typeof options !== 'object') {
return reject(new TypeError('Options must be an object'));
}
this.call('getPNG', options).then((data) => {
if (typeof data === 'string') {
return resolve(data);
}
return resolve(new Uint8Array(data));
}).catch(reject);
});
}

@@ -240,5 +240,5 @@ /**

*/
getEmbedConfig() {
return this.call('getEmbedConfig');
}
getEmbedConfig() {
return this.call('getEmbedConfig');
}

@@ -254,5 +254,5 @@ /**

*/
setEditorConfig(editor) {
return this.call('setEditorConfig', editor);
}
setEditorConfig(editor) {
return this.call('setEditorConfig', editor);
}

@@ -315,3 +315,3 @@ /**

/**
* Get the current master volume
* Set the current master volume
*

@@ -544,2 +544,22 @@ * @return {Promise}

/**
* Get the number of measures in the score.
*
* @return {Promise}
* @fullfill {Number} The number of measures in the score
*/
getNbMeasures() {
return this.call('getNbMeasures');
}
/**
* Get the measures uuids of the score
*
* @return {Promise}
* @fullfill {Array} The list of measures uuids.
*/
getMeasuresUuids() {
return this.call('getMeasuresUuids');
}
/**
* Get all the parts information

@@ -563,4 +583,89 @@ *

}
/**
* Move the cursor to the next left item in the score (grace note, note or rest).
*
* @param {Boolean} mute false to play the note the cursor is moving to
* @return {Promise}
* @fullfill {Promise}
*/
goLeft(mute = false) {
return this.call('goLeft', { mute });
}
/**
* Move the cursor to the next right item in the score (grace note, note or rest).
*
* @param {Boolean} mute false to play the note the cursor is moving to
* @return {Promise}
* @fullfill {Promise}
*/
goRight(mute = false) {
return this.call('goRight', { mute });
}
/**
* Get the current metronome mode
*
* @returns {Promise}
* @fullfill {Number} The metronome mode
*/
getMetronomeMode() {
return this.call('getMetronomeMode');
}
/**
* Sett the metronome mode.
*
* Mode is defined as:
* ``` javascript
* const METRONOME_MODES = {
* COUNT_IN: 0,
* CONTINUOUS: 1,
* DISABLED: 2,
* };
* ```
*
* @param {Number} mode the new metronome mode
* @return {Promise}
*/
setMetronomeMode(mode) {
return this.call('setMetronomeMode', { mode });
}
/**
* Get the current metronome mode
*
* @returns {Promise}
* @fullfill {Number} The Playback speed
*/
getPlaybackSpeed() {
return this.call('getPlaybackSpeed');
}
/**
* Set the playback speed.
*
* 1 is the normal value, then it is a value between 0.2 and 2.
*
* @param {Number} speed the new playback speed
* @return {Promise}
*/
setPlaybackSpeed(speed) {
return this.call('setPlaybackSpeed', { speed });
}
/**
* Scroll to the cursor position in the score.
*
* The scrolling is done asynchronously, so it is not guaranteed that it will be complete
* by the time the callback is called.
*
* @return {Promise}
*/
scrollToCursor() {
return this.call('scrollToCursor');
}
}
export default Embed;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc