"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 BackingEvents_exports = {};
__export(BackingEvents_exports, {
  BackingEvents: () => BackingEvents
});
module.exports = __toCommonJS(BackingEvents_exports);
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Ident[ifier: Apache-2.0
 */
const EventCache = /* @__PURE__ */ new WeakMap();
function BackingEvents(backing) {
  const target = backing.endpoint.eventsOf(backing.type);
  const constructor = target.constructor;
  let Implementation = EventCache.get(constructor);
  if (Implementation === void 0) {
    Implementation = EventEmitterProxy(target);
    EventCache.set(constructor, Implementation);
  }
  return new Implementation(target);
}
const TARGET = /* @__PURE__ */ Symbol("target");
const PROXIES = /* @__PURE__ */ Symbol("proxies");
class EventProxy extends import_general.ObservableProxy {
  constructor(target) {
    super(target);
  }
  get isQuieter() {
    return this.target.isQuieter;
  }
  get quiet() {
    return this.target.quiet;
  }
  get online() {
    return this.target.online;
  }
  toString() {
    return this.target.toString();
  }
}
function EventEmitterProxy(instance) {
  const descriptors = {
    [Symbol.dispose]: {
      value() {
        const proxies = this[PROXIES];
        if (!proxies) {
          return;
        }
        for (const proxy of Object.values(proxies)) {
          proxy[Symbol.dispose]();
        }
        this[PROXIES] = void 0;
      }
    }
  };
  for (const key in instance) {
    descriptors[key] = {
      get() {
        let proxies = this[PROXIES];
        if (proxies === void 0) {
          proxies = this[PROXIES] = {};
        } else if (key in proxies) {
          return proxies[key];
        }
        return proxies[key] = new EventProxy(this[TARGET][key]);
      }
    };
  }
  return (0, import_general.GeneratedClass)({
    name: `${instance.constructor.name}$Proxy`,
    base: import_general.EventEmitter,
    instanceDescriptors: descriptors,
    initialize(target) {
      this[TARGET] = target;
    }
  });
}
//# sourceMappingURL=BackingEvents.js.map
