programmatic video rendering framework that is actually fast
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Cx from "rescript-classnames/src/Cx.bs.js";
import * as Curry from "rescript/lib/es6/curry.js";
import * as Utils from "./Utils.bs.js";
import * as React from "react";
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
import * as MediaLoader from "./services/mediaLoader.bs.js";
import * as Belt_MapString from "rescript/lib/es6/belt_MapString.js";
import * as Icon from "@openai/apps-sdk-ui/components/Icon";
function MediaList$LoadedMediaIcon(Props) {
var variant = Props.variant;
var name = Props.name;
var media = Props.media;
var containerClassName = Cx.cx([
"flex shrink-0 items-center justify-center overflow-hidden bg-primary-soft-alpha text-secondary",
variant ? "size-10 rounded-lg [&>svg]:size-5" : "aspect-square w-full rounded-xl [&>svg]:size-8"
]);
var tmp;
switch (media.TAG | 0) {
case /* Font */0 :
tmp = React.createElement(Icon.Text, {});
break;
case /* Subtitles */1 :
tmp = React.createElement(Icon.CaptionOn, {});
break;
case /* Lottie */2 :
tmp = React.createElement(Icon.PlayCircle, {});
break;
case /* Image */3 :
tmp = React.cloneElement(React.createElement("img", {
className: "size-full object-cover",
alt: name,
src: media._0.src
}), {
loading: "lazy"
});
break;
case /* Audio */4 :
tmp = React.createElement(Icon.Music, {});
break;
}
return React.createElement("div", {
className: containerClassName
}, tmp);
}
var LoadedMediaIcon = {
make: MediaList$LoadedMediaIcon
};
function stringifyFontWeight(weight) {
if (weight >= 500) {
if (weight < 701) {
if (weight > 699 || weight < 501) {
if (weight >= 700) {
return "Bold";
} else {
return "Medium";
}
} else if (weight !== 600) {
return "Unknown";
} else {
return "Semi Bold";
}
} else if (weight !== 800) {
if (weight !== 900) {
return "Unknown";
} else {
return "Black";
}
} else {
return "Extra bold";
}
} else if (weight >= 201) {
if (weight !== 300) {
if (weight !== 400) {
return "Unknown";
} else {
return "Regular";
}
} else {
return "Light";
}
} else if (weight !== 100) {
if (weight >= 200) {
return "Extra light";
} else {
return "Unknown";
}
} else {
return "Thin";
}
}
function MediaList$LoadedMedia(Props) {
var name = Props.name;
var media = Props.media;
var variant = Props.variant;
var tmp;
switch (media.TAG | 0) {
case /* Font */0 :
var fontInfo = media._0;
tmp = fontInfo.style === "normal" ? fontInfo.name + " (" + stringifyFontWeight(fontInfo.weight) + ", " + fontInfo.unicodeRange + ")" : (
variant ? fontInfo.name + " (" + fontInfo.style + ", " + stringifyFontWeight(fontInfo.weight) + ", " + fontInfo.unicodeRange + ")" : fontInfo.name
);
break;
case /* Subtitles */1 :
tmp = String(media._0) + " phrases";
break;
case /* Lottie */2 :
tmp = "Lottie, " + Utils.Duration.formatSeconds(media._0);
break;
case /* Image */3 :
var match = media._0;
tmp = String(match.width) + "x" + String(match.height);
break;
case /* Audio */4 :
var match$1 = media._0;
tmp = Utils.Duration.formatSeconds(match$1.duration) + ", " + String(match$1.sampleRate) + "hz";
break;
}
return React.createElement("li", {
className: variant ? "flex items-center gap-3 rounded-lg px-2 py-2" : "flex min-w-0 flex-col gap-2",
title: name
}, React.createElement(MediaList$LoadedMediaIcon, {
variant: variant,
name: name,
media: media
}), React.createElement("div", {
className: "flex min-w-0 flex-1 flex-col"
}, React.createElement("p", {
className: "truncate text-sm text-default"
}, name), React.createElement("p", {
className: "truncate text-xs text-secondary"
}, tmp)));
}
var LoadedMedia = {
make: MediaList$LoadedMedia
};
function memo(__x) {
return React.memo(__x, (function (propsB, propsA) {
return propsA.variant === propsB.variant;
}));
}
var make = memo(function (Props) {
var variant = Props.variant;
var mediaState = Curry._1(MediaLoader.MediaLoaderObserver.useObservable, undefined);
return React.createElement("ul", {
"aria-label": "Media",
className: variant ? "flex flex-col px-2" : "grid grid-cols-[repeat(auto-fill,minmax(7rem,1fr))] gap-x-3 gap-y-4 px-4"
}, Belt_Array.map(Belt_MapString.keysToArray(mediaState.mediaList), (function (name) {
var media = Belt_MapString.getExn(mediaState.mediaList, name);
switch (media.TAG | 0) {
case /* Media */1 :
return React.createElement(MediaList$LoadedMedia, {
name: name,
media: media._0,
variant: variant,
key: name
});
case /* Loading */0 :
case /* Error */2 :
return null;
}
})));
});
export {
LoadedMediaIcon ,
stringifyFontWeight ,
LoadedMedia ,
memo ,
make ,
}
/* make Not a pure module */