@mocanvas/mocanvas · interface
interface EmbedDefinitionOne embeddable service: the exact hosts it is recognised by, and how one of its page urls becomes an embeddable one.
hostnames are matched exactly (case-insensitively, with a leading www.
ignored), never as a suffix — youtube.com.evil.test is a different host and
is not on the list. toEmbedUrl receives the parsed url and returns an
absolute https: url, or null when this particular page of the service is
not embeddable (a channel page rather than a video, say).
Methods · 1
toEmbedUrl(url: URL, settings?: EmbedSettings): string | nullsettings is this service's entry in the editor's EmbedConfig —
an api key, a player flag, a locale. It is passed in rather than read from
the environment on purpose: a definition that reached for process.env
would only work in one bundler, would leak a secret into every client
bundle that imported it, and could not differ between two editors on one
page. It is undefined when the app configured nothing.
Properties · 5
fromEmbedUrl?(url: URL): string | nullThe inverse: given an already-embeddable url, the *page* url a person
would share. Optional — implement it only where the two forms differ
enough that toEmbedUrl cannot simply be handed its own output.
getEmbedInfo uses it as its second pass, so that pasting an embed
url stores the shareable url on the shape rather than the embed one.
Return null when the url is not one of this service's embed urls.
hostnames: readonly string[]sizeToContentAspectRatio?: numberThe width ÷ height this service's content actually is, when it has a fixed
one — 16 / 9 for a video player. Optional, and unset on every built-in:
a service whose pages vary has no such number, and guessing one would
resize somebody's embed for no reason.
Where it is set, EmbedShapeUtil.resolveAspectRatio reports it, a new shape is created at it, and resizing preserves it.
title: stringHuman-readable name, shown on the placeholder card.
type: stringStable id for the service, e.g. "youtube".
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.