UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

134 lines 4.39 kB
import { O } from "./o.js"; import { transitions } from "../parts/transitions.js"; import { filters } from "../parts/filters.js"; import { animationPresets, visualAnimations } from "../parts/animations/registry.js"; function createTimeline() { return { format: "timeline", info: "https://omniclip.app/", version: 0, items: [], rootId: 0 }; } export function timeline(root) { const o = new O({ timeline: createTimeline() }); const item = root(o); o.timeline.rootId = item.id; return o.timeline; } export function sequence(...input) { const [first, ...rest] = input; const label = typeof first === "string" ? first : undefined; const items = (label ? rest : input); return o => { const built = items.map(item => item(o)); return label ? o.sequence(label, ...built) : o.sequence(...built); }; } export function stack(...input) { const [first, ...rest] = input; const label = typeof first === "string" ? first : undefined; const items = (label ? rest : input); return o => { const built = items.map(item => item(o)); return label ? o.stack(label, ...built) : o.stack(...built); }; } export function video(media, options) { return o => o.video(media, options); } export function image(media, options) { return o => o.image(media, options); } export function audio(media, options) { return o => o.audio(media, options); } export function text(content, options) { return o => o.text(content, options); } export function captions(item, transcript, options) { return o => o.captions(item(o), transcript, options); } export function gap(duration, options) { return o => o.gap(duration, options); } export function spatial(transform, crop) { return o => o.spatial(transform, crop); } export const anim = { scalar(terp, track) { return { terp, track }; }, vec2(terp, source) { const track = { x: [], y: [] }; for (const [time, [x, y]] of source) { track.x.push([time, x]); track.y.push([time, y]); } return { terp, track }; }, transform: (terp, source) => { const track = { position: { x: [], y: [] }, scale: { x: [], y: [] }, rotation: [], }; for (const [time, [position, scale, rotation]] of source) { track.position.x.push([time, position[0]]); track.position.y.push([time, position[1]]); track.scale.x.push([time, scale[0]]); track.scale.y.push([time, scale[1]]); track.rotation.push([time, rotation]); } return { terp, track }; } }; function makeFilter(get) { const action = ((item, params) => o => get(o)(item(o), params)); action.make = (params) => o => get(o).make(params); return action; } function makeFilters() { const names = Object.keys(filters); const entries = names.map(name => [ name, makeFilter(o => o.filter[name]) ]); return Object.fromEntries(entries); } export const filter = makeFilters(); function makeAnimate(get) { const action = ((item, terp, track) => o => get(o)(item(o), terp, track)); action.make = (terp, track) => o => get(o).make(terp, track); return action; } function makeAnimateActions() { const entries = Object.keys(visualAnimations) .map(key => [key, makeAnimate(o => o.animate[key])]); return Object.fromEntries(entries); } function makePresetAnimate(key) { const action = ((item, options) => o => o.animate.presets[key](item(o), options)); action.make = (options) => o => o.animate.presets[key].make(options); return action; } function makePresetAnimateActions() { const entries = Object.keys(animationPresets) .map(key => [key, makePresetAnimate(key)]); return Object.fromEntries(entries); } export const animate = { ...makeAnimateActions(), presets: makePresetAnimateActions(), }; export function textStyle(style) { return o => o.textStyle(style); } function makeTransitionActions() { const entries = Object.keys(transitions) .map(key => [key, (duration, options) => (o) => o.transition[key](duration, options)]); return Object.fromEntries(entries); } export const transition = makeTransitionActions(); //# sourceMappingURL=helpers.js.map