import type { ElementDatum, ElementType } from '../types';
import { idOf } from '../utils/id';
import type { DrawData, ProcedureData } from './types';
/**
* 重新分配绘制任务
*
* Reassign drawing tasks
* @param input - 绘制数据 | DrawData
* @param type - 类型 | type
* @param elementType - 元素类型 | element type
* @param datum - 数据 | data
* @param overwrite - 是否覆盖现有数据 | whether to overwrite existing data
*/
export function reassignTo(
input: DrawData,
type: 'add' | 'update' | 'remove',
elementType: ElementType,
datum: ElementDatum,
overwrite?: boolean,
) {
const id = idOf(datum);
const typeName = `${elementType}s` as keyof ProcedureData;
const exitsDatum: any = overwrite
? datum
: input.add[typeName].get(id) || input.update[typeName].get(id) || input.remove[typeName].get(id) || datum;
Object.entries(input).forEach(([_type, value]) => {
if (type === _type) value[typeName].set(id, exitsDatum);
else value[typeName].delete(id);
});
}
/**
* 判断样式是否与原始样式一致
*
* Determine whether the style is consistent with the original style
* @param style - 样式 | style
* @param originalStyle - 原始样式 | original style
* @returns 是否一致 | Whether it is consistent
*/
export function isStyleEqual(style: Record, originalStyle: Record) {
return Object.keys(style).every((key) => style[key] === originalStyle[key]);
}