"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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.applyVisualControl = void 0; const studio_shared_1 = require("@remotion/studio-shared"); const recast = __importStar(require("recast")); const parse_ast_1 = require("./parse-ast"); const expectString = (node) => { if (node.type === 'StringLiteral') { return node.value; } if (node.type === 'TemplateLiteral') { if (node.expressions.length > 0) { throw new Error('applyVisualControl() must use a static identifier, the string may not be dynamic.'); } return node.quasis[0].value.raw; } throw new Error('Expected a string literal'); }; const applyVisualControl = ({ file, transformation, changesMade, }) => { recast.types.visit(file.program, { visitCallExpression(path) { const { node } = path; if (node.type !== 'CallExpression') { throw new Error('Expected a call expression'); } if (node.callee.type !== 'Identifier') { return this.traverse(path); } if (node.callee.name !== 'visualControl') { return this.traverse(path); } const firstArgument = node.arguments[0]; const str = expectString(firstArgument); for (const change of transformation.changes) { if (change.id !== str) { continue; } const parsed = (0, parse_ast_1.parseAst)(`a = ${(0, studio_shared_1.stringifyDefaultProps)({ props: JSON.parse(change.newValueSerialized), enumPaths: change.enumPaths })}`).program.body[0].expression.right; node.arguments[1] = parsed; changesMade.push({ description: `Applied visual control ${change.id}`, }); } return this.traverse(path); }, }); return { newAst: file, changesMade }; }; exports.applyVisualControl = applyVisualControl;