"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.releaseMatchMedia = exports.getMatchMedia = void 0;
var mq_json_1 = __importDefault(require("../mq/mq.json"));
var pool = {};
var refCounters = {};
/**
 * Возвращает MediaQueryList для заданного media-выражения.
 *
 * @param queryProp media выражение или кастомные запросы из `src/mq/mq.json`, например `--small`.
 */
function getMatchMedia(queryProp) {
    var query = mq_json_1.default[queryProp] || queryProp;
    if (pool[query]) {
        refCounters[query] += 1;
    }
    else {
        pool[query] = window.matchMedia(query);
        refCounters[query] = 1;
    }
    return pool[query];
}
exports.getMatchMedia = getMatchMedia;
/**
 * Удаляет MediaQueryList.
 *
 * @param queryProp media выражение
 */
function releaseMatchMedia(queryProp) {
    var query = mq_json_1.default[queryProp] || queryProp;
    refCounters[query] -= 1;
    if (pool[query] && refCounters[query] === 0) {
        delete pool[query];
        delete refCounters[query];
    }
}
exports.releaseMatchMedia = releaseMatchMedia;

//# sourceMappingURL=match-media.js.map
