remotion
Version:
Make videos programmatically
132 lines (131 loc) • 5.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeEffectiveSchemaValuesDotNotation = exports.isKeyframedStatus = exports.getStaticDragOverrideValue = exports.makeKeyframedDragOverride = exports.makeStaticDragOverride = void 0;
const find_props_to_delete_js_1 = require("./find-props-to-delete.js");
const get_effective_visual_mode_value_js_1 = require("./get-effective-visual-mode-value.js");
const interpolate_keyframed_status_js_1 = require("./interpolate-keyframed-status.js");
const makeStaticDragOverride = (value) => {
return { type: 'static', value };
};
exports.makeStaticDragOverride = makeStaticDragOverride;
const makeKeyframedDragOverride = ({ status, frame, value, }) => {
const existingIndex = status.keyframes.findIndex((keyframe) => keyframe.frame === frame);
const keyframes = existingIndex === -1
? [...status.keyframes, { frame, value }].sort((first, second) => first.frame - second.frame)
: status.keyframes.map((keyframe, index) => index === existingIndex ? { frame, value } : keyframe);
const easing = [...status.easing];
while (easing.length < keyframes.length - 1) {
easing.push('linear');
}
if (easing.length > keyframes.length - 1) {
easing.length = keyframes.length - 1;
}
return {
type: 'keyframed',
status: {
...status,
keyframes,
easing,
},
};
};
exports.makeKeyframedDragOverride = makeKeyframedDragOverride;
const getStaticDragOverrideValue = (dragOverrideValue) => {
if ((dragOverrideValue === null || dragOverrideValue === void 0 ? void 0 : dragOverrideValue.type) !== 'static') {
return undefined;
}
return dragOverrideValue.value;
};
exports.getStaticDragOverrideValue = getStaticDragOverrideValue;
const isKeyframedStatus = (status) => {
return status !== null && status.status === 'keyframed';
};
exports.isKeyframedStatus = isKeyframedStatus;
const findFieldInSchema = (schema, key) => {
if (key in schema) {
return schema[key];
}
for (const field of Object.values(schema)) {
if (field.type !== 'enum') {
continue;
}
for (const variant of Object.values(field.variants)) {
const found = findFieldInSchema(variant, key);
if (found) {
return found;
}
}
}
return undefined;
};
const computeEffectiveSchemaValuesDotNotation = ({ schema, currentValue, overrideValues, propStatus, frame, }) => {
var _a;
var _b;
const merged = {};
const propsToDelete = new Set();
for (const key of Object.keys(currentValue)) {
const codeValueStatus = (_b = propStatus === null || propStatus === void 0 ? void 0 : propStatus[key]) !== null && _b !== void 0 ? _b : null;
const field = findFieldInSchema(schema, key);
if ((field === null || field === void 0 ? void 0 : field.type) === 'hidden') {
continue;
}
let value;
if (codeValueStatus === null) {
value = currentValue[key];
}
else if ((0, exports.isKeyframedStatus)(codeValueStatus)) {
if ((field === null || field === void 0 ? void 0 : field.type) === 'array' || (field === null || field === void 0 ? void 0 : field.keyframable) === false) {
value = currentValue[key];
}
else {
const dragOverride = (0, get_effective_visual_mode_value_js_1.resolveDragOverrideValue)({
dragOverrideValue: overrideValues[key],
frame,
});
if (dragOverride.type === 'resolved') {
value = dragOverride.value;
}
else if (frame !== null) {
const interpolated = (0, interpolate_keyframed_status_js_1.interpolateKeyframedStatus)({
frame,
status: codeValueStatus,
});
value = interpolated !== null && interpolated !== void 0 ? interpolated : currentValue[key];
}
else {
value = currentValue[key];
}
}
}
else if (codeValueStatus.status === 'computed') {
value = currentValue[key];
}
else {
value = (0, get_effective_visual_mode_value_js_1.getEffectiveVisualModeValue)({
codeValue: codeValueStatus,
dragOverrideValue: overrideValues[key],
defaultValue: field === null || field === void 0 ? void 0 : field.default,
frame,
shouldResortToDefaultValueIfUndefined: false,
});
}
if (value === undefined) {
propsToDelete.add(key);
}
merged[key] = value;
}
for (const key of Object.keys(overrideValues)) {
if (((_a = schema[key]) === null || _a === void 0 ? void 0 : _a.type) === 'enum') {
const propsToDeleteForKey = (0, find_props_to_delete_js_1.findPropsToDelete)({
schema,
key,
value: merged[key],
});
for (const propToDelete of propsToDeleteForKey) {
propsToDelete.add(propToDelete);
}
}
}
return { merged, propsToDelete };
};
exports.computeEffectiveSchemaValuesDotNotation = computeEffectiveSchemaValuesDotNotation;