"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/utils/sorting.ts
var sorting_exports = {};
__export(sorting_exports, {
  orderBy: () => orderBy
});
module.exports = __toCommonJS(sorting_exports);
function isGreater(a, b) {
  if (typeof a === "string" && typeof b === "string") {
    return a > b;
  }
  return Number(a) > Number(b);
}
var comparator = (field, items, order) => {
  return (a, b) => {
    let cmpA, cmpB;
    if (typeof field === "function") {
      cmpA = field(a);
      cmpB = field(b);
    } else {
      cmpA = a[field];
      cmpB = b[field];
    }
    if (isGreater(cmpA, cmpB)) {
      return order === "asc" ? 1 : -1;
    } else if (isGreater(cmpB, cmpA)) {
      return order === "asc" ? -1 : 1;
    }
    const orderA = items.findIndex((item) => item === a);
    const orderB = items.findIndex((item) => item === b);
    if (orderA > orderB) {
      return 1;
    } else if (orderB > orderA) {
      return -1;
    }
    return 0;
  };
};
function orderBy(items, field, order = "asc") {
  return items.concat().sort(comparator(field, items, order));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  orderBy
});
//# sourceMappingURL=sorting.cjs.map
