@tamagui/react-native-web-lite
Version:
React Native for Web
116 lines (115 loc) • 4.87 kB
JavaScript
;
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: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__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: !0 }), mod);
var AppState_exports = {};
__export(AppState_exports, {
default: () => AppState
});
module.exports = __toCommonJS(AppState_exports);
var import_react_native_web_internals = require("@tamagui/react-native-web-internals");
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor))
throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor;
}
function _define_property(obj, key, value) {
return key in obj ? Object.defineProperty(obj, key, {
value,
enumerable: !0,
configurable: !0,
writable: !0
}) : obj[key] = value, obj;
}
var isPrefixed = (
// eslint-disable-next-line no-prototype-builtins
import_react_native_web_internals.canUseDOM && !document.hasOwnProperty("hidden") && document.hasOwnProperty("webkitHidden")
), EVENT_TYPES = [
"change",
"memoryWarning"
], VISIBILITY_CHANGE_EVENT = isPrefixed ? "webkitvisibilitychange" : "visibilitychange", VISIBILITY_STATE_PROPERTY = isPrefixed ? "webkitVisibilityState" : "visibilityState", AppStates = {
BACKGROUND: "background",
ACTIVE: "active"
}, EventEmitter = /* @__PURE__ */ function() {
"use strict";
function EventEmitter2() {
_class_call_check(this, EventEmitter2), _define_property(this, "listeners", {});
}
return _create_class(EventEmitter2, [
{
key: "addListener",
value: function(type, handler) {
var _this_listeners, _type, _;
(_ = (_this_listeners = this.listeners)[_type = type]) !== null && _ !== void 0 || (_this_listeners[_type] = /* @__PURE__ */ new Set()), this.listeners[type].add(handler);
}
},
{
key: "emit",
value: function(type, state) {
var _this_listeners_type;
(_this_listeners_type = this.listeners[type]) === null || _this_listeners_type === void 0 || _this_listeners_type.forEach(function(cb) {
return cb(state);
});
}
},
{
key: "removeListener",
value: function(type, handler) {
var _this_listeners_type;
(_this_listeners_type = this.listeners[type]) === null || _this_listeners_type === void 0 || _this_listeners_type.delete(handler);
}
}
]), EventEmitter2;
}(), hasBoundVisibilityChangeEvent = !1, changeEmitter = new EventEmitter(), AppState = /* @__PURE__ */ function() {
"use strict";
function AppState2() {
_class_call_check(this, AppState2);
}
return _create_class(AppState2, null, [
{
key: "currentState",
get: function() {
if (!AppState2.isAvailable)
return AppStates.ACTIVE;
switch (document[VISIBILITY_STATE_PROPERTY]) {
case "hidden":
case "prerender":
case "unloaded":
return AppStates.BACKGROUND;
default:
return AppStates.ACTIVE;
}
}
},
{
key: "addEventListener",
value: function(type, handler) {
if (AppState2.isAvailable && ((0, import_react_native_web_internals.invariant)(EVENT_TYPES.indexOf(type) !== -1, 'Trying to subscribe to unknown event: "%s"', type), type === "change"))
return hasBoundVisibilityChangeEvent || (hasBoundVisibilityChangeEvent = !0, document.addEventListener(VISIBILITY_CHANGE_EVENT, function() {
changeEmitter && changeEmitter.emit("change", AppState2.currentState);
}, !1)), changeEmitter.addListener(type, handler);
}
}
]), AppState2;
}();
_define_property(AppState, "isAvailable", import_react_native_web_internals.canUseDOM && document[VISIBILITY_STATE_PROPERTY]);
//# sourceMappingURL=index.js.map