'use strict'; import { WorkletsModule } from '../WorkletsModule/NativeWorklets'; import { createSerializable } from './serializable'; import type { FixedSynchronizable, Synchronizable, SynchronizableConfig, } from './types'; export function createSynchronizable( initialValue: TValue, config: SynchronizableConfig & { fixedType: true } ): FixedSynchronizable; export function createSynchronizable( initialValue: TValue, config: SynchronizableConfig ): Synchronizable | FixedSynchronizable; export function createSynchronizable( initialValue: TValue, config?: SynchronizableConfig ): Synchronizable; export function createSynchronizable( initialValue: TValue, config?: SynchronizableConfig ): Synchronizable { const isFixed = !!config?.fixedType; if ( __DEV__ && isFixed && !(typeof initialValue === 'number' || typeof initialValue === 'boolean') ) { throw new Error( '[Worklets] `fixedType` requires a number or boolean initial value.' ); } const synchronizableRef = WorkletsModule.createSynchronizable( isFixed ? initialValue : createSerializable(initialValue), isFixed ); return globalThis.__synchronizableUnpacker( synchronizableRef, isFixed ) as unknown as Synchronizable; }