Socket
Socket
Sign inDemoInstall

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 0.11.0 to 1.0.0

4

CHANGELOG.md
# Changelog
## v1.0.0
* Host on our CDN (`https://prod.flat-cdn.com/embed-js/${VERSION}/embed.min.js`)
## v0.11.0

@@ -4,0 +8,0 @@

271

dist/embed.js

@@ -1,8 +0,44 @@

/*! flat-embed v0.10.0 | (c) 2018 Tutteo Ltd. (Flat) | Apache-2.0 License | https://github.com/FlatIO/embed-client */
/*! flat-embed v1.0.0 | (c) 2019 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.Flat = global.Flat || {}, global.Flat.Embed = factory());
}(this, (function () { 'use strict';
(global = global || self, (global.Flat = global.Flat || {}, global.Flat.Embed = factory()));
}(this, function () { 'use strict';
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
if (typeof window.postMessage === 'undefined') {

@@ -21,18 +57,19 @@ throw new Error('The Flat Embed JS API is not supported in this browser');

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) {

@@ -52,19 +89,14 @@ element = iframe;

function buildIframeUrl(parameters) {
var url = parameters.baseUrl || 'https://flat-embed.com';
var url = parameters.baseUrl || 'https://flat-embed.com'; // Score id or blank embed
// Score id or blank embed
url += '/' + (parameters.score || 'blank');
url += '/' + (parameters.score || 'blank'); // Build qs parameters
// Build qs parameters
var urlParameters = Object.assign({
jsapi: true
}, parameters.embedParams);
var qs = Object.keys(urlParameters).map(function (k) {
return encodeURIComponent(k) + '=' + encodeURIComponent(urlParameters[k]);
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(urlParameters[k]));
}).join('&');
return url + '?' + qs;
}
/**

@@ -76,5 +108,5 @@ * Create an iframe inside a specified element

*/
function createEmbedIframe(element, parameters) {
var url = buildIframeUrl(parameters);
var iframe = document.createElement('iframe');

@@ -86,5 +118,3 @@ iframe.setAttribute('src', url);

iframe.setAttribute('frameborder', '0');
element.appendChild(iframe);
return iframe;

@@ -109,6 +139,4 @@ }

};
embed.element.contentWindow.postMessage(message, embed.origin);
}
/**

@@ -120,2 +148,3 @@ * Parse a message received from postMessage

*/
function parseMessage(data) {

@@ -125,38 +154,11 @@ if (typeof data === 'string') {

}
return data;
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var EmbedCallback = function () {
var EmbedCallback =
/*#__PURE__*/
function () {
function EmbedCallback(embed) {
classCallCheck(this, EmbedCallback);
_classCallCheck(this, EmbedCallback);

@@ -169,9 +171,11 @@ this.embed = embed;

createClass(EmbedCallback, [{
_createClass(EmbedCallback, [{
key: "pushCall",
value: function pushCall(name, resolve, reject) {
this.promises[name] = this.promises[name] || [];
this.promises[name].push({ resolve: resolve, reject: reject });
this.promises[name].push({
resolve: resolve,
reject: reject
});
}
/**

@@ -192,3 +196,2 @@ * Register a callback for a specified event

}
/**

@@ -208,12 +211,12 @@ * Unregister a callback for a specified event

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 {

@@ -225,3 +228,2 @@ this.eventCallbacks[event] = [];

}
/**

@@ -242,3 +244,2 @@ * Process a message received from postMessage

}
/**

@@ -256,6 +257,9 @@ * Process a method response

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

@@ -267,3 +271,2 @@ promise.reject(data.error);

}
/**

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

}
this.eventCallbacks[data.event].forEach(function (callback) {

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

}]);
return EmbedCallback;

@@ -296,3 +301,5 @@ }();

var Embed = function () {
var Embed =
/*#__PURE__*/
function () {
/**

@@ -309,12 +316,12 @@ * Create a new Flat Embed

var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
classCallCheck(this, Embed);
element = normalizeElement(element);
_classCallCheck(this, Embed);
// Keep a single object instance per iframe
element = normalizeElement(element); // 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') {

@@ -327,3 +334,2 @@ element = createEmbedIframe(element, params);

this.embedCallback = new EmbedCallback();
var onReady = new Promise(function (resolve) {

@@ -338,14 +344,13 @@ // Handle incoming messages from embed

_this.origin = event.origin;
}
} // Parse inbound message
// Parse inbound message
var data = parseMessage(event.data);
// Mark the embed as ready
var data = parseMessage(event.data); // 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);

@@ -357,11 +362,9 @@ };

});
embeds.set(this.element, this);
embedsReady.set(this, onReady);
return this;
}
createClass(Embed, [{
key: 'ready',
_createClass(Embed, [{
key: "ready",
value: function ready() {

@@ -371,3 +374,3 @@ return Promise.resolve(embedsReady.get(this));

}, {
key: 'call',
key: "call",
value: function call(method) {

@@ -377,6 +380,6 @@ var _this2 = this;

var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Promise(function (resolve, reject) {
return _this2.ready().then(function () {
_this2.embedCallback.pushCall(method, resolve, reject);
postMessage(_this2, method, parameters);

@@ -386,3 +389,2 @@ });

}
/**

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

}, {
key: 'on',
key: "on",
value: function on(event, callback) {

@@ -402,5 +404,7 @@ if (typeof event !== 'string') {

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

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

}
/**

@@ -420,3 +423,3 @@ * Unsubscribe to a specific event

}, {
key: 'off',
key: "off",
value: function off(event, callback) {

@@ -426,2 +429,3 @@ if (typeof event !== 'string') {

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

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

}
/**

@@ -443,7 +446,9 @@ * Load a score hosted on Flat

}, {
key: 'loadFlatScore',
key: "loadFlatScore",
value: function loadFlatScore(score, revision) {
return this.call('loadFlatScore', { score: score, revision: revision });
return this.call('loadFlatScore', {
score: score,
revision: revision
});
}
/**

@@ -458,7 +463,6 @@ * Load a MusicXML score

}, {
key: 'loadMusicXML',
key: "loadMusicXML",
value: function loadMusicXML(score) {
return this.call('loadMusicXML', score);
}
/**

@@ -473,7 +477,6 @@ * Load a Flat JSON score

}, {
key: 'loadJSON',
key: "loadJSON",
value: function loadJSON(score) {
return this.call('loadJSON', score);
}
/**

@@ -487,7 +490,6 @@ * Get the score in Flat JSON format

}, {
key: 'getJSON',
key: "getJSON",
value: function getJSON() {
return this.call('getJSON');
}
/**

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

}, {
key: 'getMusicXML',
key: "getMusicXML",
value: function getMusicXML(options) {

@@ -510,5 +512,7 @@ var _this3 = this;

options = options || {};
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
if (_typeof(options) !== 'object') {
return reject(new TypeError('Options must be an object'));
}
_this3.call('getMusicXML', options).then(function (data) {

@@ -518,4 +522,5 @@ // Plain XML

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

@@ -525,3 +530,2 @@ }).catch(reject);

}
/**

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

}, {
key: 'getPNG',
key: "getPNG",
value: function getPNG(options) {

@@ -543,5 +547,7 @@ var _this4 = this;

options = options || {};
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
if (_typeof(options) !== 'object') {
return reject(new TypeError('Options must be an object'));
}
_this4.call('getPNG', options).then(function (data) {

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

}
return resolve(new Uint8Array(data));

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

}
/**

@@ -567,3 +573,3 @@ * Convert the displayed score in MIDI

}, {
key: 'getMIDI',
key: "getMIDI",
value: function getMIDI() {

@@ -574,3 +580,2 @@ return this.call('getMIDI').then(function (data) {

}
/**

@@ -584,7 +589,6 @@ * Get the metadata of the score (for scores hosted on Flat)

}, {
key: 'getFlatScoreMetadata',
key: "getFlatScoreMetadata",
value: function getFlatScoreMetadata() {
return this.call('getFlatScoreMetadata');
}
/**

@@ -598,7 +602,6 @@ * Get the whole embed config

}, {
key: 'getEmbedConfig',
key: "getEmbedConfig",
value: function getEmbedConfig() {
return this.call('getEmbedConfig');
}
/**

@@ -615,7 +618,6 @@ * Set a config for the embed mode

}, {
key: 'setEditorConfig',
key: "setEditorConfig",
value: function setEditorConfig(editor) {
return this.call('setEditorConfig', editor);
}
/**

@@ -629,7 +631,6 @@ * Toggle fullscreen state

}, {
key: 'fullscreen',
key: "fullscreen",
value: function fullscreen(active) {
return this.call('fullscreen', active);
}
/**

@@ -642,7 +643,6 @@ * Start the playback

}, {
key: 'play',
key: "play",
value: function play() {
return this.call('play');
}
/**

@@ -655,7 +655,6 @@ * Pause the playback

}, {
key: 'pause',
key: "pause",
value: function pause() {
return this.call('pause');
}
/**

@@ -668,7 +667,6 @@ * Stop the playback

}, {
key: 'stop',
key: "stop",
value: function stop() {
return this.call('stop');
}
/**

@@ -681,7 +679,6 @@ * Mute playback

}, {
key: 'mute',
key: "mute",
value: function mute() {
return this.call('mute');
}
/**

@@ -694,7 +691,6 @@ * Print the score

}, {
key: 'print',
key: "print",
value: function print() {
return this.call('print');
}
/**

@@ -708,7 +704,6 @@ * Get the current zoom ratio

}, {
key: 'getZoom',
key: "getZoom",
value: function getZoom() {
return this.call('getZoom');
}
/**

@@ -723,7 +718,6 @@ * Set a new zoom ratio (this will disable the zoom auto if set)

}, {
key: 'setZoom',
key: "setZoom",
value: function setZoom(zoom) {
return this.call('setZoom', zoom);
}
/**

@@ -737,7 +731,6 @@ * Get the auto-zoom

}, {
key: 'getAutoZoom',
key: "getAutoZoom",
value: function getAutoZoom() {
return this.call('getAutoZoom');
}
/**

@@ -752,7 +745,6 @@ * Enable or disable the auto-zoom

}, {
key: 'setAutoZoom',
key: "setAutoZoom",
value: function setAutoZoom(state) {
return this.call('setAutoZoom', state);
}
/**

@@ -765,7 +757,6 @@ * Set the focus to the score

}, {
key: 'focusScore',
key: "focusScore",
value: function focusScore() {
return this.call('focusScore');
}
/**

@@ -779,7 +770,6 @@ * Get cursor position

}, {
key: 'getCursorPosition',
key: "getCursorPosition",
value: function getCursorPosition() {
return this.call('getCursorPosition');
}
/**

@@ -794,3 +784,3 @@ * Set cursor position

}, {
key: 'setCursorPosition',
key: "setCursorPosition",
value: function setCursorPosition(position) {

@@ -800,2 +790,3 @@ return this.call('setCursorPosition', position);

}]);
return Embed;

@@ -806,4 +797,4 @@ }();

})));
}));
//# sourceMappingURL=embed.js.map

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

/*! flat-embed v0.10.0 | (c) 2018 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.Flat=e.Flat||{},e.Flat.Embed=t())}(this,function(){"use strict";if(void 0===window.postMessage)throw new Error("The Flat Embed JS API is not supported in this browser");function n(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 encodeURIComponent(e)+"="+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("frameborder","0"),e.appendChild(r),r}function s(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 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},r=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e=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)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),a=function(){function t(e){return r(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(o){var i=this,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(r(this,Embed),o=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}(o),u.has(o))return u.get(o);"IFRAME"!==o.nodeName&&(o=n(o,e)),this.origin="*",this.element=o,this.embedCallback=new a;var t=new Promise(function(r){window.addEventListener("message",function(e){if(o.contentWindow===e.source){"*"===i.origin&&(i.origin=e.origin);var t,n=("string"==typeof(t=e.data)&&(t=JSON.parse(t)),t);"ready"!==n.event&&"ping"!==n.method?i.embedCallback.process(n):r()}},!1),s(i,"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),s(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"!==(void 0===(n=n||{})?"undefined":o(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"!==(void 0===(n=n||{})?"undefined":o(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:"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)}}]),Embed}()});
/*! flat-embed v1.0.0 | (c) 2019 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("frameborder","0"),e.appendChild(r),r}function s(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 a=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 a;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),s(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),s(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:"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)}}]),Embed}()});
{
"name": "flat-embed",
"version": "0.11.0",
"version": "1.0.0",
"description": "Interact and get events from Flat's Sheet Music Embed",

@@ -34,6 +34,5 @@ "license": "Apache-2.0",

"build": "BABEL_ENV=production node rollup.js",
"build:watch": "npm run build --watch",
"test": "npm run eslint && npm run test:unit && npm run test:karma",
"build:watch": "BUILD_WATCH=true npm run build",
"test": "npm run eslint && npm run test:karma",
"eslint": "./node_modules/.bin/eslint src",
"test:unit": "./node_modules/.bin/mocha --ui exports --reporter spec --slow 150ms --timeout 30000ms test/unit --exit",
"test:karma": "./node_modules/.bin/karma start --single-run",

@@ -43,20 +42,18 @@ "test:karma-watch": "./node_modules/.bin/karma start --single-run=false --auto-watch"

"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.7.0",
"chokidar": "^2.0.4",
"eslint": "^5.7.0",
"jquery": "^3.3.1",
"jsdom": "^11.0.0",
"karma": "^3.1.0",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"chokidar": "^3.0.0",
"eslint": "^5.16.0",
"jquery": "^3.4.1",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"mocha": "^5.2.0",
"rollup": "^0.67.0",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
"uglify-js": "^3.4.9"
"mocha": "^6.1.4",
"rollup": "^1.11.3",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.2.4",
"uglify-js": "^3.5.12"
}
}

@@ -22,6 +22,6 @@ # Flat Sheet Music Embed Client

or use the latest version hosted on jsDelivr:
Or use the latest version hosted on our CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/flat-embed@v0.11.0/dist/embed.min.js"></script>
<script src="https://prod.flat-cdn.com/embed-js/v1.0.0/embed.min.js"></script>
```

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

<div id="embed-container"></div>
<script src="https://cdn.jsdelivr.net/npm/flat-embed@v0.11.0/dist/embed.min.js"></script>
<script src="https://prod.flat-cdn.com/embed-js/v1.0.0/embed.min.js"></script>
<script>

@@ -43,3 +43,3 @@ var container = document.getElementById('embed-container');

appId: '<your-app-id>',
controlsFloating: false
controlsPosition: 'bottom',
}

@@ -109,4 +109,2 @@ });

* [`setCursorPosition`](#setcursorpositionposition-object-promiseobject-error): Set a new position for the cursor
* [Editor Methods](#editor-methods)
* [`setEditorConfig`](#seteditorconfigconfig-object-promiseobject-error): Set the config of the editor
* [Events API](#events-api)

@@ -497,15 +495,2 @@ * [`scoreLoaded`](#event-scoreLoaded): A new score has been loaded

### `setEditorConfig(config: object): Promise<object, Error>`
**NOTE: "Modes" are now deprecated and new options will be available for this method in the upcoming weeks. [Please contact our team](mailto:developers@flat.io) if you are interested in customizing the embed editor.**
Set a new config for the editor (e.g. the different tools available in the embed). This one will be used at the next loading score.
```js
embed.setEditorConfig({}).then(function (config) {
// The config of the embed
console.log(config);
});
```
## Events API

@@ -512,0 +497,0 @@

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