{"name":"normalize-scroll-left","description":"Utility library to determine and normalize Element.scrollLeft behavior","version":"0.2.1","author":{"name":"Ali Taheri Moghaddar","email":"ali.taheri.m@gmail.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/alitaheri/normalize-scroll-left.git"},"keywords":["rtl","dom","scroll-left","scrollLeft","normalize","browser","element"],"scripts":{"build":"rimraf cjs esm && tsc --module commonjs --outDir cjs && tsc --module es6 --outDir esm","prepublishOnly":"npm run build","lint":"tslint -e \"node_modules/**\" \"src/**/*.ts\"","test":"mocha -r ts-node/register \"src/**/*.spec.ts\""},"license":"MIT","main":"cjs/main.js","module":"esm/main.js","types":"cjs/main.d.ts","devDependencies":{"@types/chai":"^4.2.12","@types/mocha":"^8.0.3","@types/node":"^14.6.4","chai":"^4.2.0","mocha":"^8.1.3","rimraf":"^3.0.2","ts-loader":"^8.0.3","ts-node":"^9.0.0","tslint":"^6.1.3","tslint-eslint-rules":"^5.4.0","tslint-microsoft-contrib":"^6.2.0","typescript":"^4.0.2"},"gitHead":"eef5dd4bfe62d7b5e5ee8103d40ba66f401cb094","bugs":{"url":"https://github.com/alitaheri/normalize-scroll-left/issues"},"homepage":"https://github.com/alitaheri/normalize-scroll-left#readme","_id":"normalize-scroll-left@0.2.1","_nodeVersion":"12.11.0","_npmVersion":"6.13.3","dist":{"integrity":"sha512-YanMJCtsykxVQuWiwQR531bbyPtMt/jpUKy2XcVVe/oHiDgYme0NmuEZfceLeZhFbrQtO/GS/9KvWbSfDGRblA==","shasum":"978fdd04bfeb2d3543e16696814285557c127502","tarball":"http://registry-npm.ywwl.com/normalize-scroll-left/download/normalize-scroll-left-0.2.1.tgz","fileCount":7,"unpackedSize":13148,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfVpeuCRA9TVsSAnZWagAADSsP/R+wRRKrtEqMsSPBFXny\nz1eJKc6+BlxQFymyg/gSFjDP76NMmboN/f3RckeQ1jeP5UKL2i3oRGz9A1SI\n6zMhPhVaMBzkSdJklaMXKpV9B32plrMEZkOg/1QuOEzJf3AaUPxYD8Sgo3CG\n9ifT4QjY5R038FUaO9jk4l/JITZby0wPNt1lFIVo8rQzXHpQido0y6sHzhUd\nTPRVj5G6VwFcoucP5TQNlIOVvwFfAIyqX8lqnEdyxTiqfLzrb/KRRArNTY/V\nn4x7ex+g1223xSn5ndZEkwCWh/sUPwOdowzs3QUubzf/RPTWoy/EsJ7xZc/7\nI5TcgBIXnibmg9R+5Y18t9T9z1abnD5phrF4f9yiNs7+dE0amve6iymUvvYx\njfNgCl4ejsQcP47jfZD3v06xaugtife9yuQl76mjL/t2Gco5aj+u0+nYAzl3\nXd72yKl7d0RfBx7PMUjplmI9pySS/vB/gcFeYuLq8swHKi3KOPRO+UW8GJhz\nzwIyRB8jZbJj4b1kbSoz4mdegD4nHb8mqTQOYdNksT+rWccd3lX13f8AEEd1\n0J5C/EsK5azCoXJG6OJuzgUFAc0lF8PT8QtprWfqPVB+oOdk7BOcbauLhMjP\noLtrRNlYr3bTeXCJIqKKiXNDfjI8wq/Cf2UPNn5g88R7AI/gi20B5GzGXNoe\nK1Sf\r\n=k3U3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFLeuhwWcbWWt5ibzXTVUUFMsFlgwx50OlWYhPoF0fMtAiB09DunjgyaLOli0dGEHiaWeVvQ/F59TgdTnKXQzWcxgQ=="}],"size":3815,"noattachment":false,"key":"/normalize-scroll-left/-/normalize-scroll-left-0.2.1.tgz"},"maintainers":[{"name":"alitaheri","email":"ali.taheri.m@gmail.com"}],"_npmUser":{"name":"alitaheri","email":"ali.taheri.m@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/normalize-scroll-left_0.2.1_1599510446491_0.8244516919463856"},"_hasShrinkwrap":false,"readme":"# Normalize Scroll Left for Right-to-Left\r\n\r\nThis library normalizes the `Element.scrollLeft` property when direction is `rtl`.\r\n\r\nAll the hardwork are based on [this juqery plugin](https://github.com/othree/jquery.rtl-scroll-type)\r\nand [this stackoverflow answer](https://stackoverflow.com/a/24394376).\r\n\r\nSince `Element.scrollLeft`'s behavior with `dir=\"rtl\"` is not defined in any spec we use\r\na feature detection logic to determine the behavior of the current browser.\r\n\r\nTypes of `scrollLeft` (`scrollWidth` = 100) (Copied from \r\n[here](https://github.com/othree/jquery.rtl-scroll-type#3-types-of-scrollleft-scrollwidth--100))\r\n\r\nBrowser        | Type          | Most Left | Most Right | Initial\r\n-------------- | ------------- | --------- | ---------- | -------\r\nWebKit         | default       | 0         | 100        | 100\r\nFirefox/Opera  | negative      | -100      | 0          | 0\r\nIE/Edge        | reverse       | 100       | 0          | 0\r\n\r\n## Installation\r\n\r\nYou can install this package with the following command:\r\n\r\n```sh\r\nnpm install normalize-scroll-left\r\n```\r\n\r\n## API\r\n\r\nThis library exposes these methods:\r\n\r\n### `detectScrollType`\r\n\r\n```ts\r\ntype ScrollType = 'indeterminate' | 'default' | 'negative' | 'reverse';\r\nfunction detectScrollType(): ScrollType;\r\n```\r\n\r\nThis function returns the scroll type detected, Keep in mind, this function\r\ncaches the result as it should render a dummy on the DOM (which is expensive).\r\nMake sure the first invocation of this function happens **after** the body is loaded.\r\n\r\n**note**: To support server-side-rendering, it will output `indeterminate` if\r\nit detects a non-browser environment.\r\n\r\n```javascript\r\nimport { detectScrollType } from 'normalize-scroll-left';\r\n\r\nconst type = detectScrollType();\r\n```\r\n\r\nThe output is not based on the browser, but feature detection:\r\n\r\nBrowser        | Type\r\n-------------- | -------------\r\nWebKit         | `default`\r\nFirefox/Opera  | `negative`\r\nIE/Edge        | `reverse`\r\nOther/Server   | `indeterminate`\r\n\r\n### `getNormalizedScrollLeft`\r\n\r\n```ts\r\nfunction getNormalizedScrollLeft(element: HTMLElement, direction: 'rtl' | 'ltr'): number;\r\n```\r\n\r\nYou can use this method to get the normalized `scrollLeft` property of an element.\r\nYou should explicitly pass the direction for the following reasons:\r\n\r\n1. Querying the `getComputedStyle` is expensive and might cause a reflow.\r\n2. The behavior shouldn't be changed when direction is `ltr`.\r\n\r\nThe output is `NaN` on the server. Otherwise, it will mimic the behavior of\r\n`WebKit` as it's the esiest to work with.\r\n\r\n```ts\r\nimport { getNormalizedScrollLeft } from 'normalize-scroll-left';\r\n\r\nconst element = document.getElementById('my-scrollable-container');\r\n\r\n// element.scrollWidth = 100;\r\n\r\nconst scrollLeft = getNormalizedScrollLeft(element, 'rtl');\r\n\r\n// scrollLeft will always be from 0 (Most Left) to 100 (Most Right).\r\n// It will initially be 100, That means the most right.\r\n```\r\n\r\n### `setNormalizedScrollLeft`\r\n\r\n```ts\r\nfunction setNormalizedScrollLeft(\r\n  element: HTMLElement,\r\n  scrollLeft: number,\r\n  direction: 'rtl' | 'ltr',\r\n): void;\r\n```\r\n\r\nYou can use this method to set the `scrollLeft` property of an element as normalized.\r\nYou should explicitly pass the direction for the same reasons as `getNormalizedScrollLeft`:\r\n\r\nFor `scrollWidth = 100` the argument `scrollLeft` must be between `0` and `100`. This\r\nfunction will automatically convert it into something the current browser understands.\r\n\r\n```ts\r\nimport { setNormalizedScrollLeft } from 'normalize-scroll-left';\r\n\r\nconst element = document.getElementById('my-scrollable-container');\r\n\r\n// element.scrollWidth = 100, element.clientWidth = 20;\r\n\r\nsetNormalizedScrollLeft(element, 20, 'rtl');\r\n\r\n// Will set element.scrollLeft to ...\r\n//  20 in WebKit (chrome)\r\n//  -60 in Firefox/Opera\r\n//  60 in IE/Edge\r\n// Does nothing on the server\r\n```\r\n\r\n## Typings\r\n\r\nThe typescript type definitions are also available and are installed via npm.\r\n\r\n## License\r\nThis project is licensed under the\r\n[MIT license](https://github.com/alitaheri/normalize-scroll-left/blob/master/LICENSE).","publish_time":1599510446608,"_cnpm_publish_time":1599510446608,"dist-tags":{"latest":"0.2.1"}}