
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
flat-embed
Advanced tools
JavaScript/TypeScript SDK to interact and receive events from our Sheet Music Embed.
If you have any feedback or questions regarding this product, please feel free to contact our developers' support.
You can install our ES/TypeScript Embed Client using npm, pnpm, or yarn:
npm install flat-embed
pnpm add flat-embed
yarn add flat-embed
Or use the latest UMD version hosted on our CDN:
<script src="https://prod.flat-cdn.com/embed-js/v2.5.0/embed.min.js"></script>
The simplest way to get started is to pass a DOM element to our embed that will be used as container. By default, this one will completely fit its container:
<div id="embed-container"></div>
<script src="https://prod.flat-cdn.com/embed-js/v2.5.0/embed.min.js"></script>
<script>
var container = document.getElementById('embed-container');
var embed = new Flat.Embed(container, {
score: '<score-id-you-want-to-load>',
embedParams: {
appId: '<your-app-id>',
controlsPosition: 'bottom',
},
});
</script>
Otherwise, if you are using our embed in an ES6 project:
import Embed from 'flat-embed';
const container = document.getElementById('embed-container');
const embed = new Embed(container, {
score: '<score-id-you-want-to-load>',
embedParams: {
appId: '<your-app-id>',
controlsPosition: 'bottom',
},
});
Some demos of this Embed API are available in a dedicated repository: https://github.com/FlatIO/embed-examples.
Our Embed JS API requires an App ID (appId
) to use it:
localhost
/*.localhost
.By default, analytics and billing of unique users is done using the visitor IPs. To improve accuracy and avoid counting the same user multiple times, you can pass a unique identifier for the user using the embedParams.userId
option.
This identifier must be a unique identifier for the user. For example, you can use the user ID of your application. Please don't use any personal information (e.g. email address).
import Embed from 'flat-embed';
const container = document.getElementById('embed-container');
const embed = new Embed(container, {
score: '<score-id-you-want-to-load>',
embedParams: {
appId: '<your-app-id>',
userId: '<your-end-user-id>',
},
});
When instantiating Flat.Embed
, the first argument will always refer to a DOM element. It can take:
document.getElementById('embed-container')
)."embed-container"
).jsapi=true
.If you instance a different Flat.Embed
for the same element, you will always get the same instance of the object.
When instantiating Flat.Embed
, you can pass options in the second parameter. To use the different methods available and events subscriptions, you will need to pass at least embedParams.appId
.
Option | Description | Values | Default |
---|---|---|---|
score | The score identifier that will load initially | Unique score id | blank |
width | The width of your embed | A width of the embed | 100% |
height | The height of your embed | A height of the embed | 100% |
embedParams | Object containing the loading options for the embed | Any URL parameters | {} |
lazy | Add a loading="lazy" attribute to the iframe | A boolean to enable the lazy-loading | false |
The full JavaScript API documentation is available at https://flat.io/developers/docs/embed/javascript.
// Wait for the embed to be ready
await embed.ready();
// Load a score
await embed.loadFlatScore('SCORE_ID');
// Control playback
await embed.play();
await embed.pause();
await embed.stop();
// Listen to events
embed.on('play', () => {
console.log('Playback started');
});
embed.on('cursorPosition', position => {
console.log('Cursor moved:', position);
});
Our SDK provides 60+ methods to control and interact with embedded scores:
📚 View the complete API documentation →
You can enable the editor mode by setting the mode
to edit
when creating the embed:
var embed = new Flat.Embed(container, {
embedParams: {
appId: '<your-app-id>',
mode: 'edit',
},
});
Learn more about the editor mode →
This SDK includes TypeScript definitions out of the box. All methods and events are fully typed for better development experience.
import Embed from 'flat-embed';
const embed = new Embed(container, {
score: 'SCORE_ID',
embedParams: {
appId: 'YOUR_APP_ID',
mode: 'view', // TypeScript knows valid modes
},
});
// Full type checking and autocompletion
const parts = await embed.getParts();
Apache-2.0 - see LICENSE for details.
FAQs
Interact and get events from Flat's Sheet Music Embed
We found that flat-embed demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.