mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-05-17 13:40:38 +00:00
feat(editor): scale video embeddables based on zoom (#11251)
This commit is contained in:
@@ -603,6 +603,8 @@ const YOUTUBE_VIDEO_STATES = new Map<
|
||||
ValueOf<typeof YOUTUBE_STATES>
|
||||
>();
|
||||
|
||||
const MAX_EMBEDDABLE_VIEWPORT_SCALE = 4;
|
||||
|
||||
let IS_PLAIN_PASTE = false;
|
||||
let IS_PLAIN_PASTE_TIMER = 0;
|
||||
let PLAIN_PASTE_TOAST_SHOWN = false;
|
||||
@@ -1735,6 +1737,18 @@ class App extends React.Component<AppProps, AppState> {
|
||||
this.state.activeEmbeddable?.element === el &&
|
||||
this.state.activeEmbeddable?.state === "hover";
|
||||
|
||||
// scale video embeds based on zoom (capped) so that smaller embeds
|
||||
// on canvas when zoomed are still of legible quality
|
||||
// (note: for some embed types like gdrive, the quality is poor when
|
||||
// scaling mid playback and works only when you initially start the
|
||||
// playback at the higher zoom level)
|
||||
const shouldScaleEmbeddableViewport = src?.type === "video";
|
||||
const embeddableViewportScale = clamp(
|
||||
shouldScaleEmbeddableViewport ? scale : 1,
|
||||
0.75,
|
||||
MAX_EMBEDDABLE_VIEWPORT_SCALE,
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={el.id}
|
||||
@@ -1801,31 +1815,42 @@ class App extends React.Component<AppProps, AppState> {
|
||||
padding: `${el.strokeWidth}px`,
|
||||
}}
|
||||
>
|
||||
{(isEmbeddableElement(el)
|
||||
? this.props.renderEmbeddable?.(el, this.state)
|
||||
: null) ?? (
|
||||
<iframe
|
||||
ref={(ref) => this.cacheEmbeddableRef(el, ref)}
|
||||
className="excalidraw__embeddable"
|
||||
srcDoc={
|
||||
src?.type === "document"
|
||||
? src.srcdoc(this.state.theme)
|
||||
: undefined
|
||||
}
|
||||
src={
|
||||
src?.type !== "document" ? src?.link ?? "" : undefined
|
||||
}
|
||||
// https://stackoverflow.com/q/18470015
|
||||
scrolling="no"
|
||||
referrerPolicy="no-referrer-when-downgrade"
|
||||
title="Excalidraw Embedded Content"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowFullScreen={true}
|
||||
sandbox={`${
|
||||
src?.sandbox?.allowSameOrigin ? "allow-same-origin" : ""
|
||||
} allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-downloads`}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
className="excalidraw__embeddable__content"
|
||||
style={{
|
||||
width: `${embeddableViewportScale * 100}%`,
|
||||
height: `${embeddableViewportScale * 100}%`,
|
||||
transform: `scale(${1 / embeddableViewportScale})`,
|
||||
}}
|
||||
>
|
||||
{(isEmbeddableElement(el)
|
||||
? this.props.renderEmbeddable?.(el, this.state)
|
||||
: null) ?? (
|
||||
<iframe
|
||||
ref={(ref) => this.cacheEmbeddableRef(el, ref)}
|
||||
className="excalidraw__embeddable"
|
||||
srcDoc={
|
||||
src?.type === "document"
|
||||
? src.srcdoc(this.state.theme)
|
||||
: undefined
|
||||
}
|
||||
src={
|
||||
src?.type !== "document" ? src?.link ?? "" : undefined
|
||||
}
|
||||
// https://stackoverflow.com/q/18470015
|
||||
scrolling="no"
|
||||
referrerPolicy="no-referrer-when-downgrade"
|
||||
title="Excalidraw Embedded Content"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowFullScreen={true}
|
||||
sandbox={`${
|
||||
src?.sandbox?.allowSameOrigin
|
||||
? "allow-same-origin"
|
||||
: ""
|
||||
} allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-downloads`}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -814,6 +814,14 @@ body.excalidraw-cursor-resize * {
|
||||
.excalidraw__embeddable__outer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.excalidraw__embeddable__content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transform-origin: top left;
|
||||
|
||||
&,
|
||||
& > * {
|
||||
border-radius: var(--embeddable-radius);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user