UNPKG

@react-av/editor

Version:

Editor Timeline Components built on React AV.

38 lines 3.67 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import * as Media from "@react-av/core"; import React, { useState } from "react"; import { VideoRatio } from "./VideoRatio"; const EditorContext = React.createContext(null); export function useEditorContext() { const context = React.useContext(EditorContext); if (!context) { throw new Error('useEditorContext must be used within an Editor component'); } return context; } export function Editor(_a) { var { styling, fallbackAspectRatio = 16 / 9, children } = _a, mediaProps = __rest(_a, ["styling", "fallbackAspectRatio", "children"]); const [aspectRatio, setAspectRatio] = useState(() => fallbackAspectRatio); return _jsxs("div", { style: Object.assign({ display: 'flex', flexDirection: 'column', maxWidth: '100%', overflow: 'hidden' }, (typeof (styling === null || styling === void 0 ? void 0 : styling.editorContainer) === 'string' ? {} : styling === null || styling === void 0 ? void 0 : styling.editorContainer)), className: typeof (styling === null || styling === void 0 ? void 0 : styling.editorContainer) === 'string' ? styling.editorContainer : undefined, children: [mediaProps.audioOnly ? _jsx("div", { style: Object.assign({ width: '100%', overflow: 'hidden', display: 'flex', justifyContent: 'center', alignItems: 'center', flexShrink: 0, gap: '1rem', background: 'hsl(0, 0%, 88.7%)' }, (typeof (styling === null || styling === void 0 ? void 0 : styling.mediaContainer) === 'string' ? {} : styling === null || styling === void 0 ? void 0 : styling.mediaContainer)), className: typeof (styling === null || styling === void 0 ? void 0 : styling.mediaContainer) === 'string' ? styling.mediaContainer : undefined, children: mediaProps.mediaComponent }) : _jsx(Media.Container, { style: Object.assign({ '--aspect-ratio': aspectRatio, '--media-width': 'min(100%, (100% / var(--container-aspect-ratio)) * var(--aspect-ratio))', '--container-aspect-ratio': 'max(calc(16 / 9), calc(var(--aspect-ratio)))', background: 'hsl(0, 0%, 88.7%)', width: '100%', overflow: 'hidden', display: 'flex', justifyContent: 'center', alignItems: 'center', flexShrink: 0 }, (typeof (styling === null || styling === void 0 ? void 0 : styling.mediaContainer) === 'string' ? {} : styling === null || styling === void 0 ? void 0 : styling.mediaContainer)), className: typeof (styling === null || styling === void 0 ? void 0 : styling.mediaContainer) === 'string' ? styling.mediaContainer : undefined, children: // TODO: this type as unknown stuff is hacky, should find a better way to do this React.cloneElement(mediaProps.mediaComponent, { style: Object.assign(Object.assign({}, mediaProps.mediaComponent.props.style), { width: 'var(--media-width)', display: 'block' }) }) }), _jsx(VideoRatio, { fallback: fallbackAspectRatio, onAspectRatio: setAspectRatio }), _jsx(EditorContext.Provider, { value: { isAudioOnly: !!mediaProps.audioOnly, styling: styling }, children: children })] }); } //# sourceMappingURL=Editor.js.map