{"name":"normalize-scroll-left","description":"Utility library to determine and normalize Element.scrollLeft behavior","version":"0.1.2","author":{"name":"Ali Taheri Moghaddar","email":"ali.taheri.m@gmail.com"},"files":["lib"],"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 lib && tsc","prepublishOnly":"npm run build","lint":"tslint -e \"node_modules/**\" \"src/**/*.ts\"","test":"mocha --compilers ts:ts-node/register \"src/**/*.spec.ts\""},"license":"MIT","main":"lib/main.js","types":"lib/main.d.ts","devDependencies":{"@types/chai":"^4.0.4","@types/mocha":"^2.2.43","@types/node":"^8.0.34","chai":"^4.1.2","mocha":"^4.0.1","rimraf":"^2.6.2","ts-loader":"^2.3.7","ts-node":"^3.3.0","tslint":"^5.7.0","tslint-eslint-rules":"^4.1.1","tslint-microsoft-contrib":"^5.0.1","typescript":"^2.5.3"},"gitHead":"bdc4ac297fdf1cd4920998456cd09f9dc0293e71","bugs":{"url":"https://github.com/alitaheri/normalize-scroll-left/issues"},"homepage":"https://github.com/alitaheri/normalize-scroll-left#readme","_id":"normalize-scroll-left@0.1.2","_npmVersion":"5.4.2","_nodeVersion":"8.6.0","_npmUser":{"name":"alitaheri","email":"ali.taheri.m@gmail.com"},"dist":{"integrity":"sha512-F9YMRls0zCF6BFIE2YnXDRpHPpfd91nOIaNdDgrx5YMoPLo8Wqj+6jNXHQsYBavJeXP4ww8HCt0xQAKc5qk2Fg==","shasum":"6b79691ba79eb5fb107fa5edfbdc06b55caee2aa","tarball":"http://registry-npm.ywwl.com/normalize-scroll-left/download/normalize-scroll-left-0.1.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDMHmbup/gNiqTGbRVaJFNWWoA/QsgWM107YF1lniUmLwIhAPrGdNTUL759U3j5AvsdaD/az9yI4eP82FQRdAjwijtu"}],"size":3655,"noattachment":false,"key":"/normalize-scroll-left/-/normalize-scroll-left-0.1.2.tgz"},"maintainers":[{"name":"alitaheri","email":"ali.taheri.m@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/normalize-scroll-left-0.1.2.tgz_1507887793335_0.37238744203932583"},"directories":{},"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":1507887794208,"_cnpm_publish_time":1507887794208,"dist-tags":{"latest":"0.2.1"}}