// Copyright 2026 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. import { getEventValue } from './event-value.js'; import { prepareSpreadRefAttrValue } from './ref.js'; import { isEventPropKey, isNamespacedEventPropKey, transformAttrName } from '../../shared/attribute-name.js'; import type { SerializableValue } from '../protocol/types.js'; function isSpreadRecord(value: unknown): value is Record { return value !== null && typeof value === 'object' && !Array.isArray(value); } export function prepareSpreadAttrSlot( handleId: number, attrSlotIndex: number, value: unknown, ): SerializableValue | null { if (value === false || !isSpreadRecord(value)) { return null; } const prepared: Record = {}; for (const key in value) { const spreadValue = value[key]; if (key === '__spread' || key === '__self' || key === '__source') { continue; } if (key === 'class' || key === 'className') { prepared['class'] = (spreadValue ?? '') as SerializableValue; continue; } if (key === 'ref') { const refValue = prepareSpreadRefAttrValue(handleId, attrSlotIndex, value); if (refValue !== undefined) { prepared['ref'] = refValue; } continue; } const transformedKey = transformAttrName(key); if (isEventPropKey(transformedKey)) { prepared[transformedKey] = spreadValue === null || spreadValue === undefined || spreadValue === false ? null : getEventValue(handleId, attrSlotIndex, key); continue; } if ( spreadValue === undefined || transformedKey.endsWith(':ref') || transformedKey.endsWith(':gesture') || isNamespacedEventPropKey(key) || typeof spreadValue === 'function' ) { continue; } prepared[transformedKey] = spreadValue as SerializableValue; } return prepared; }