scale embeddable and fix youtube start bug
This commit is contained in:
parent
23b24ea5c3
commit
e2982a2968
@ -868,6 +868,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.state.activeEmbeddable?.element === el &&
|
this.state.activeEmbeddable?.element === el &&
|
||||||
this.state.activeEmbeddable?.state === "hover";
|
this.state.activeEmbeddable?.state === "hover";
|
||||||
|
|
||||||
|
// Modify the scale based on el.scale property
|
||||||
|
const [xScale, yScale] = el.scale;
|
||||||
|
const scaledTransform = `scale(${scale * xScale}, ${scale * yScale})`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={el.id}
|
key={el.id}
|
||||||
@ -878,7 +882,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
transform: isVisible
|
transform: isVisible
|
||||||
? `translate(${x - this.state.offsetLeft}px, ${
|
? `translate(${x - this.state.offsetLeft}px, ${
|
||||||
y - this.state.offsetTop
|
y - this.state.offsetTop
|
||||||
}px) scale(${scale})`
|
}px) ${scaledTransform}`
|
||||||
: "none",
|
: "none",
|
||||||
display: isVisible ? "block" : "none",
|
display: isVisible ? "block" : "none",
|
||||||
opacity: el.opacity / 100,
|
opacity: el.opacity / 100,
|
||||||
@ -907,8 +911,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}}*/
|
}}*/
|
||||||
className="excalidraw__embeddable-container__inner"
|
className="excalidraw__embeddable-container__inner"
|
||||||
style={{
|
style={{
|
||||||
width: isVisible ? `${el.width}px` : 0,
|
width: isVisible ? `${el.width / xScale}px` : 0,
|
||||||
height: isVisible ? `${el.height}px` : 0,
|
height: isVisible ? `${el.height / yScale}px` : 0,
|
||||||
transform: isVisible ? `rotate(${el.angle}rad)` : "none",
|
transform: isVisible ? `rotate(${el.angle}rad)` : "none",
|
||||||
pointerEvents: isActive
|
pointerEvents: isActive
|
||||||
? POINTER_EVENTS.enabled
|
? POINTER_EVENTS.enabled
|
||||||
|
@ -297,6 +297,7 @@ const restoreElement = (
|
|||||||
case "embeddable":
|
case "embeddable":
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
validated: null,
|
validated: null,
|
||||||
|
scale: [1, 1],
|
||||||
});
|
});
|
||||||
case "frame":
|
case "frame":
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
|
@ -27,7 +27,7 @@ type EmbeddedLink =
|
|||||||
const embeddedLinkCache = new Map<string, EmbeddedLink>();
|
const embeddedLinkCache = new Map<string, EmbeddedLink>();
|
||||||
|
|
||||||
const RE_YOUTUBE =
|
const RE_YOUTUBE =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|.*&t=|\?start=|.*&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
|
||||||
|
|
||||||
const RE_VIMEO =
|
const RE_VIMEO =
|
||||||
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;
|
||||||
|
@ -140,6 +140,7 @@ export const newEmbeddableElement = (
|
|||||||
return {
|
return {
|
||||||
..._newElementBase<ExcalidrawEmbeddableElement>("embeddable", opts),
|
..._newElementBase<ExcalidrawEmbeddableElement>("embeddable", opts),
|
||||||
validated: opts.validated,
|
validated: opts.validated,
|
||||||
|
scale: [1, 1],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
|
isEmbeddableElement,
|
||||||
isFrameElement,
|
isFrameElement,
|
||||||
isFreeDrawElement,
|
isFreeDrawElement,
|
||||||
isImageElement,
|
isImageElement,
|
||||||
@ -586,6 +587,14 @@ export const resizeSingleElement = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ("scale" in element && "scale" in stateAtResizeStart) {
|
if ("scale" in element && "scale" in stateAtResizeStart) {
|
||||||
|
if (isEmbeddableElement(element) && shouldMaintainAspectRatio) {
|
||||||
|
const scale: [number, number] = [
|
||||||
|
eleNewWidth / (stateAtResizeStart.width / stateAtResizeStart.scale[0]),
|
||||||
|
eleNewHeight /
|
||||||
|
(stateAtResizeStart.height / stateAtResizeStart.scale[1]),
|
||||||
|
];
|
||||||
|
mutateElement(element, { scale });
|
||||||
|
} else {
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
scale: [
|
scale: [
|
||||||
// defaulting because scaleX/Y can be 0/-0
|
// defaulting because scaleX/Y can be 0/-0
|
||||||
@ -596,6 +605,7 @@ export const resizeSingleElement = (
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isArrowElement(element) &&
|
isArrowElement(element) &&
|
||||||
|
@ -95,6 +95,7 @@ export type ExcalidrawEmbeddableElement = _ExcalidrawElementBase &
|
|||||||
* may not have access to host-app supplied url validator during restore.
|
* may not have access to host-app supplied url validator during restore.
|
||||||
*/
|
*/
|
||||||
validated: boolean | null;
|
validated: boolean | null;
|
||||||
|
scale: [number, number];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type ExcalidrawImageElement = _ExcalidrawElementBase &
|
export type ExcalidrawImageElement = _ExcalidrawElementBase &
|
||||||
|
1
src/tests/fixtures/elementFixture.ts
vendored
1
src/tests/fixtures/elementFixture.ts
vendored
@ -35,6 +35,7 @@ export const embeddableFixture: ExcalidrawElement = {
|
|||||||
...elementBase,
|
...elementBase,
|
||||||
type: "embeddable",
|
type: "embeddable",
|
||||||
validated: null,
|
validated: null,
|
||||||
|
scale: [1, 1],
|
||||||
};
|
};
|
||||||
export const ellipseFixture: ExcalidrawElement = {
|
export const ellipseFixture: ExcalidrawElement = {
|
||||||
...elementBase,
|
...elementBase,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user