import {z} from 'zod' export type OverlayAnimationCurve = 'linear' | 'smooth' | 'natural' | 'slow_down' | 'accelerate' | 'elastic' | 'bounce' | 'overshoot' | 'impulse' | 'swing' | 'custom' | 'spring'; export type OverlayAnimationSpring = {damping: number, mass: number, stiffness: number}; export type OverlayAnimationEasingInput = {bezier?: (Array) | undefined, curve: OverlayAnimationCurve, intensity?: number | undefined, spring?: OverlayAnimationSpring | undefined}; export type OverlayAnimationPreset = 'fade' | 'slide_up' | 'slide_down' | 'slide_left' | 'slide_right' | 'mask_up' | 'mask_down' | 'grow' | 'shrink' | 'blur' | 'blur_slide_up'; export type OverlayAnimationTextInput = {delayMs?: number | undefined, order?: ('forward' | 'backward' | 'center' | 'edges' | 'random') | undefined, smoothing?: ('linear' | 'smooth' | 'natural' | 'slow_down' | 'accelerate' | 'elastic' | 'overshoot' | 'impulse' | 'swing') | undefined, unit: 'letters' | 'words' | 'lines'}; export type OverlayAnimationSideInput = {blur?: number | undefined, clip?: boolean | undefined, durationMs?: number | undefined, easing?: OverlayAnimationEasingInput | undefined, moveX?: number | undefined, moveY?: number | undefined, opacity?: number | undefined, preset?: OverlayAnimationPreset | undefined, rotate?: number | undefined, scale?: number | undefined, text?: OverlayAnimationTextInput | undefined}; export type OverlayAnimationInput = {intro?: (OverlayAnimationSideInput | null) | undefined, motionBlur?: boolean | undefined, outro?: (OverlayAnimationSideInput | null) | undefined, textIntro?: (OverlayAnimationSideInput | null) | undefined, textOutro?: (OverlayAnimationSideInput | null) | undefined}; export type OverlayDepth = 'front' | 'behind_presenter'; export type OverlayDepthChanges = Array<{atMs: number, depth: OverlayDepth}>; export type OverlayDimensions = {height: number, width: number}; export type OverlayPoint = {xPct: number, yPct: number}; export type TransitionStyle = 'smooth' | 'hard_cut'; export type UpdateClipOverlayRequest = {animation?: (OverlayAnimationInput | null) | undefined, depth?: OverlayDepth | undefined, depthChanges?: OverlayDepthChanges | undefined, dimensions?: OverlayDimensions | undefined, durationMs?: number | undefined, name?: string | undefined, point?: OverlayPoint | undefined, startTimeMs?: number | undefined, transition?: TransitionStyle | undefined, zIndex?: number | undefined}; export type PatchApiV1VideosIdClipsClipIdOverlaysOverlayIdArgs = {id: string, clipId: string, overlayId: string, body: UpdateClipOverlayRequest}; export type PatchApiV1VideosIdClipsClipIdOverlaysOverlayIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const overlayAnimationCurve = z.enum(["linear", "smooth", "natural", "slow_down", "accelerate", "elastic", "bounce", "overshoot", "impulse", "swing", "custom", "spring"]); export const overlayAnimationSpringOutput = z.object({damping: z.number().gte(1).lte(300), mass: z.number().gte(0.1).lte(10), stiffness: z.number().gte(1).lte(1000)}); export const overlayAnimationEasing = z.object({bezier: z.array(z.union([z.number().gte(0).lte(1), z.number(), z.number().gte(0).lte(1), z.number()])).optional(), curve: overlayAnimationCurve, intensity: z.number().gte(0).lte(1), spring: overlayAnimationSpringOutput.optional()}); export const overlayAnimationPreset = z.enum(["fade", "slide_up", "slide_down", "slide_left", "slide_right", "mask_up", "mask_down", "grow", "shrink", "blur", "blur_slide_up"]); export const overlayAnimationText = z.object({delayMs: z.number().int().gte(0).lte(2000), order: z.enum(["forward", "backward", "center", "edges", "random"]), smoothing: z.enum(["linear", "smooth", "natural", "slow_down", "accelerate", "elastic", "overshoot", "impulse", "swing"]), unit: z.enum(["letters", "words", "lines"])}); export const overlayAnimationSide = z.object({blur: z.number(), clip: z.boolean(), durationMs: z.number().int().gte(-9007199254740991).lte(9007199254740991), easing: overlayAnimationEasing, moveX: z.number(), moveY: z.number(), opacity: z.number(), preset: overlayAnimationPreset.nullable(), rotate: z.number(), scale: z.number(), text: overlayAnimationText.optional()}); export const overlayAnimation = z.object({intro: overlayAnimationSide.nullable(), motionBlur: z.boolean(), outro: overlayAnimationSide.nullable(), textIntro: overlayAnimationSide.nullable(), textOutro: overlayAnimationSide.nullable()}); export const overlayDepth = z.enum(["front", "behind_presenter"]); export const overlayDepthChanges = z.array(z.object({atMs: z.number().gte(0), depth: overlayDepth})); export const overlayDimensionsOutput = z.object({height: z.number().gt(0), width: z.number().gt(0)}); export const overlayPointOutput = z.object({xPct: z.number(), yPct: z.number()}); export const transitionStyle = z.enum(["smooth", "hard_cut"]); export const overlayZIndex = z.number().int().gte(0).lte(9007199254740991); export const clipOverlay = z.object({animation: overlayAnimation.nullable(), depth: overlayDepth, depthChanges: overlayDepthChanges.optional(), dimensions: overlayDimensionsOutput, durationMs: z.number().gte(0), id: z.string(), imageUrl: z.string().nullable().optional(), motionDocumentId: z.string().optional(), name: z.string().nullable().optional(), point: overlayPointOutput, sourceId: z.string().nullable().optional(), startTimeMs: z.number().gte(0), transition: transitionStyle, type: z.enum(["image", "video", "motion"]), zIndex: overlayZIndex}); export const clipOverlayResponse = z.object({overlay: clipOverlay}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update an overlay * * PATCH /v1/videos/{id}/clips/{clipId}/overlays/{overlayId} */ export const patchApiV1VideosIdClipsClipIdOverlaysOverlayId = async (args: PatchApiV1VideosIdClipsClipIdOverlaysOverlayIdArgs, options?: PatchApiV1VideosIdClipsClipIdOverlaysOverlayIdOptions) => { const {baseUrl = "https://api.tella.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.id))}/clips/${encodeURIComponent(String(args.clipId))}/overlays/${encodeURIComponent(String(args.overlayId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(clipOverlayResponse, await res.json()) };