Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/text-selection

Package Overview
Dependencies
Maintainers
1
Versions
670
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/text-selection - npm Package Compare versions

Comparing version 0.0.0-dev-20230223073112 to 0.0.0-dev-20230504114722

17

dist/index.d.ts

@@ -1,10 +0,11 @@

declare function disableTextSelection({ target, doc }?: {
target?: HTMLElement;
type DisableTextSelectionOptions<T = MaybeElement> = {
target?: T;
doc?: Document;
}): () => void;
declare function restoreTextSelection({ target, doc }?: {
target?: HTMLElement;
doc?: Document;
}): void;
defer?: boolean;
};
declare function restoreTextSelection(options?: DisableTextSelectionOptions): void;
type MaybeElement = HTMLElement | null | undefined;
type NodeOrFn = MaybeElement | (() => MaybeElement);
declare function disableTextSelection(options?: DisableTextSelectionOptions<NodeOrFn>): () => void;
export { disableTextSelection, restoreTextSelection };
export { DisableTextSelectionOptions, disableTextSelection, restoreTextSelection };

@@ -27,20 +27,11 @@ "use strict";

module.exports = __toCommonJS(src_exports);
var import_dom_query = require("@zag-js/dom-query");
var state = "default";
var userSelect = "";
var elementMap = /* @__PURE__ */ new WeakMap();
var isIos = () => {
const userAgent = navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test(userAgent);
};
var nextTick = (fn) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
fn();
});
});
};
function disableTextSelection({ target, doc } = {}) {
const _document = doc ?? document;
const rootEl = _document.documentElement;
if (isIos()) {
function disableTextSelectionImpl(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if ((0, import_dom_query.isIos)()) {
if (state === "default") {

@@ -55,8 +46,9 @@ userSelect = rootEl.style.webkitUserSelect;

}
return () => restoreTextSelection({ target, doc: _document });
return () => restoreTextSelection({ target, doc: docNode });
}
function restoreTextSelection({ target, doc } = {}) {
const _document = doc ?? document;
const rootEl = _document.documentElement;
if (isIos()) {
function restoreTextSelection(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if ((0, import_dom_query.isIos)()) {
if (state !== "disabled")

@@ -66,3 +58,3 @@ return;

setTimeout(() => {
nextTick(() => {
(0, import_dom_query.nextTick)(() => {
if (state === "restoring") {

@@ -90,2 +82,16 @@ if (rootEl.style.webkitUserSelect === "none") {

}
function disableTextSelection(options = {}) {
const { defer, target, ...restOptions } = options;
const func = defer ? import_dom_query.raf : (v) => v();
const cleanups = [];
cleanups.push(
func(() => {
const node = typeof target === "function" ? target() : target;
cleanups.push(disableTextSelectionImpl({ ...restOptions, target: node }));
})
);
return () => {
cleanups.forEach((fn) => fn?.());
};
}
// Annotate the CommonJS export names for ESM import in node:

@@ -92,0 +98,0 @@ 0 && (module.exports = {

{
"name": "@zag-js/text-selection",
"version": "0.0.0-dev-20230223073112",
"version": "0.0.0-dev-20230504114722",
"description": "",

@@ -29,2 +29,5 @@ "keywords": [

},
"dependencies": {
"@zag-js/dom-query": "0.1.4"
},
"module": "dist/index.mjs",

@@ -31,0 +34,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc