{"name":"normalize-scroll-left","description":"Utility library to determine and normalize Element.scrollLeft behavior","version":"0.2.0","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.1.7","@types/mocha":"^5.2.7","@types/node":"^12.0.4","chai":"^4.2.0","mocha":"^6.1.4","rimraf":"^2.6.3","ts-loader":"^6.0.2","ts-node":"^8.2.0","tslint":"^5.17.0","tslint-eslint-rules":"^5.4.0","tslint-microsoft-contrib":"^6.2.0","typescript":"^3.5.1"},"gitHead":"2120cf215d146cd586b0a294da819642c7c977bf","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.0","_npmVersion":"6.1.0","_nodeVersion":"12.1.0","_npmUser":{"name":"alitaheri","email":"ali.taheri.m@gmail.com"},"dist":{"integrity":"sha512-t5oCENZJl8TGusJKoCJm7+asaSsPuNmK6+iEjrZ5TyBj2f02brCRsd4c83hwtu+e5d4LCSBZ0uoDlMjBo+A8yA==","shasum":"9445d74275f303cc661e113329aefa492f58114c","tarball":"http://registry-npm.ywwl.com/normalize-scroll-left/download/normalize-scroll-left-0.2.0.tgz","fileCount":7,"unpackedSize":13023,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc8ri7CRA9TVsSAnZWagAALiEQAKG7C4NpWwh/gKxxXrlZ\nn1YcHLonXRFo2yQxcxG/efBsDfuKkirNMXgitiNQRMCgkPvtx66yKqGG0i2x\nu4ewShsOoMxCHpwWDNlvyH8mbivjyvBq4FfBEQ/XJVn55VzlsuTI2yJVNtXq\ncy8cOTAFwpJAKV25K9plTb+9WBH0R8Xknub+GWse2/THwmJHjOznhyeLCJu9\ndPYy4Xs05nrAfU6StwuDroQLrxgrNflrlSuPxk8gppC8CALpd4hqfYxPMWSp\n8mS7W4fCDdL42NGpTNR+XmeGnaAPsRahVwHO4uCxwEVBWH7UnU+7insmsvfs\neqevv2NHISe05l5egNZZmlxhWVQdNxswzZ8br5ReOauOMZ5ph5rDFYtFWjNz\nLKt1rlsLhMdWz9ekm81VOndUwlGsEPPP0rEZB34/hL0fVRgHiMMGVPBVKrnO\nmhS0LmYcE3ydHZ8DEZ+opMUuPlY33TwI32ZDmQh6gHFBx3Hhhgjpu6kRQ3aQ\nOrnh4iwTYzX/LzkXvdm3eMgOfBgqSVIisAmdHvjjAxsz8SKUCDMFxGPjXzw+\nXcSxHwnUX9BmdsCW8ADf9goiFjxSp6CXpUfKtUCzc7PS/Ygig3rPo7dfHS+z\nK65rQY1WAJPHNka1pP7sMztvd/RkPqXlF34DKadq4175eaDwny17Y9AaAjp0\n75Y6\r\n=DNZP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnLJo8kFrORW7w63EL5BRgEMaxRSAtioPAFLjlqhrGqgIgDLw3MPOP/13jPLurnGObKxqRq/H0B0rqor9BLeoQ3d4="}],"size":3778,"noattachment":false,"key":"/normalize-scroll-left/-/normalize-scroll-left-0.2.0.tgz"},"maintainers":[{"name":"alitaheri","email":"ali.taheri.m@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/normalize-scroll-left_0.2.0_1559410875018_0.8373502041912004"},"_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":1559410875121,"_cnpm_publish_time":1559410875121,"dist-tags":{"latest":"0.2.1"}}