@remotion/studio
Version:
APIs for interacting with the Remotion Studio
46 lines (45 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimelineZoomContext = exports.TimelineZoomCtx = exports.TIMELINE_MAX_ZOOM = exports.TIMELINE_MIN_ZOOM = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const imperative_state_1 = require("../components/Timeline/imperative-state");
const timeline_scroll_logic_1 = require("../components/Timeline/timeline-scroll-logic");
const ZoomPersistor_1 = require("../components/ZoomPersistor");
exports.TIMELINE_MIN_ZOOM = 1;
exports.TIMELINE_MAX_ZOOM = 5;
exports.TimelineZoomCtx = (0, react_1.createContext)({
zoom: {},
setZoom: () => {
throw new Error('has no context');
},
});
const TimelineZoomContext = ({ children }) => {
const [zoom, setZoomState] = (0, react_1.useState)(() => (0, ZoomPersistor_1.getZoomFromLocalStorage)());
const setZoom = (0, react_1.useCallback)((compositionId, callback, options) => {
setZoomState((prevZoomMap) => {
var _a, _b, _c, _d;
const newZoomWithFloatingPointErrors = Math.min(exports.TIMELINE_MAX_ZOOM, Math.max(exports.TIMELINE_MIN_ZOOM, callback((_a = prevZoomMap[compositionId]) !== null && _a !== void 0 ? _a : exports.TIMELINE_MIN_ZOOM)));
const newZoom = Math.round(newZoomWithFloatingPointErrors * 10) / 10;
const anchorFrame = (_b = options === null || options === void 0 ? void 0 : options.anchorFrame) !== null && _b !== void 0 ? _b : null;
const anchorContentX = (_c = options === null || options === void 0 ? void 0 : options.anchorContentX) !== null && _c !== void 0 ? _c : null;
(0, timeline_scroll_logic_1.zoomAndPreserveCursor)({
oldZoom: (_d = prevZoomMap[compositionId]) !== null && _d !== void 0 ? _d : exports.TIMELINE_MIN_ZOOM,
newZoom,
currentDurationInFrames: (0, imperative_state_1.getCurrentDuration)(),
currentFrame: (0, imperative_state_1.getCurrentFrame)(),
anchorFrame,
anchorContentX,
});
return { ...prevZoomMap, [compositionId]: newZoom };
});
}, []);
const value = (0, react_1.useMemo)(() => {
return {
zoom,
setZoom,
};
}, [zoom, setZoom]);
return (jsx_runtime_1.jsx(exports.TimelineZoomCtx.Provider, { value: value, children: children }));
};
exports.TimelineZoomContext = TimelineZoomContext;