Socket
Socket
Sign inDemoInstall

@zag-js/text-selection

Package Overview
Dependencies
Maintainers
1
Versions
655
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.53.0 to 0.54.0

98

dist/index.js

@@ -1,2 +0,98 @@

"use strict";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 src_exports={};__export(src_exports,{disableTextSelection:()=>disableTextSelection,restoreTextSelection:()=>restoreTextSelection});module.exports=__toCommonJS(src_exports);var import_dom_query=require("@zag-js/dom-query");var state="default";var userSelect="";var elementMap=new WeakMap;function disableTextSelectionImpl(options={}){const{target,doc}=options;const docNode=doc??document;const rootEl=docNode.documentElement;if((0,import_dom_query.isIos)()){if(state==="default"){userSelect=rootEl.style.webkitUserSelect;rootEl.style.webkitUserSelect="none"}state="disabled"}else if(target){elementMap.set(target,target.style.userSelect);target.style.userSelect="none"}return()=>restoreTextSelection({target,doc:docNode})}function restoreTextSelection(options={}){const{target,doc}=options;const docNode=doc??document;const rootEl=docNode.documentElement;if((0,import_dom_query.isIos)()){if(state!=="disabled")return;state="restoring";setTimeout(()=>{(0,import_dom_query.nextTick)(()=>{if(state==="restoring"){if(rootEl.style.webkitUserSelect==="none"){rootEl.style.webkitUserSelect=userSelect||""}userSelect="";state="default"}})},300)}else{if(target&&elementMap.has(target)){const prevUserSelect=elementMap.get(target);if(target.style.userSelect==="none"){target.style.userSelect=prevUserSelect??""}if(target.getAttribute("style")===""){target.removeAttribute("style")}elementMap.delete(target)}}}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?.())}}0&&(module.exports={disableTextSelection,restoreTextSelection});
"use strict";
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);
// src/index.ts
var src_exports = {};
__export(src_exports, {
disableTextSelection: () => disableTextSelection,
restoreTextSelection: () => restoreTextSelection
});
module.exports = __toCommonJS(src_exports);
var import_dom_query = require("@zag-js/dom-query");
var state = "default";
var userSelect = "";
var elementMap = /* @__PURE__ */ new WeakMap();
function disableTextSelectionImpl(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if ((0, import_dom_query.isIos)()) {
if (state === "default") {
userSelect = rootEl.style.webkitUserSelect;
rootEl.style.webkitUserSelect = "none";
}
state = "disabled";
} else if (target) {
elementMap.set(target, target.style.userSelect);
target.style.userSelect = "none";
}
return () => restoreTextSelection({ target, doc: docNode });
}
function restoreTextSelection(options = {}) {
const { target, doc } = options;
const docNode = doc ?? document;
const rootEl = docNode.documentElement;
if ((0, import_dom_query.isIos)()) {
if (state !== "disabled")
return;
state = "restoring";
setTimeout(() => {
(0, import_dom_query.nextTick)(() => {
if (state === "restoring") {
if (rootEl.style.webkitUserSelect === "none") {
rootEl.style.webkitUserSelect = userSelect || "";
}
userSelect = "";
state = "default";
}
});
}, 300);
} else {
if (target && elementMap.has(target)) {
const prevUserSelect = elementMap.get(target);
if (target.style.userSelect === "none") {
target.style.userSelect = prevUserSelect ?? "";
}
if (target.getAttribute("style") === "") {
target.removeAttribute("style");
}
elementMap.delete(target);
}
}
}
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:
0 && (module.exports = {
disableTextSelection,
restoreTextSelection
});
//# sourceMappingURL=index.js.map

4

package.json
{
"name": "@zag-js/text-selection",
"version": "0.53.0",
"version": "0.54.0",
"description": "",

@@ -31,3 +31,3 @@ "keywords": [

"dependencies": {
"@zag-js/dom-query": "0.53.0"
"@zag-js/dom-query": "0.54.0"
},

@@ -34,0 +34,0 @@ "module": "dist/index.mjs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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