UNPKG

@react-av/editor

Version:

Editor Timeline Components built on React AV.

65 lines 4.99 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useEditorContext = useEditorContext; exports.Editor = Editor; const jsx_runtime_1 = require("react/jsx-runtime"); const Media = __importStar(require("@react-av/core")); const react_1 = __importStar(require("react")); const VideoRatio_1 = require("./VideoRatio"); const EditorContext = react_1.default.createContext(null); function useEditorContext() { const context = react_1.default.useContext(EditorContext); if (!context) { throw new Error('useEditorContext must be used within an Editor component'); } return context; } function Editor(_a) { var { styling, fallbackAspectRatio = 16 / 9, children } = _a, mediaProps = __rest(_a, ["styling", "fallbackAspectRatio", "children"]); const [aspectRatio, setAspectRatio] = (0, react_1.useState)(() => fallbackAspectRatio); return (0, jsx_runtime_1.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 ? (0, jsx_runtime_1.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 }) : (0, jsx_runtime_1.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_1.default.cloneElement(mediaProps.mediaComponent, { style: Object.assign(Object.assign({}, mediaProps.mediaComponent.props.style), { width: 'var(--media-width)', display: 'block' }) }) }), (0, jsx_runtime_1.jsx)(VideoRatio_1.VideoRatio, { fallback: fallbackAspectRatio, onAspectRatio: setAspectRatio }), (0, jsx_runtime_1.jsx)(EditorContext.Provider, { value: { isAudioOnly: !!mediaProps.audioOnly, styling: styling }, children: children })] }); } //# sourceMappingURL=Editor.js.map