@zag-js/text-selection
Advanced tools
Comparing version 0.53.0 to 0.54.0
@@ -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 |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
19471
250
1
+ Added@zag-js/dom-query@0.54.0(transitive)
- Removed@zag-js/dom-query@0.53.0(transitive)
Updated@zag-js/dom-query@0.54.0