export class AnimationLayer {
    name;
    weight;
    additive;
    mask;
    actions = [];
    baseWeights = new WeakMap();
    constructor(name, weightOrOptions = 1) {
        if (name.trim().length === 0) {
            throw new Error("AnimationLayer name cannot be empty.");
        }
        this.name = name;
        const options = typeof weightOrOptions === "number" ? { weight: weightOrOptions } : weightOrOptions;
        this.weight = options.weight ?? 1;
        this.additive = options.additive ?? false;
        this.mask = [...(options.mask ?? [])];
        if (!Number.isFinite(this.weight) || this.weight < 0) {
            throw new Error("AnimationLayer weight must be finite and non-negative.");
        }
        for (const entry of this.mask) {
            if (entry.trim().length === 0) {
                throw new Error("AnimationLayer mask entries cannot be empty.");
            }
        }
    }
    add(action) {
        if (!this.actions.includes(action)) {
            this.actions.push(action);
            this.baseWeights.set(action, action.weight);
        }
    }
    applyWeight() {
        for (const action of this.actions) {
            action.setWeight((this.baseWeights.get(action) ?? action.weight) * this.weight);
        }
    }
    capturesTarget(target) {
        if (this.mask.length === 0) {
            return true;
        }
        return this.mask.some((entry) => target === entry || target.startsWith(`${entry}.`));
    }
    snapshot() {
        return {
            name: this.name,
            weight: this.weight,
            additive: this.additive,
            mask: [...this.mask],
            actions: this.actions.map((action) => action.clip.name)
        };
    }
}
//# sourceMappingURL=AnimationLayer.js.map