"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get getRectInMultiPlatform () {
        return getRectInMultiPlatform;
    },
    get getRectInMultiPlatformWithoutCache () {
        return getRectInMultiPlatformWithoutCache;
    },
    get makeRect () {
        return makeRect;
    }
});
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _ts_generator = require("@swc/helpers/_/_ts_generator");
var _taro = require("@tarojs/taro");
var _lru = require("../lru");
var _getrect = require("../get-rect");
var lru = new _lru.MiniLru(10);
var createScopedSelectorQuery = function createScopedSelectorQuery(scope) {
    var query = (0, _taro.createSelectorQuery)();
    return scope ? query.in(scope) : query;
};
function makeRect(width, height) {
    return {
        top: 0,
        left: 0,
        right: width,
        bottom: height,
        width: width,
        height: height
    };
}
var getRectInMultiPlatform = function getRectInMultiPlatform(element) {
    var harmonyId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '';
    return (0, _async_to_generator._)(function() {
        return (0, _ts_generator._)(this, function(_state) {
            if (element) {
                if (_getrect.inBrowser) {
                    return [
                        2,
                        Promise.resolve((0, _getrect.getRect)(element))
                    ];
                }
                // 小程序下的逻辑
                return [
                    2,
                    new Promise(function(resolve, reject) {
                        if (lru.has(element)) {
                            resolve(lru.get(element));
                            return;
                        }
                        createScopedSelectorQuery(element === null || element === void 0 ? void 0 : element._scope) // https://taro.jd.com/docs/reference/config/page/
                        .select("#".concat(harmonyId || element.uid)).boundingClientRect().exec(function(param) {
                            var _param = (0, _sliced_to_array._)(param, 1), rects = _param[0];
                            if (rects) {
                                lru.set(element, rects);
                            }
                            resolve(rects);
                        });
                    })
                ];
            }
            return [
                2,
                Promise.resolve(makeRect(0, 0))
            ];
        });
    })();
};
var getRectInMultiPlatformWithoutCache = function getRectInMultiPlatformWithoutCache(element) {
    var harmonyId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '';
    return (0, _async_to_generator._)(function() {
        return (0, _ts_generator._)(this, function(_state) {
            if (element) {
                if (_getrect.inBrowser) {
                    return [
                        2,
                        Promise.resolve((0, _getrect.getRect)(element))
                    ];
                }
                return [
                    2,
                    new Promise(function(resolve, reject) {
                        createScopedSelectorQuery(element === null || element === void 0 ? void 0 : element._scope) // https://taro.jd.com/docs/reference/config/page/
                        .select("#".concat(harmonyId || element.uid)).boundingClientRect().exec(function(param) {
                            var _param = (0, _sliced_to_array._)(param, 1), rects = _param[0];
                            resolve(rects);
                        });
                    })
                ];
            }
            return [
                2,
                Promise.resolve(makeRect(0, 0))
            ];
        });
    })();
};
