function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/**
 * 平面图编辑态：侧栏图元拖拽到画布的 DataTransfer 与坐标
 */

/** 与 setData 一致，用于识别左侧图元栏发起的拖拽 */
export var FLOOR_MAP_PALETTE_DRAG_MIME = 'application/x-pisell-floor-map-element';
/**
 * 与 {@link useFloorMapEditState} 落点一致：内容区 drop 的 offset 减去内容区 padding 偏移
 */
export function sceneXYFromContentDropOffset(offsetX, offsetY, contentOffset) {
  return {
    x: Math.round(offsetX - contentOffset.x),
    y: Math.round(offsetY - contentOffset.y)
  };
}

/** 是否为左侧图元栏拖拽（非本地文件 / 外链图片） */
export function isFloorMapPaletteDrag(dt) {
  var _dt$types;
  if (!dt) return false;
  return Array.from((_dt$types = dt.types) !== null && _dt$types !== void 0 ? _dt$types : []).includes(FLOOR_MAP_PALETTE_DRAG_MIME);
}

/**
 * 解析侧栏拖拽 payload；非法时返回 null
 */
export function parsePaletteDragPayload(dt) {
  try {
    var raw = dt.getData(FLOOR_MAP_PALETTE_DRAG_MIME);
    if (!raw) return null;
    var o = JSON.parse(raw);
    if (!o || _typeof(o) !== 'object') return null;
    var rec = o;
    var elementKind = rec.elementKind;
    if (typeof elementKind !== 'string' || !elementKind) return null;
    var dataSourceKey = typeof rec.dataSourceKey === 'string' ? rec.dataSourceKey : undefined;
    var recordId = typeof rec.recordId === 'string' ? rec.recordId : undefined;
    var recordIds;
    var rawIds = rec.recordIds;
    if (Array.isArray(rawIds)) {
      recordIds = rawIds.filter(function (x) {
        return typeof x === 'string' && x;
      });
      if (recordIds.length === 0) recordIds = undefined;
    }
    var builtinShapeKey = typeof rec.builtinShapeKey === 'string' && rec.builtinShapeKey ? rec.builtinShapeKey : undefined;
    return {
      elementKind: elementKind,
      dataSourceKey: dataSourceKey,
      recordId: recordId,
      recordIds: recordIds,
      builtinShapeKey: builtinShapeKey
    };
  } catch (_unused) {
    return null;
  }
}