function cloneScriptAttachmentValue(value) {
    if (Array.isArray(value)) {
        return value.map((item)=>cloneScriptAttachmentValue(item));
    }
    if (value && typeof value === 'object') {
        const result = {};
        for (const [key, item] of Object.entries(value)){
            result[key] = cloneScriptAttachmentValue(item);
        }
        return result;
    }
    return value;
}
/**
 * Normalizes a script attachment config into a clone-safe serializable shape.
 *
 * @public
 */ function normalizeScriptAttachmentConfig(value) {
    if (value == null) {
        return null;
    }
    if (Array.isArray(value)) {
        return cloneScriptAttachmentValue(value);
    }
    if (typeof value === 'object') {
        return cloneScriptAttachmentValue(value);
    }
    return null;
}
/**
 * Describes a script attached to a scene node.
 *
 * @public
 */ class ScriptAttachment {
    script;
    config;
    constructor(script = '', config = null){
        this.script = script ?? '';
        this.config = normalizeScriptAttachmentConfig(config);
    }
}
/**
 * Normalizes an arbitrary value into an array of script attachments.
 *
 * @public
 */ function normalizeScriptAttachments(value) {
    if (!Array.isArray(value)) {
        return [];
    }
    const result = [];
    for (const item of value){
        if (item instanceof ScriptAttachment) {
            if (item.script || item.config != null) {
                result.push(new ScriptAttachment(item.script, item.config));
            }
            continue;
        }
        if (item && typeof item === 'object') {
            const attachment = item;
            const script = typeof attachment.script === 'string' ? attachment.script : '';
            const config = normalizeScriptAttachmentConfig(attachment.config);
            if (script || config != null) {
                result.push(new ScriptAttachment(script, config));
            }
        }
    }
    return result;
}

export { ScriptAttachment, normalizeScriptAttachmentConfig, normalizeScriptAttachments };
//# sourceMappingURL=script_attachment.js.map
