flat-embed
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -1,2 +0,2 @@ | ||
(function(n,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(n=typeof globalThis!="undefined"?globalThis:n||self,n.Flat=n.Flat||{},n.Flat.Embed=o())})(this,function(){"use strict";var M=Object.defineProperty;var P=(n,o,l)=>o in n?M(n,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):n[o]=l;var a=(n,o,l)=>(P(n,typeof o!="symbol"?o+"":o,l),l);if(typeof window.postMessage=="undefined")throw new Error("The Flat Embed JS API is not supported in this browser");function n(r){if(typeof r=="string"){const e=document.getElementById(r);if(!e)throw new TypeError(`The DOM element with the identifier "${r}" was not found.`);r=e}if(!(r instanceof window.HTMLElement))throw new TypeError("The first parameter must be an existing DOM element or an identifier.");if(r.nodeName!=="IFRAME"){const e=r.querySelector("iframe");e&&(r=e)}return r}function o(r){let e=r.baseUrl||"https://flat-embed.com";e+="/"+(r.score||"blank");const t=Object.assign({jsapi:!0},r.embedParams),s=Object.keys(t).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(t[i])}`).join("&");return e+"?"+s}function l(r,e){const t=o(e),s=document.createElement("iframe");return s.setAttribute("src",t),s.setAttribute("width",e.width||"100%"),s.setAttribute("height",e.height||"100%"),s.setAttribute("allowfullscreen","true"),s.setAttribute("allow","autoplay; midi"),s.setAttribute("frameborder","0"),r.appendChild(s),s}function d(r,e,t){if(!r.element.contentWindow||!r.element.contentWindow.postMessage)throw new Error("No `contentWindow` or `contentWindow.postMessage` available on the element");const s={method:e,parameters:t};r.element.contentWindow.postMessage(s,r.origin)}function g(r){return typeof r=="string"&&(r=JSON.parse(r)),r}class m{constructor(e){a(this,"embed");a(this,"promises");a(this,"eventCallbacks");return this.embed=e,this.promises={},this.eventCallbacks={},this}pushCall(e,t,s){this.promises[e]=this.promises[e]||[],this.promises[e].push({resolve:t,reject:s})}subscribeEvent(e,t){return this.eventCallbacks[e]=this.eventCallbacks[e]||[],this.eventCallbacks[e].push(t),this.eventCallbacks[e].length===1}unsubscribeEvent(e,t){if(!this.eventCallbacks[e])return!1;if(t){const s=this.eventCallbacks[e].indexOf(t);s>=0&&this.eventCallbacks[e].splice(s,1)}else this.eventCallbacks[e]=[];return!t||this.eventCallbacks[e].length===0}process(e){"method"in e&&e.method?this.processMethodResponse(e):"event"in e&&e.event&&this.processEvent(e)}processMethodResponse(e){if(!this.promises[e.method])return;const t=this.promises[e.method].shift();t&&(e.error?t.reject(e.error):t.resolve(e.response))}processEvent(e){!this.eventCallbacks[e.event]||this.eventCallbacks[e.event].length===0||this.eventCallbacks[e.event].forEach(t=>{t.call(this.embed,e.parameters)})}}const u=new WeakMap,f=new WeakMap;class b{constructor(e,t={}){a(this,"origin","*");a(this,"element");a(this,"embedCallback");if(e=n(e),u.has(e))return u.get(e);e.nodeName!=="IFRAME"&&(e=l(e,t)),this.element=e,this.embedCallback=new m(this);const s=new Promise(i=>{const p=c=>{if(this.element.contentWindow!==c.source)return;this.origin==="*"&&(this.origin=c.origin);const h=g(c.data);if(h.event==="ready"||h.method==="ping"){i();return}this.embedCallback.process(h)};window.addEventListener("message",p,!1),d(this,"ping")});return u.set(this.element,this),f.set(this.element,s),this}ready(){return f.get(this.element)}call(e,t={}){return new Promise((s,i)=>this.ready().then(()=>{this.embedCallback.pushCall(e,s,i),d(this,e,t)}))}on(e,t){if(typeof e!="string")throw new TypeError("An event name (string) is required");if(typeof t!="function")throw new TypeError("An callback (function) is required");this.embedCallback.subscribeEvent(e,t)&&this.call("addEventListener",e).catch(()=>{})}off(e,t){if(typeof e!="string")throw new TypeError("An event name (string) is required");this.embedCallback.unsubscribeEvent(e,t)&&this.call("removeEventListener",e).catch(()=>{})}loadFlatScore(e){return typeof e=="string"&&(e={score:e}),this.call("loadFlatScore",e)}loadMusicXML(e){return this.call("loadMusicXML",e)}loadJSON(e){return this.call("loadJSON",e)}getJSON(){return this.call("getJSON")}getMusicXML(e){return new Promise((t,s)=>{if(e=e||{},typeof e!="object")return s(new TypeError("Options must be an object"));this.call("getMusicXML",e).then(i=>t(typeof i=="string"?i:new Uint8Array(i))).catch(s)})}getPNG(e){return new Promise((t,s)=>{if(e=e||{},typeof e!="object")return s(new TypeError("Options must be an object"));this.call("getPNG",e).then(i=>{if(typeof i=="string")return t(i);t(new Uint8Array(i))}).catch(s)})}getMIDI(){return this.call("getMIDI").then(e=>new Uint8Array(e))}getFlatScoreMetadata(){return this.call("getFlatScoreMetadata")}getEmbedConfig(){return this.call("getEmbedConfig")}setEditorConfig(e){return this.call("setEditorConfig",e)}fullscreen(e){return this.call("fullscreen",e)}play(){return this.call("play")}pause(){return this.call("pause")}stop(){return this.call("stop")}mute(){return this.call("mute")}getMasterVolume(){return this.call("getMasterVolume")}setMasterVolume(e){return this.call("setMasterVolume",e)}getPartVolume(e){return this.call("getPartVolume",e)}setPartVolume(e){return this.call("setPartVolume",e)}mutePart(e){return this.call("mutePart",e)}unmutePart(e){return this.call("unmutePart",e)}setPartSoloMode(e){return this.call("setPartSoloMode",e)}unsetPartSoloMode(e){return this.call("unsetPartSoloMode",e)}getPartSoloMode(e){return this.call("getPartSoloMode",e)}getPartReverb(e){return this.call("getPartReverb",e)}setPartReverb(e){return this.call("setPartReverb",e)}setTrack(e){return this.call("setTrack",e)}useTrack(e){return this.call("useTrack",e)}seekTrackTo(e){return this.call("seekTrackTo",e)}print(){return this.call("print")}getZoom(){return this.call("getZoom")}setZoom(e){return this.call("setZoom",e)}getAutoZoom(){return this.call("getAutoZoom")}setAutoZoom(e){return this.call("setAutoZoom",e)}focusScore(){return this.call("focusScore")}getCursorPosition(){return this.call("getCursorPosition")}setCursorPosition(e){return this.call("setCursorPosition",e)}getParts(){return this.call("getParts")}getDisplayedParts(){return this.call("getDisplayedParts")}setDisplayedParts(e){return this.call("setDisplayedParts",e)}getNbMeasures(){return this.call("getNbMeasures")}getMeasuresUuids(){return this.call("getMeasuresUuids")}getMeasureDetails(){return this.call("getMeasureDetails")}getNbParts(){return this.call("getNbParts")}getPartsUuids(){return this.call("getPartsUuids")}getMeasureVoicesUuids(e){return this.call("getMeasureVoicesUuids",e)}getMeasureNbNotes(e){return this.call("getMeasureNbNotes",e)}getNoteData(e){return this.call("getNoteData",e)}playbackPositionToNoteIdx(e){return this.call("playbackPositionToNoteIdx",e)}getNoteDetails(){return this.call("getNoteDetails")}goLeft(e=!1){return this.call("goLeft",{mute:e})}goRight(e=!1){return this.call("goRight",{mute:e})}getMetronomeMode(){return this.call("getMetronomeMode")}setMetronomeMode(e){return this.call("setMetronomeMode",{mode:e})}getPlaybackSpeed(){return this.call("getPlaybackSpeed")}setPlaybackSpeed(e){return this.call("setPlaybackSpeed",{speed:e})}scrollToCursor(){return this.call("scrollToCursor")}}return b}); | ||
(function(n,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(n=typeof globalThis!="undefined"?globalThis:n||self,n.Flat=n.Flat||{},n.Flat.Embed=o())})(this,function(){"use strict";var M=Object.defineProperty;var P=(n,o,l)=>o in n?M(n,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):n[o]=l;var a=(n,o,l)=>(P(n,typeof o!="symbol"?o+"":o,l),l);if(typeof window.postMessage=="undefined")throw new Error("The Flat Embed JS API is not supported in this browser");function n(s){if(typeof s=="string"){const e=document.getElementById(s);if(!e)throw new TypeError(`The DOM element with the identifier "${s}" was not found.`);s=e}if(!(s instanceof window.HTMLElement))throw new TypeError("The first parameter must be an existing DOM element or an identifier.");if(s.nodeName!=="IFRAME"){const e=s.querySelector("iframe");e&&(s=e)}return s}function o(s){let e=s.baseUrl||"https://flat-embed.com";e+="/"+(s.score||"blank");const t=Object.assign({jsapi:!0},s.embedParams),r=Object.keys(t).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(t[i])}`).join("&");return e+"?"+r}function l(s,e){const t=o(e),r=document.createElement("iframe");return r.setAttribute("src",t),r.setAttribute("width",e.width||"100%"),r.setAttribute("height",e.height||"100%"),r.setAttribute("allowfullscreen","true"),r.setAttribute("allow","autoplay; midi"),r.setAttribute("frameborder","0"),e.lazy&&r.setAttribute("loading","lazy"),s.appendChild(r),r}function d(s,e,t){if(!s.element.contentWindow||!s.element.contentWindow.postMessage)throw new Error("No `contentWindow` or `contentWindow.postMessage` available on the element");const r={method:e,parameters:t};s.element.contentWindow.postMessage(r,s.origin)}function g(s){return typeof s=="string"&&(s=JSON.parse(s)),s}class m{constructor(e){a(this,"embed");a(this,"promises");a(this,"eventCallbacks");return this.embed=e,this.promises={},this.eventCallbacks={},this}pushCall(e,t,r){this.promises[e]=this.promises[e]||[],this.promises[e].push({resolve:t,reject:r})}subscribeEvent(e,t){return this.eventCallbacks[e]=this.eventCallbacks[e]||[],this.eventCallbacks[e].push(t),this.eventCallbacks[e].length===1}unsubscribeEvent(e,t){if(!this.eventCallbacks[e])return!1;if(t){const r=this.eventCallbacks[e].indexOf(t);r>=0&&this.eventCallbacks[e].splice(r,1)}else this.eventCallbacks[e]=[];return!t||this.eventCallbacks[e].length===0}process(e){"method"in e&&e.method?this.processMethodResponse(e):"event"in e&&e.event&&this.processEvent(e)}processMethodResponse(e){if(!this.promises[e.method])return;const t=this.promises[e.method].shift();t&&(e.error?t.reject(e.error):t.resolve(e.response))}processEvent(e){!this.eventCallbacks[e.event]||this.eventCallbacks[e.event].length===0||this.eventCallbacks[e.event].forEach(t=>{t.call(this.embed,e.parameters)})}}const u=new WeakMap,f=new WeakMap;class b{constructor(e,t={}){a(this,"origin","*");a(this,"element");a(this,"embedCallback");if(e=n(e),u.has(e))return u.get(e);e.nodeName!=="IFRAME"&&(e=l(e,t)),this.element=e,this.embedCallback=new m(this);const r=new Promise(i=>{const p=c=>{if(this.element.contentWindow!==c.source)return;this.origin==="*"&&(this.origin=c.origin);const h=g(c.data);if(h.event==="ready"||h.method==="ping"){i();return}this.embedCallback.process(h)};window.addEventListener("message",p,!1),d(this,"ping")});return u.set(this.element,this),f.set(this.element,r),this}ready(){return f.get(this.element)}call(e,t={}){return new Promise((r,i)=>this.ready().then(()=>{this.embedCallback.pushCall(e,r,i),d(this,e,t)}))}on(e,t){if(typeof e!="string")throw new TypeError("An event name (string) is required");if(typeof t!="function")throw new TypeError("An callback (function) is required");this.embedCallback.subscribeEvent(e,t)&&this.call("addEventListener",e).catch(()=>{})}off(e,t){if(typeof e!="string")throw new TypeError("An event name (string) is required");this.embedCallback.unsubscribeEvent(e,t)&&this.call("removeEventListener",e).catch(()=>{})}loadFlatScore(e){return typeof e=="string"&&(e={score:e}),this.call("loadFlatScore",e)}loadMusicXML(e){return this.call("loadMusicXML",e)}loadJSON(e){return this.call("loadJSON",e)}getJSON(){return this.call("getJSON")}getMusicXML(e){return new Promise((t,r)=>{if(e=e||{},typeof e!="object")return r(new TypeError("Options must be an object"));this.call("getMusicXML",e).then(i=>t(typeof i=="string"?i:new Uint8Array(i))).catch(r)})}getPNG(e){return new Promise((t,r)=>{if(e=e||{},typeof e!="object")return r(new TypeError("Options must be an object"));this.call("getPNG",e).then(i=>{if(typeof i=="string")return t(i);t(new Uint8Array(i))}).catch(r)})}getMIDI(){return this.call("getMIDI").then(e=>new Uint8Array(e))}getFlatScoreMetadata(){return this.call("getFlatScoreMetadata")}getEmbedConfig(){return this.call("getEmbedConfig")}setEditorConfig(e){return this.call("setEditorConfig",e)}fullscreen(e){return this.call("fullscreen",e)}play(){return this.call("play")}pause(){return this.call("pause")}stop(){return this.call("stop")}mute(){return this.call("mute")}getMasterVolume(){return this.call("getMasterVolume")}setMasterVolume(e){return this.call("setMasterVolume",e)}getPartVolume(e){return this.call("getPartVolume",e)}setPartVolume(e){return this.call("setPartVolume",e)}mutePart(e){return this.call("mutePart",e)}unmutePart(e){return this.call("unmutePart",e)}setPartSoloMode(e){return this.call("setPartSoloMode",e)}unsetPartSoloMode(e){return this.call("unsetPartSoloMode",e)}getPartSoloMode(e){return this.call("getPartSoloMode",e)}getPartReverb(e){return this.call("getPartReverb",e)}setPartReverb(e){return this.call("setPartReverb",e)}setTrack(e){return this.call("setTrack",e)}useTrack(e){return this.call("useTrack",e)}seekTrackTo(e){return this.call("seekTrackTo",e)}print(){return this.call("print")}getZoom(){return this.call("getZoom")}setZoom(e){return this.call("setZoom",e)}getAutoZoom(){return this.call("getAutoZoom")}setAutoZoom(e){return this.call("setAutoZoom",e)}focusScore(){return this.call("focusScore")}getCursorPosition(){return this.call("getCursorPosition")}setCursorPosition(e){return this.call("setCursorPosition",e)}getParts(){return this.call("getParts")}getDisplayedParts(){return this.call("getDisplayedParts")}setDisplayedParts(e){return this.call("setDisplayedParts",e)}getNbMeasures(){return this.call("getNbMeasures")}getMeasuresUuids(){return this.call("getMeasuresUuids")}getMeasureDetails(){return this.call("getMeasureDetails")}getNbParts(){return this.call("getNbParts")}getPartsUuids(){return this.call("getPartsUuids")}getMeasureVoicesUuids(e){return this.call("getMeasureVoicesUuids",e)}getMeasureNbNotes(e){return this.call("getMeasureNbNotes",e)}getNoteData(e){return this.call("getNoteData",e)}playbackPositionToNoteIdx(e){return this.call("playbackPositionToNoteIdx",e)}getNoteDetails(){return this.call("getNoteDetails")}goLeft(e=!1){return this.call("goLeft",{mute:e})}goRight(e=!1){return this.call("goRight",{mute:e})}getMetronomeMode(){return this.call("getMetronomeMode")}setMetronomeMode(e){return this.call("setMetronomeMode",{mode:e})}getPlaybackSpeed(){return this.call("getPlaybackSpeed")}setPlaybackSpeed(e){return this.call("setPlaybackSpeed",{speed:e})}scrollToCursor(){return this.call("scrollToCursor")}}return b}); | ||
//# sourceMappingURL=flat-embed.umd.js.map |
@@ -15,15 +15,2 @@ export interface NoteCursorPosition { | ||
} | ||
export interface NoteCursorPositionOptional { | ||
partIdx?: number; | ||
partUuid?: string; | ||
staffIdx?: number; | ||
staffUuid?: string; | ||
voiceIdxInStaff?: number; | ||
voiceUuid?: string; | ||
measureIdx?: number; | ||
measureUuid?: string; | ||
noteIdx?: number; | ||
line?: number; | ||
dpq?: number; | ||
timePos?: number; | ||
} | ||
export type NoteCursorPositionOptional = Partial<NoteCursorPosition>; |
@@ -134,2 +134,4 @@ /** Display locale for the Embed */ | ||
baseUrl?: string; | ||
/** Lazy loading of the iframe */ | ||
lazy?: boolean; | ||
/** | ||
@@ -136,0 +138,0 @@ * Optional configuration and customization options |
{ | ||
"name": "flat-embed", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Interact and get events from Flat's Sheet Music Embed", | ||
@@ -36,2 +36,12 @@ "license": "Apache-2.0", | ||
], | ||
"scripts": { | ||
"clean": "rm build/*", | ||
"build": "tsc && vite build", | ||
"test": "tsc && pnpm run prettier:check && npm run eslint && npm run test:karma", | ||
"eslint": "eslint src --max-warnings=0", | ||
"prettier:check": "prettier --check .", | ||
"test:karma": "karma start --single-run", | ||
"test:karma-watch": "karma start --single-run=false --auto-watch", | ||
"prepare": "husky install" | ||
}, | ||
"lint-staged": { | ||
@@ -57,12 +67,3 @@ "**/*": "prettier --write --ignore-unknown", | ||
"vite-plugin-dts": "^3.6.3" | ||
}, | ||
"scripts": { | ||
"clean": "rm build/*", | ||
"build": "tsc && vite build", | ||
"test": "tsc && pnpm run prettier:check && npm run eslint && npm run test:karma", | ||
"eslint": "eslint src --max-warnings=0", | ||
"prettier:check": "prettier --check .", | ||
"test:karma": "karma start --single-run", | ||
"test:karma-watch": "karma start --single-run=false --auto-watch" | ||
} | ||
} | ||
} |
@@ -25,3 +25,3 @@ # Flat Sheet Music Embed Client | ||
```html | ||
<script src="https://prod.flat-cdn.com/embed-js/v2.2.0/embed.min.js"></script> | ||
<script src="https://prod.flat-cdn.com/embed-js/v2.3.0/embed.min.js"></script> | ||
``` | ||
@@ -35,3 +35,3 @@ | ||
<div id="embed-container"></div> | ||
<script src="https://prod.flat-cdn.com/embed-js/v2.2.0/embed.min.js"></script> | ||
<script src="https://prod.flat-cdn.com/embed-js/v2.3.0/embed.min.js"></script> | ||
<script> | ||
@@ -118,2 +118,3 @@ var container = document.getElementById('embed-container'); | ||
| `embedParams` | Object containing the loading options for the embed | [Any URL parameters](https://flat.io/developers/docs/embed/url-parameters.html) | `{}` | | ||
| `lazy` | Add a `loading="lazy"` attribute to the iframe | A boolean to enable the lazy-loading | `false` | | ||
@@ -120,0 +121,0 @@ ## JavaScript API |
Sorry, the diff of this file is not supported yet
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
1404
179286
24
1541