UNPKG

@iicoding/utils

Version:

Browser 端 - 类型判断 - 类似 koa 的异步compose - sleep - 扩展对象属性 - 扩展 storage 对象功能

61 lines (59 loc) 1.94 kB
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/helper/toggle-selection.ts var toggle_selection_exports = {}; __export(toggle_selection_exports, { toggleSelection: () => toggleSelection }); module.exports = __toCommonJS(toggle_selection_exports); function toggleSelection() { var _a; const selection = document.getSelection(); if (!(selection == null ? void 0 : selection.rangeCount)) { return function() { }; } let active = document.activeElement; const ranges = []; for (let i = 0; i < selection.rangeCount; i++) { ranges.push(selection.getRangeAt(i)); } switch ((_a = active == null ? void 0 : active.tagName) == null ? void 0 : _a.toUpperCase()) { case "INPUT": case "TEXTAREA": active.blur(); break; default: active = null; break; } selection.removeAllRanges(); return function() { selection.type === "Caret" && selection.removeAllRanges(); if (!selection.rangeCount) { ranges.forEach(function(range) { selection.addRange(range); }); } active && active.focus(); }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { toggleSelection });