Web component
@munsonlabs/splice/element is SpliceEditor as a custom element, <ml-splice-editor>, for pages without Vue. It pairs with video-player's <ml-video-player>. Importing it registers the tag and puts the editor's stylesheet on the page; the core and Mediabunny still load only when an editor opens.
<ml-video-player id="interview" src="/video/interview.m3u8" deep-link="interview"></ml-video-player>
<ml-splice-editor for="interview" src="/video/interview.m3u8" caption-position="bottom"></ml-splice-editor>
<script type="module">
import '@munsonlabs/video-player/element'
import '@munsonlabs/splice/element'
import { canSplice } from '@munsonlabs/splice'
const player = document.getElementById('interview')
const editor = document.querySelector('ml-splice-editor')
editor.origin = {
url: location.href,
title: 'The interview',
publisher: 'Example News',
player: 'interview',
}
editor.stamp = { logo: '/logo.svg' }
editor.endCard = {
logo: '/logo.svg',
displayUrl: 'example.com/interview',
}
const check = await canSplice(player.getAttribute('src'), { crop: { aspect: '9:16' } })
if (check.ok) {
player.action = {
icon: '<svg viewBox="0 0 24 24">…</svg>', // your icon, as SVG markup
label: 'Clip this',
onClick: () => editor.show(),
}
}
editor.addEventListener('splice-export', ({ detail }) => {
console.log(detail.link)
})
</script>
Branding and links
The branding and the link back are the same options createSplice takes, set on the element as properties. Set them before the editor opens; each export uses them as they are then.
const editor = document.querySelector('ml-splice-editor')
// Where the clip came from. Its metadata carries the title, the publisher and a #ml-t= link back.
// `player` is the <ml-video-player>'s deep-link id, so the link comes back to that player.
editor.origin = {
url: location.href,
title: 'The interview',
publisher: 'Example News',
player: 'interview',
}
// The logo in a corner of every frame, and a toggle for it in the panel.
editor.stamp = {
logo: '/logo.svg',
position: 'top-right',
}
// The end card after the clip, headed by the logo and pointing at the article.
editor.endCard = {
logo: '/logo.svg',
displayUrl: 'example.com/interview',
cta: 'Watch the full interview at',
}
// A band of text across every frame.
editor.watermark = { text: 'example.com' }
// The panel's words, in your language.
editor.labels = {
title: 'Make a clip',
export: 'Export',
}
editor.endCard = false leaves the end card out, and its toggle with it. Without a stamp there's no logo toggle. Logos on another origin need CORS headers; one that can't be loaded is left out and reported as a non-fatal splice-error. For the link to open at the moment, the player needs deep-link on with the id origin.player names. The options themselves are covered in end card, stamp and watermark and origin and links.
Attributes, properties and events
for names the <ml-video-player> by id; the editor waits for the tag to be defined if it isn't yet. Attributes carry strings and numbers: for, src, open, aspect, caption-position, clip-length, shortest-clip, longest-clip, timeline-span, height and share-caption. Objects are set as properties: origin, endCard, stamp, watermark, captionStyle, aspects, labels, player, source for a File, and shareCaption as a function.
| Event | detail | When |
|---|---|---|
splice-open | - | Opened |
splice-close | - | Closed, from its button, close() or removing open |
splice-export | { blob, start, end, link } | A clip was made |
splice-error | { message, fatal } | fatal when nothing could be made; otherwise something left out |
They bubble. open is reflected as an attribute, and the state (closed, loading, editing, blocked, exporting or done) is on data-state. The element has show(), close(), export(), cancel() and a read-only state.
Unlike the Vue component, the element can't find a player it's nested in without for: Vue's provide/inject doesn't cross from one custom element's app into another's.
To pick your own tag, load the element with ?defer and register it yourself. The flag is read from the file's own URL, so it works when the element is loaded by URL (from a CDN or self-hosted); a bundled import always registers ml-splice-editor.
import { defineSpliceEditor } from 'https://esm.sh/@munsonlabs/splice/element?defer'
defineSpliceEditor('my-clip-editor')
One copy of Vue
The editor reads the player's state reactively, so the editor and <ml-video-player> must share one copy of Vue. Both builds keep Vue (and the editor, the player) as external imports for exactly this. With a bundler, that's automatic.
Without a build step
The core needs nothing. esm.sh rewrites splice's bare mediabunny import to its own URL, so no import map is needed:
<script type="module">
import { createSplice } from 'https://esm.sh/@munsonlabs/splice'
</script>
The element from esm.sh works the same way as video-player's: esm.sh rewrites vue and @munsonlabs/video-player to its own URLs, and with both packages from esm.sh they resolve to the same Vue. Vue's devtools flag has to be set first, in its own non-module script, for the reason video-player's docs give:
<script>
globalThis.__VUE_PROD_DEVTOOLS__ = false
</script>
<script type="module">
import 'https://esm.sh/@munsonlabs/video-player/element'
import 'https://esm.sh/@munsonlabs/splice/element'
</script>
To be sure of one Vue, or to use one already on the page, opt both packages out of esm.sh's rewriting with ?external=vue and map vue yourself:
<script type="importmap">
{
"imports": {
"vue": "https://unpkg.com/vue@3/dist/vue.runtime.esm-browser.prod.js",
"@munsonlabs/video-player": "https://esm.sh/@munsonlabs/video-player?external=vue",
"@munsonlabs/video-player/element": "https://esm.sh/@munsonlabs/video-player/element?external=vue",
"@munsonlabs/splice/element": "https://esm.sh/@munsonlabs/splice/element?external=vue,@munsonlabs/video-player"
}
}
</script>
<script type="module">
import '@munsonlabs/video-player/element'
import '@munsonlabs/splice/element'
</script>
The editor's bundle imports @munsonlabs/video-player for the player's headless controls, which is why it's mapped too. Self-hosting the built files serves them with every bare specifier intact, so vue, @munsonlabs/video-player and mediabunny all need import map entries. The core's chunk is a relative import(), so deploy dist/elements/chunks/ next to the bundle.