programmatic video rendering framework that is actually fast
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Curry from "rescript/lib/es6/curry.js";
import * as Theme from "../Theme.bs.js";
import * as React from "react";
import * as CanvasSize from "./canvasSize.bs.js";
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as EditorContext from "../../EditorContext.bs.js";
import * as Webapi__Canvas__Canvas2d from "bs-webapi/src/Webapi/Canvas/Webapi__Canvas__Canvas2d.bs.js";
var pinPath = "M12.8636 3.26026C13.9444 1.74705 16.1254 1.56655 17.4403 2.88148L21.1185 6.55971C22.4335 7.87464 22.2529 10.0556 20.7397 11.1364L16.4786 14.1801C16.1638 14.405 16 14.7305 16 15V17.5C16 18.9069 15.0409 19.9513 13.976 20.4104C12.9046 20.8724 11.4792 20.8468 10.4568 19.8243L8.02332 17.3909L3.70711 21.7071C3.31658 22.0976 2.68342 22.0976 2.29289 21.7071C1.90237 21.3166 1.90237 20.6834 2.29289 20.2929L6.60911 15.9767L4.17567 13.5432C3.1532 12.5208 3.12762 11.0954 3.58957 10.024C4.04871 8.95908 5.09306 8 6.5 8H9C9.26948 8 9.59505 7.8362 9.81994 7.52136L12.8636 3.26026ZM8.73001 15.2692L11.871 18.4101C12.1769 18.716 12.6696 18.7957 13.1842 18.5739C13.7052 18.3492 14 17.9208 14 17.5V15C14 13.9717 14.5749 13.0821 15.3162 12.5526L19.5773 9.50895C20.0848 9.14643 20.1453 8.41495 19.7043 7.97392L16.0261 4.29569C15.5851 3.85467 14.8536 3.9152 14.491 4.42273L11.4474 8.68383C10.9179 9.42507 10.0283 10 9 10H6.5C6.07925 10 5.65079 10.2948 5.42615 10.8158C5.20431 11.3304 5.28397 11.8231 5.58988 12.129L8.73001 15.2692Z";
function makePinImage(color) {
var image = new Image(18, 18);
var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"" + color + "\" d=\"" + pinPath + "\"/></svg>";
image.src = "data:image/svg+xml;base64,".concat(window.btoa(svg));
return image;
}
var darkPin = makePinImage(Theme.dark.text);
var lightPin = makePinImage(Theme.light.text);
function pinImage(theme) {
if (theme) {
return darkPin;
} else {
return lightPin;
}
}
function rendermagnet(ctx, size, frame, theme) {
var palette = Theme.palette(theme);
var imageData = theme ? darkPin : lightPin;
var magnetX = CanvasSize.frameToX(frame, size);
var timelineStart = size.timelineMarginLeft;
var timelineEnd = timelineStart + size.maxSceneWidth;
var isMagnetVisible = magnetX >= timelineStart && magnetX <= timelineEnd;
if (isMagnetVisible) {
ctx.beginPath();
ctx.moveTo(magnetX, 0);
ctx.lineTo(magnetX, size.height);
Webapi__Canvas__Canvas2d.setStrokeStyle(ctx, /* String */0, palette.textSecondary);
ctx.lineWidth = 1;
ctx.stroke();
ctx.drawImage(imageData, ((magnetX | 0) - 18 | 0) - 5 | 0, 2, 18, 18);
return ;
}
var cornerX = magnetX < timelineStart ? timelineStart + 10.0 : timelineEnd - 30.0;
ctx.save();
ctx.globalAlpha = 0.7;
ctx.drawImage(imageData, cornerX | 0, 2, 18, 18);
ctx.restore();
}
function ControlsCanvas(Props) {
var size = Props.size;
var controlsCanvasRef = React.useRef(null);
var editorContext = EditorContext.useEditorContext(undefined);
var match = Curry._1(editorContext.usePlayer, undefined);
var player = match[0];
var theme = Theme.use(undefined);
CanvasSize.useCanvasScale(controlsCanvasRef, size);
React.useEffect((function () {
Belt_Option.map(Caml_option.nullable_to_opt(controlsCanvasRef.current), (function (canvasElement) {
var ctx = canvasElement.getContext("2d");
ctx.clearRect(0, 0, size.scaledWidth, size.scaledHeight);
return Belt_Option.map(player.magnet, (function (frame) {
return rendermagnet(ctx, size, frame, theme);
}));
}));
}), [
player.magnet,
player.viewportOffset,
theme
]);
return React.createElement("canvas", {
ref: controlsCanvasRef,
className: "absolute inset-0",
style: {
height: String(size.height) + "px",
width: String(size.width) + "px"
},
height: String(Math.floor(size.height)) + "px",
width: String(Math.floor(size.width)) + "px"
});
}
var imageSize = 18;
var make = ControlsCanvas;
export {
imageSize ,
pinPath ,
makePinImage ,
darkPin ,
lightPin ,
pinImage ,
rendermagnet ,
make ,
}
/* darkPin Not a pure module */