"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 Aspect_exports = {};
__export(Aspect_exports, {
  Aspect: () => Aspect
});
module.exports = __toCommonJS(Aspect_exports);
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const empty = /* @__PURE__ */ new Map();
const aspectCache = /* @__PURE__ */ new Map();
class Aspect {
  definition;
  isEmpty = false;
  get valid() {
    return !this.errors;
  }
  constructor(definition) {
    this.definition = definition;
  }
  /**
   * Test for logical equivalence.
   */
  equals(other) {
    if (!(other instanceof this.constructor)) {
      return false;
    }
    return (0, import_general.isDeepEqual)(this.valueOf(), other.valueOf());
  }
  valueOf() {
    return this.isEmpty ? void 0 : this.toString();
  }
  error(code, message) {
    if (!this.errors) {
      this.errors = [];
    }
    this.errors.push({
      code,
      source: `${this.constructor.name} ${(0, import_general.serialize)(this.definition)}`,
      message
    });
  }
  static create(definition) {
    if (definition === void 0) {
      let none = empty.get(this);
      if (!none) {
        none = new this(definition);
        empty.set(this, none);
      }
      return none;
    }
    if (definition instanceof this) {
      return definition;
    }
    if (typeof definition === "string") {
      let slot = aspectCache.get(this);
      if (slot === void 0) {
        slot = {};
        aspectCache.set(this, slot);
      }
      let some = slot[definition];
      if (some) {
        return some;
      }
      some = definition === "" ? this.create() : new this(definition);
      slot[definition] = some;
      return some;
    }
    return new this(definition);
  }
  freeze() {
    Object.freeze(this);
  }
}
//# sourceMappingURL=Aspect.js.map
