"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);
var DeepCopy_exports = {};
__export(DeepCopy_exports, {
  deepCopy: () => deepCopy
});
module.exports = __toCommonJS(DeepCopy_exports);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function deepCopy(value) {
  let clones;
  function copy(value2) {
    if (typeof value2 === "object") {
      if (value2 === null) {
        return null;
      }
      let clone = clones?.get(value2);
      if (clone) {
        return clone;
      }
      if (Array.isArray(value2)) {
        clone = value2.map(copy);
      } else if (ArrayBuffer.isView(value2)) {
        const ViewType = value2.constructor;
        clone = ViewType.from(value2);
      } else if (value2 instanceof Set) {
        const set = remember(value2, /* @__PURE__ */ new Set());
        for (const member of value2) {
          set.add(copy(member));
        }
        return set;
      } else if (value2 instanceof Map) {
        const map = remember(value2, /* @__PURE__ */ new Map());
        for (const [k, v] of value2) {
          map.set(copy(k), copy(v));
        }
        return map;
      } else {
        clone = Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, copy(v)]));
      }
      return remember(value2, clone);
    }
    return value2;
  }
  function remember(original, clone) {
    (clones ??= /* @__PURE__ */ new Map()).set(original, clone);
    return clone;
  }
  return copy(value);
}
//# sourceMappingURL=DeepCopy.js.map
