{"_id":"@abasb75/selection-js","_rev":"1-402fc2d5aeaa6b601c2af41a601405e4","name":"@abasb75/selection-js","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@abasb75/selection-js","version":"0.0.1","description":"Library for work javascript text selection","main":"index.js","keywords":["selection","selection-js","rich-editor","getSelection","window getSelection"],"peerDependencies":{"@abasb75/copy-to-clipboard":"^0.0.5"},"author":{"name":"Abbas Bagheri","email":"abasgabagheria@gmail.com","url":"https://abasgabagheri.ir"},"homepage":"https://github.com/abasb75/selection-js","bugs":{"url":"https://github.com/abasb75/selection-js/issues","email":"abasgabagheria@gmail.com"},"_id":"@abasb75/selection-js@0.0.1","_nodeVersion":"14.18.2","_npmVersion":"6.14.15","dist":{"integrity":"sha512-yUPBRaxxCTN726CC3SFOpdq59P2DOcM2t+CO8/6m3T06YW/9Ndz6o86rKDt04m4pEHwjKjmU7iLwQNVOTx6tLg==","shasum":"7ce7b3e7a01a289af87d95199339444e24c8deca","tarball":"https://registry.npmjs.org/@abasb75/selection-js/-/selection-js-0.0.1.tgz","fileCount":21,"unpackedSize":69207,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAdizkG/ZpOY8IzyrbYw6lwp5Hg8wzDe/xUHxHzdcTnTAiEAjxqgBM5ybWBLcZ1Lsi5UMgv5SHC+Wvw3e3olymLOUFE="}]},"_npmUser":{"name":"abasb75","email":"abasbagheria@gmail.com"},"directories":{},"maintainers":[{"name":"abasb75","email":"abasbagheria@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/selection-js_0.0.1_1702033317227_0.47492153361539646"},"_hasShrinkwrap":false},"0.0.2":{"name":"@abasb75/selection-js","version":"0.0.2","description":"Library for work javascript text selection","private":false,"main":"index.js","keywords":["selection","selection-js","rich-editor","getSelection","window getSelection"],"peerDependencies":{"@abasb75/copy-to-clipboard":"^0.0.5"},"author":{"name":"Abbas Bagheri","email":"abasgabagheria@gmail.com","url":"https://abasgabagheri.ir"},"homepage":"https://github.com/abasb75/selection-js","bugs":{"url":"https://github.com/abasb75/selection-js/issues","email":"abasgabagheria@gmail.com"},"_id":"@abasb75/selection-js@0.0.2","_nodeVersion":"14.18.2","_npmVersion":"6.14.15","dist":{"integrity":"sha512-NSu0yVU8b0GsidLbcMF3zt22UOQat4OmtsmqkVHKClgNEPSiVhvMC/RLwetXkfZiV0KAPa57FULPAMqOWVuBRg==","shasum":"64e5a78874ee38659f1449ff39802b790ceeb3f5","tarball":"https://registry.npmjs.org/@abasb75/selection-js/-/selection-js-0.0.2.tgz","fileCount":21,"unpackedSize":60701,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHlrqgjhJRVwyyoyH4rjcpeoW2RAKJZEZKfDEiP+8qPTAiEAqpDfLLCday4TJX6/E3bsZQcxSvHqGbhwUWx6zDxPVk8="}]},"_npmUser":{"name":"abasb75","email":"abasbagheria@gmail.com"},"directories":{},"maintainers":[{"name":"abasb75","email":"abasbagheria@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/selection-js_0.0.2_1702054326700_0.4509495844453435"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-08T11:01:57.106Z","0.0.1":"2023-12-08T11:01:57.378Z","modified":"2023-12-08T16:52:07.087Z","0.0.2":"2023-12-08T16:52:06.901Z"},"maintainers":[{"name":"abasb75","email":"abasbagheria@gmail.com"}],"description":"Library for work javascript text selection","homepage":"https://github.com/abasb75/selection-js","keywords":["selection","selection-js","rich-editor","getSelection","window getSelection"],"author":{"name":"Abbas Bagheri","email":"abasgabagheria@gmail.com","url":"https://abasgabagheri.ir"},"bugs":{"url":"https://github.com/abasb75/selection-js/issues","email":"abasgabagheria@gmail.com"},"readme":"\r\n\r\n\r\n\r\n# Installation :\r\n\r\ninstall with command :\r\n```sh\r\nnpm i @abasb75/selection-js\r\n```\r\n\r\n# copy selected text\r\n`copyText()` used for copy selected text to user clipboard:\r\n<image src=\"https://github.com/abasb75/selection-js/blob/master/assets/copy-text.gif\" alt=\"selection.js\">\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\n<button onClick={e=>selection.copyText()}>Copy Selected Text</button>\r\n...\r\n\r\n```\r\n\r\n# copy selected text with style\r\n`copyStyledText()` used for copy selected text with style to user clipboard:\r\n\r\n<image src=\"https://github.com/abasb75/selection-js/blob/master/assets/copy-styled-text.gif\" alt=\"selection.js\">\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\n<button onClick={e=>selection.copyStyledText()}>Copy Selected Text</button>\r\n...\r\n\r\n```\r\n\r\n# copy selected text with style\r\n`copyHTML()` used for getting copy of html of selected text to user clipboard:\r\n\r\n<image src=\"https://github.com/abasb75/selection-js/blob/master/assets/copy-html.gif\" alt=\"selection.js\">\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\n<button onClick={e=>selection.copyHTML()}>Copy HTML</button>\r\n...\r\n\r\n```\r\n\r\n# Getting Container of selected text\r\n`getContainer()` can be used to get the container element:\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst container = selection.getContainer();\r\n...\r\n\r\n```\r\n\r\n\r\n# getAnchorContainer\r\nUse `getAnchorContainer()` to get the child of `container`, which is the parent of <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Selection/anchorNode\">anchorNode</a>.\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst anchorContainer = selection.getAnchorContainer();\r\n...\r\n\r\n\r\n```\r\n\r\n\r\n# getFocusContainer\r\nUse `getFocusContainer()` to get the child of `container`, which is the parent of <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Selection/focusNode\">focusNode</a>.\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst anchorContainer = selection.getFocusContainer();\r\n...\r\n\r\n\r\n```\r\n\r\n# getClonedNodes\r\n\r\n`getClonedNodes()` gives a tree of the nodes of the selected part of the page. The nodes of the tree aren't linked to the `DOM`\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst clonedTree = selection.getClonedNodes();\r\n...\r\n\r\n```\r\n\r\n# getTree\r\n\r\n`getTree()` gives a tree of the nodes of the selected part of the page. The nodes of the tree are linked to the `DOM`\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst tree = selection.getTree();\r\n...\r\n\r\n```\r\n\r\n# getNodes\r\n\r\n`getNodes()` gives an array of the nodes of the selected part of the page. The nodes of the tree are linked to the `DOM`\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst nodes = selection.getNodes();\r\n...\r\n\r\n```\r\n\r\n\r\n# asString\r\n\r\n`asString()` returns a string of selected part of web page!\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst nodes = selection.asString();\r\n// result: left-to-right or right-to-left\r\n...\r\n\r\n```\r\n\r\n# asHTML\r\n\r\n`asHTML()` returns a string include html of selected part of web page!\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst nodes = selection.asHTML();\r\n// result: <b><i><a href=\"#\">left</a>-to-<a href=\"#\">ri<span>ght</span></a></i></b>or<b><i>right-to-left</i></b>\r\n...\r\n\r\n```\r\n\r\n# caretPosition\r\n\r\n`caretPosition()` returns number of position of cursor (caret) in `innerHTML` of `container`\r\n\r\n```javascript\r\nimport slection from \"selection-js\";\r\n...\r\nconst position = selection.caretPosition();\r\n...\r\n\r\n```\r\n\r\n<image src=\"https://github.com/abasb75/selection-js/blob/master/assets/get-caret-position.png\" alt=\"selection.js\">\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","readmeFilename":"README.md"}