one
Version:
One is a React framework for web, iOS, and Android apps.
129 lines (126 loc) • 4.38 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: 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 index_native_exports = {};
__export(index_native_exports, {
ScreenCapture: () => ScreenCapture,
usePreventScreenCapture: () => usePreventScreenCapture
});
module.exports = __toCommonJS(index_native_exports);
var import_react = require("react");
var import_validate = require("./validate.native.js");
var import_validateCallback = require("../validateCallback.native.js");
var import_react_native_nitro_modules = require("react-native-nitro-modules");
var import_nativeError = require("../nativeError.native.js");
var hybrid;
function native() {
hybrid !== null && hybrid !== void 0 ? hybrid : hybrid = import_react_native_nitro_modules.NitroModules.createHybridObject("OneScreenCapture");
return hybrid;
}
function getState() {
return native().getState().catch(import_nativeError.rethrowNativeError);
}
function captureWindow() {
return native().captureWindow().catch(import_nativeError.rethrowNativeError);
}
function captureView(viewTag) {
(0, import_validate.validateViewTag)(viewTag);
return native().captureView(viewTag).catch(import_nativeError.rethrowNativeError);
}
function addStateListener(onChange) {
(0, import_validateCallback.validateCallback)(onChange, "ScreenCapture.addStateListener requires a function");
return native().addStateListener(onChange);
}
function addScreenshotListener(onScreenshot) {
(0, import_validateCallback.validateCallback)(onScreenshot, "ScreenCapture.addScreenshotListener requires a function");
return native().addScreenshotListener(onScreenshot);
}
var activeKeys = /* @__PURE__ */ new Set();
var transitions = Promise.resolve();
var armed = false;
var arming;
function enqueue(transition) {
var next = transitions.then(transition);
transitions = next.catch(function() {});
return next;
}
function prevent() {
var key = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : import_validate.preventDefaultKey;
(0, import_validate.assertPreventKey)(key, "prevent");
activeKeys.add(key);
if (armed) return Promise.resolve();
arming !== null && arming !== void 0 ? arming : arming = enqueue(async function() {
try {
if (activeKeys.size === 0 || armed) return;
await native().prevent();
armed = true;
} catch (error) {
activeKeys.clear();
(0, import_nativeError.rethrowNativeError)(error);
} finally {
arming = void 0;
}
});
return arming;
}
function allow() {
var key = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : import_validate.preventDefaultKey;
(0, import_validate.assertPreventKey)(key, "allow");
activeKeys.delete(key);
if (activeKeys.size > 0) return Promise.resolve();
return enqueue(async function() {
if (activeKeys.size > 0) return;
var wasArmed = armed;
armed = false;
try {
await native().allow();
} catch (error) {
armed = wasArmed;
(0, import_nativeError.rethrowNativeError)(error);
}
});
}
function isPrevented() {
return native().isPrevented().catch(import_nativeError.rethrowNativeError);
}
function usePreventScreenCapture() {
var key = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : import_validate.preventDefaultKey;
(0, import_validate.assertPreventKey)(key, "prevent");
(0, import_react.useEffect)(function() {
prevent(key).catch(function(error) {
console.error(`Failed to prevent screen capture: ${String(error)}`);
});
return function() {
allow(key).catch(function() {});
};
}, [key]);
}
var ScreenCapture = Object.freeze({
getState,
captureWindow,
captureView,
addStateListener,
addScreenshotListener,
prevent,
allow,
isPrevented
});
//# sourceMappingURL=index.native.js.map