add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
# See editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

View File

@@ -0,0 +1,27 @@
{
"extends": ["airbnb-base", "prettier"],
"env": {
"browser": true,
"es6": true
},
"rules": {
"import/no-cycle": 1,
"no-const-assign": 1,
"no-shadow": 0,
"no-this-before-super": 1,
"no-undef": 1,
"no-unreachable": 1,
"no-unused-vars": 1,
"constructor-super": 1,
"valid-typeof": 1,
"indent": [2, 4, { "SwitchCase": 1 }],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"eqeqeq": [2, "always"],
"one-var": [2, "never"],
"comma-dangle": [2, "always-multiline"],
"spaced-comment": [2, "always"],
"no-restricted-globals": 2,
"no-param-reassign": [2, { "props": false }]
}
}

View File

@@ -0,0 +1,30 @@
{
"parser": "babel-eslint",
"extends": ["airbnb-base", "prettier"],
"env": {
"browser": true,
"es6": true
},
"rules": {
"no-const-assign": 1,
"no-shadow": 0,
"no-this-before-super": 1,
"no-undef": 1,
"no-unreachable": 1,
"no-unused-vars": 1,
"constructor-super": 1,
"valid-typeof": 1,
"indent": [2, 4, { "SwitchCase": 1 }],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"eqeqeq": [2, "always"],
"one-var": [2, "never"],
"comma-dangle": [2, "always-multiline"],
"spaced-comment": [2, "always"],
"no-restricted-globals": 2,
"no-param-reassign": [2, { "props": false }]
},
"parserOptions": {
"sourceType": "module"
}
}

View File

@@ -0,0 +1,7 @@
{
"useTabs": false,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
}

View File

@@ -0,0 +1,11 @@
{
"extends": ["stylelint-config-recommended", "stylelint-config-prettier"],
"rules": {
"selector-class-pattern": null,
"selector-no-qualifying-type": [true, { "ignore": ["attribute", "class"] }],
"string-no-newline": null,
"indentation": 4,
"string-quotes": "single",
"max-nesting-depth": 2
}
}

View File

@@ -0,0 +1,12 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
"dbaeumer.vscode-eslint",
"wix.vscode-import-cost",
"esbenp.prettier-vscode",
"shinnn.stylelint",
"wayou.vscode-todo-highlight"
]
}

View File

@@ -0,0 +1,16 @@
{
// Exclude from search
"search.exclude": {
"dist/": true
},
// Formatting
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
// Prettier settings
"prettier.tabWidth": 4,
"prettier.eslintIntegration": true,
"prettier.printWidth": 120
}

View File

@@ -0,0 +1,20 @@
{
"js": {
"rangetouch.js": {
"src": "./src/js/rangetouch.js",
"dist": "./dist/",
"formats": ["es", "umd"]
},
"docs.js": {
"src": "./docs/src/js/docs.js",
"dist": "./docs/dist/",
"formats": ["iife"]
}
},
"css": {
"docs.css": {
"src": "./docs/src/less/docs.less",
"dist": "./docs/dist/"
}
}
}

View File

@@ -0,0 +1,73 @@
# Changelog
## v2.0.0
- Rewritten using ES6 syntax and a proper `RangeTouch` class
- No longer using event delegation do to compatibility issues
## v1.0.6
- Fixed issue with stylesheet re-use
## v1.0.5
- Fixed issue with variable naming
## v1.0.4
- Fixed bug introduced in v1.0.3 with selector for disabled elements
- No long require the upfront check for elements on the page given we just listen to events
## v1.0.3
- Fixed error if no `<input type="range">` found
- CustomEvent polyfill no longer effects the global scope
- AddCSS option to set whether to add helpful CSS to the page
## v1.0.2
- More clean up
## v1.0.1
- Clean up
## v1.0.0
- Repo move and release
## v0.0.9
- Added disabled selector
## v0.0.8
- Bug fix for zoomed input
## v0.0.7
- Triggering `input` and `change` events
## v0.0.6
- Bug fix for min attrubute
## v0.0.5
- Bug fix for breaking other touches
## v0.0.4
- Bug fix for thumb width offset
## v0.0.3
- Microsoft Edge fixes and improvements to touch area
## v0.0.2
- Version bump for bower
## v0.0.1
- Initial release

View File

@@ -0,0 +1,12 @@
{
"cdn": {
"bucket": "cdn-rangetouch",
"domain": "cdn.rangetouch.com",
"region": "us-east-1"
},
"docs": {
"bucket": "rangetouch.com",
"domain": "rangetouch.com",
"region": "us-east-1"
}
}

View File

@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("RangeTouch",t):e.RangeTouch=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var t={addCSS:!0,thumbWidth:15,watch:!0};var n=function(e){return null!=e?e.constructor:null},r=function(e,t){return!!(e&&t&&e instanceof t)},u=function(e){return null==e},i=function(e){return n(e)===Object},o=function(e){return n(e)===String},a=function(e){return Array.isArray(e)},c=function(e){return r(e,NodeList)},l={nullOrUndefined:u,object:i,number:function(e){return n(e)===Number&&!Number.isNaN(e)},string:o,boolean:function(e){return n(e)===Boolean},function:function(e){return n(e)===Function},array:a,nodeList:c,element:function(e){return r(e,Element)},event:function(e){return r(e,Event)},empty:function(e){return u(e)||(o(e)||a(e)||c(e))&&!e.length||i(e)&&!Object.keys(e).length}};function s(e,t){if(1>t){var n=function(e){var t="".concat(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0}(t);return parseFloat(e.toFixed(n))}return Math.round(e/t)*t}return function(){function n(e,r){(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,n),l.element(e)?this.element=e:l.string(e)&&(this.element=document.querySelector(e)),l.element(this.element)&&l.empty(this.element.rangeTouch)&&(this.config=Object.assign({},t,r),this.init())}return r=n,i=[{key:"setup",value:function(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},u=null;if(l.empty(e)||l.string(e)?u=Array.from(document.querySelectorAll(l.string(e)?e:'input[type="range"]')):l.element(e)?u=[e]:l.nodeList(e)?u=Array.from(e):l.array(e)&&(u=e.filter(l.element)),l.empty(u))return null;var i=Object.assign({},t,r);l.string(e)&&i.watch&&new MutationObserver(function(t){Array.from(t).forEach(function(t){Array.from(t.addedNodes).forEach(function(t){l.element(t)&&function(e,t){return function(){return Array.from(document.querySelectorAll(t)).includes(this)}.call(e,t)}(t,e)&&new n(t,i)})})}).observe(document.body,{childList:!0,subtree:!0});return u.map(function(e){return new n(e,r)})}},{key:"enabled",get:function(){return"ontouchstart"in document.documentElement}}],(u=[{key:"init",value:function(){n.enabled&&(this.config.addCSS&&(this.element.style.userSelect="none",this.element.style.webKitUserSelect="none",this.element.style.touchAction="manipulation"),this.listeners(!0),this.element.rangeTouch=this)}},{key:"destroy",value:function(){n.enabled&&(this.listeners(!1),this.element.rangeTouch=null)}},{key:"listeners",value:function(e){var t=this,n=e?"addEventListener":"removeEventListener";["touchstart","touchmove","touchend"].forEach(function(e){t.element[n](e,function(e){return t.set(e)},!1)})}},{key:"get",value:function(e){if(!n.enabled||!l.event(e))return null;var t,r=e.target,u=e.changedTouches[0],i=parseFloat(r.getAttribute("min"))||0,o=parseFloat(r.getAttribute("max"))||100,a=parseFloat(r.getAttribute("step"))||1,c=r.getBoundingClientRect(),f=100/c.width*(this.config.thumbWidth/2)/100;return 0>(t=100/c.width*(u.clientX-c.left))?t=0:100<t&&(t=100),50>t?t-=(100-2*t)*f:50<t&&(t+=2*(t-50)*f),i+s(t/100*(o-i),a)}},{key:"set",value:function(e){n.enabled&&l.event(e)&&!e.target.disabled&&(e.preventDefault(),e.target.value=this.get(e),function(e,t){if(e&&t){var n=new Event(t);e.dispatchEvent(n)}}(e.target,"touchend"===e.type?"change":"input"))}}])&&e(r.prototype,u),i&&e(r,i),n;var r,u,i}()});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}var defaults={addCSS:!0,thumbWidth:15,watch:!0};function matches(e,t){return function(){return Array.from(document.querySelectorAll(t)).includes(this)}.call(e,t)}function trigger(e,t){if(e&&t){var n=new Event(t);e.dispatchEvent(n)}}var getConstructor=function(e){return null!=e?e.constructor:null},instanceOf=function(e,t){return!!(e&&t&&e instanceof t)},isNullOrUndefined=function(e){return null==e},isObject=function(e){return getConstructor(e)===Object},isNumber=function(e){return getConstructor(e)===Number&&!Number.isNaN(e)},isString=function(e){return getConstructor(e)===String},isBoolean=function(e){return getConstructor(e)===Boolean},isFunction=function(e){return getConstructor(e)===Function},isArray=function(e){return Array.isArray(e)},isNodeList=function(e){return instanceOf(e,NodeList)},isElement=function(e){return instanceOf(e,Element)},isEvent=function(e){return instanceOf(e,Event)},isEmpty=function(e){return isNullOrUndefined(e)||(isString(e)||isArray(e)||isNodeList(e))&&!e.length||isObject(e)&&!Object.keys(e).length},is={nullOrUndefined:isNullOrUndefined,object:isObject,number:isNumber,string:isString,boolean:isBoolean,function:isFunction,array:isArray,nodeList:isNodeList,element:isElement,event:isEvent,empty:isEmpty};function getDecimalPlaces(e){var t="".concat(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0}function round(e,t){if(1>t){var n=getDecimalPlaces(t);return parseFloat(e.toFixed(n))}return Math.round(e/t)*t}var RangeTouch=function(){function e(t,n){_classCallCheck(this,e),is.element(t)?this.element=t:is.string(t)&&(this.element=document.querySelector(t)),is.element(this.element)&&is.empty(this.element.rangeTouch)&&(this.config=Object.assign({},defaults,n),this.init())}return _createClass(e,[{key:"init",value:function(){e.enabled&&(this.config.addCSS&&(this.element.style.userSelect="none",this.element.style.webKitUserSelect="none",this.element.style.touchAction="manipulation"),this.listeners(!0),this.element.rangeTouch=this)}},{key:"destroy",value:function(){e.enabled&&(this.listeners(!1),this.element.rangeTouch=null)}},{key:"listeners",value:function(e){var t=this,n=e?"addEventListener":"removeEventListener";["touchstart","touchmove","touchend"].forEach(function(e){t.element[n](e,function(e){return t.set(e)},!1)})}},{key:"get",value:function(t){if(!e.enabled||!is.event(t))return null;var n,r=t.target,i=t.changedTouches[0],s=parseFloat(r.getAttribute("min"))||0,u=parseFloat(r.getAttribute("max"))||100,o=parseFloat(r.getAttribute("step"))||1,a=r.getBoundingClientRect(),c=100/a.width*(this.config.thumbWidth/2)/100;return 0>(n=100/a.width*(i.clientX-a.left))?n=0:100<n&&(n=100),50>n?n-=(100-2*n)*c:50<n&&(n+=2*(n-50)*c),s+round(n/100*(u-s),o)}},{key:"set",value:function(t){e.enabled&&is.event(t)&&!t.target.disabled&&(t.preventDefault(),t.target.value=this.get(t),trigger(t.target,"touchend"===t.type?"change":"input"))}}],[{key:"setup",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=null;if(is.empty(t)||is.string(t)?r=Array.from(document.querySelectorAll(is.string(t)?t:'input[type="range"]')):is.element(t)?r=[t]:is.nodeList(t)?r=Array.from(t):is.array(t)&&(r=t.filter(is.element)),is.empty(r))return null;var i=Object.assign({},defaults,n);is.string(t)&&i.watch&&new MutationObserver(function(n){Array.from(n).forEach(function(n){Array.from(n.addedNodes).forEach(function(n){is.element(n)&&matches(n,t)&&new e(n,i)})})}).observe(document.body,{childList:!0,subtree:!0});return r.map(function(t){return new e(t,n)})}},{key:"enabled",get:function(){return"ontouchstart"in document.documentElement}}]),e}();export default RangeTouch;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
!function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var t={addCSS:!0,thumbWidth:15,watch:!0};var n=function(e){return null!=e?e.constructor:null},r=function(e,t){return!!(e&&t&&e instanceof t)},i=function(e){return null==e},u=function(e){return n(e)===Object},o=function(e){return n(e)===String},a=function(e){return Array.isArray(e)},c=function(e){return r(e,NodeList)},l={nullOrUndefined:i,object:u,number:function(e){return n(e)===Number&&!Number.isNaN(e)},string:o,boolean:function(e){return n(e)===Boolean},function:function(e){return n(e)===Function},array:a,nodeList:c,element:function(e){return r(e,Element)},event:function(e){return r(e,Event)},empty:function(e){return i(e)||(o(e)||a(e)||c(e))&&!e.length||u(e)&&!Object.keys(e).length}};function s(e,t){if(1>t){var n=function(e){var t="".concat(e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0}(t);return parseFloat(e.toFixed(n))}return Math.round(e/t)*t}var f=function(){function n(e,r){(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")})(this,n),l.element(e)?this.element=e:l.string(e)&&(this.element=document.querySelector(e)),l.element(this.element)&&l.empty(this.element.rangeTouch)&&(this.config=Object.assign({},t,r),this.init())}return r=n,u=[{key:"setup",value:function(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=null;if(l.empty(e)||l.string(e)?i=Array.from(document.querySelectorAll(l.string(e)?e:'input[type="range"]')):l.element(e)?i=[e]:l.nodeList(e)?i=Array.from(e):l.array(e)&&(i=e.filter(l.element)),l.empty(i))return null;var u=Object.assign({},t,r);l.string(e)&&u.watch&&new MutationObserver(function(t){Array.from(t).forEach(function(t){Array.from(t.addedNodes).forEach(function(t){l.element(t)&&function(e,t){return function(){return Array.from(document.querySelectorAll(t)).includes(this)}.call(e,t)}(t,e)&&new n(t,u)})})}).observe(document.body,{childList:!0,subtree:!0});return i.map(function(e){return new n(e,r)})}},{key:"enabled",get:function(){return"ontouchstart"in document.documentElement}}],(i=[{key:"init",value:function(){n.enabled&&(this.config.addCSS&&(this.element.style.userSelect="none",this.element.style.webKitUserSelect="none",this.element.style.touchAction="manipulation"),this.listeners(!0),this.element.rangeTouch=this)}},{key:"destroy",value:function(){n.enabled&&(this.listeners(!1),this.element.rangeTouch=null)}},{key:"listeners",value:function(e){var t=this,n=e?"addEventListener":"removeEventListener";["touchstart","touchmove","touchend"].forEach(function(e){t.element[n](e,function(e){return t.set(e)},!1)})}},{key:"get",value:function(e){if(!n.enabled||!l.event(e))return null;var t,r=e.target,i=e.changedTouches[0],u=parseFloat(r.getAttribute("min"))||0,o=parseFloat(r.getAttribute("max"))||100,a=parseFloat(r.getAttribute("step"))||1,c=r.getBoundingClientRect(),f=100/c.width*(this.config.thumbWidth/2)/100;return 0>(t=100/c.width*(i.clientX-c.left))?t=0:100<t&&(t=100),50>t?t-=(100-2*t)*f:50<t&&(t+=2*(t-50)*f),u+s(t/100*(o-u),a)}},{key:"set",value:function(e){n.enabled&&l.event(e)&&!e.target.disabled&&(e.preventDefault(),e.target.value=this.get(e),function(e,t){if(e&&t){var n=new Event(t);e.dispatchEvent(n)}}(e.target,"touchend"===e.type?"change":"input"))}}])&&e(r.prototype,i),u&&e(r,u),n;var r,i,u}(),d=function(e){var t=new XMLHttpRequest,n=document.body;"withCredentials"in t&&(t.open("GET",e,!0),t.onload=function(){var e=document.createElement("div");e.setAttribute("hidden",""),e.innerHTML=t.responseText,n.insertBefore(e,n.childNodes[0])},t.send())};document.addEventListener("DOMContentLoaded",function(){["dist/docs.svg"].forEach(d),window.shr.setup({count:{classname:"btn__count"}}),f.setup(".js-example",{thumbWidth:20})})}();

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><symbol id="icon-github"><path fill-rule="evenodd" clip-rule="evenodd" d="M8 .2c-4.4 0-8 3.6-8 8 0 3.5 2.3 6.5 5.5 7.6.4.1.5-.2.5-.4V14c-2.2.5-2.7-1-2.7-1-.4-.9-.9-1.2-.9-1.2-.7-.5.1-.5.1-.5.8.1 1.2.8 1.2.8.7 1.3 1.9.9 2.3.7.1-.5.3-.9.5-1.1-1.8-.2-3.6-.9-3.6-4 0-.9.3-1.6.8-2.1-.1-.2-.4-1 .1-2.1 0 0 .7-.2 2.2.8.6-.2 1.3-.3 2-.3s1.4.1 2 .3c1.5-1 2.2-.8 2.2-.8.4 1.1.2 1.9.1 2.1.5.6.8 1.3.8 2.1 0 3.1-1.9 3.7-3.7 3.9.3.4.6.9.6 1.6v2.2c0 .2.1.5.6.4 3.2-1.1 5.5-4.1 5.5-7.6-.1-4.4-3.7-8-8.1-8z"/></symbol><symbol id="icon-twitter"><path d="M16 3c-.6.3-1.2.4-1.9.5.7-.4 1.2-1 1.4-1.8-.6.4-1.3.6-2.1.8-.6-.6-1.5-1-2.4-1-1.7 0-3.2 1.5-3.2 3.3 0 .3 0 .5.1.7-2.7-.1-5.2-1.4-6.8-3.4-.3.5-.4 1-.4 1.7 0 1.1.6 2.1 1.5 2.7-.5 0-1-.2-1.5-.4C.7 7.7 1.8 9 3.3 9.3c-.3.1-.6.1-.9.1-.2 0-.4 0-.6-.1.4 1.3 1.6 2.3 3.1 2.3-1.1.9-2.5 1.4-4.1 1.4H0c1.5.9 3.2 1.5 5 1.5 6 0 9.3-5 9.3-9.3v-.4C15 4.3 15.6 3.7 16 3z"/></symbol></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en" class="error">
<head>
<meta charset="utf-8" />
<title>Doh. Looks like something went wrong.</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Docs styles -->
<link rel="stylesheet" href="dist/docs.css">
</head>
<body>
<main>
<h1>Doh.</h1>
<p>Looks like something went wrong.</p>
<a href="http://plyr.io" class="btn btn--primary">Back to plyr.io</a>
</main>
</body>
</html>

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>RangeTouch - A super tiny library to make range sliders work better on touch devices</title>
<meta name="description" content="A super tiny library to make range sliders work better on touch devices" />
<meta name="author" content="Sam Potts" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="dist/docs.css" />
<script>
(function() {
try {
document.documentElement.classList.add(
'ontouchstart' in document.documentElement ? 'touch' : 'no-touch',
);
} catch (e) {}
})();
</script>
</head>
<body>
<main>
<header>
<h1>RangeTouch</h1>
<p>
A super tiny library to make <code>&lt;input type='range'&gt;</code> sliders work better on touch
devices
</p>
</header>
<div class="alert hidden-touch" role="alert">
Open this page on a touch device to see the difference with and without RangeTouch.
</div>
<div class="section example hidden-no-touch">
<label for="example1" class="color-bad">Default <span class="sr-only">example slider</span></label>
<input type="range" id="example1" />
</div>
<div class="section example hidden-no-touch">
<label for="example0" class="color-good">RangeTouch <span class="sr-only">example slider</span></label>
<input type="range" id="example0" class="js-example" />
</div>
<div class="action">
<a
href="https://github.com/sampotts/rangetouch"
target="_blank"
class="btn btn--primary"
data-shr-network="github"
>
<svg class="icon">
<use xlink:href="#icon-github"></use>
</svg>
Download on GitHub
</a>
</div>
</main>
<footer>
<svg class="icon color--twitter">
<use xlink:href="#icon-twitter" />
</svg>
If you like RangeTouch,
<a
href="https://twitter.com/intent/tweet?text=RangeTouch+-+a+super+tiny+library+to+make+input+type=range+sliders+work+better+on+touch+devices&url=http%3A%2F%2Frangetouch.com&via=Sam_Potts"
target="_blank"
data-shr-network="twitter"
>tweet it</a
>
</footer>
<!-- Shr -->
<script src="https://cdn.shr.one/1.0.1/shr.js"></script>
<!-- Docs script -->
<script src="dist/docs.js"></script>
</body>
</html>

View File

@@ -0,0 +1,44 @@
// ==========================================================================
// Docs example
// ==========================================================================
import RangeTouch from '../../../src/js/rangetouch';
const loadSprite = url => {
const xhr = new XMLHttpRequest();
const { body } = document;
// Check for CORS support
// If you're loading from same domain, you can remove the whole if/else statement
// XHR for Chrome/Firefox/Opera/Safari/IE10+
if (!('withCredentials' in xhr)) {
return;
}
xhr.open('GET', url, true);
// Inject hidden div with sprite on load
xhr.onload = () => {
const container = document.createElement('div');
container.setAttribute('hidden', '');
container.innerHTML = xhr.responseText;
body.insertBefore(container, body.childNodes[0]);
};
xhr.send();
};
document.addEventListener('DOMContentLoaded', () => {
// Load the sprite
['dist/docs.svg'].forEach(loadSprite);
// Setup shr
window.shr.setup({
count: {
classname: 'btn__count',
},
});
// Set range thumb size
RangeTouch.setup('.js-example', { thumbWidth: 20 });
});

View File

@@ -0,0 +1,10 @@
// ==========================================================================
// Alerts
// ==========================================================================
.alert {
padding: (@padding-base / 2) (@padding-base * .75);
background: @orange;
border-radius: @border-radius-base;
color: #fff;
}

View File

@@ -0,0 +1,78 @@
// ==========================================================================
// Base layout
// ==========================================================================
// BORDER-BOX ALL THE THINGS!
// http://paulirish.com/2012/box-sizing-border-box-ftw/
*,
*::after,
*::before {
box-sizing: border-box;
}
// Hidden
[hidden] {
display: none;
}
// Base
html {
height: 100%;
font-size: 100%;
}
body {
padding: (@padding-base * 1.5) (@padding-base / 2) (@padding-base * 3);
background: @body-background;
font-family: @font-stack;
line-height: 1.5;
text-align: center;
color: @text-color;
.font-smoothing(on);
.font-size();
font-weight: @font-weight-medium;
text-shadow: 0 1px 1px fade(#000, 10%);
@media only screen and (min-width: @screen-sm) {
display: flex;
height: 100%;
align-items: center;
padding-top: (@padding-base * 3);
}
}
.section,
.action {
margin-top: @padding-base;
}
.section + .section {
margin-top: (@padding-base / 2);
}
// Header
header p {
.font-size(@font-size-large);
}
// Main container
main {
max-width: 400px;
margin: 0 auto;
animation: fade-in 0.2s ease;
}
// Alert
footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
padding: (@padding-base / 2);
background: fade(#fff, 95%);
color: @gray;
text-shadow: none;
animation: fade-in-up 0.2s ease;
.icon {
margin-right: ceil(@padding-base / 3);
}
}

View File

@@ -0,0 +1,79 @@
// ==========================================================================
// Buttons
// ==========================================================================
// Shared
.btn,
.btn__count {
display: inline-block;
vertical-align: middle;
border-radius: @border-radius-base;
font-weight: @font-weight-bold;
user-select: none;
}
// Buttons
.btn {
padding: (@padding-base / 2);
background: #fff;
border: 0;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
.font-size();
color: @gray;
text-shadow: none;
white-space: nowrap;
&:hover,
&:focus {
background: fade(#fff, 95%);
color: @gray-dark;
}
&:focus {
.tab-focus();
}
&:active {
transform: scale(0.97);
}
}
.btn--twitter .icon {
color: @color-twitter;
}
// Count bubble
.btn__count {
position: relative;
margin-left: (@padding-base / 3);
padding: (@padding-base / 2) (@padding-base * 0.4);
min-width: (@padding-base * 1.75);
background: #fff;
text-shadow: none;
color: @gray;
font-weight: @font-weight-medium;
&::before {
content: '';
position: absolute;
display: block;
width: @arrow-size;
height: @arrow-size;
left: 2px;
top: 50%;
margin-top: -(@arrow-size / 2);
background: inherit;
transform: rotate(-45deg) translate(-50%, -50%);
}
}
.action {
display: flex;
.btn {
flex: 1;
}
.btn__count {
flex-shrink: 0;
}
}

View File

@@ -0,0 +1,16 @@
// ==========================================================================
// Examples
// ==========================================================================
.example {
position: relative;
text-align: left;
label {
display: inline-block;
margin-bottom: (@padding-base / 3);
.font-size(12);
font-weight: @font-weight-bold;
text-transform: uppercase;
}
}

View File

@@ -0,0 +1,22 @@
// ==========================================================================
// Icons
// ==========================================================================
// Base size icon styles
.icon {
fill: currentColor;
width: @icon-size;
height: @icon-size;
vertical-align: -3px;
}
// Within elements
a svg,
button svg,
label svg {
pointer-events: none;
}
a .icon,
.btn .icon {
margin-right: (@padding-base / 3);
}

View File

@@ -0,0 +1,82 @@
// ==========================================================================
// <input type="range">
// ==========================================================================
// Mixins for components
.range-thumb() {
position: relative;
height: @range-thumb-height;
width: @range-thumb-width;
background: @range-thumb-bg;
border: @range-thumb-border;
border-radius: 100%;
transition: background 0.3s ease;
box-shadow: 0 1px 2px fade(@gray-dark, 40%);
box-sizing: border-box;
}
.range-track() {
height: @range-track-height;
background: @range-track-bg;
border: 0;
border-radius: (@range-track-height / 2);
user-select: none;
}
input[type='range'] {
display: block;
height: @range-thumb-height;
width: 100%;
margin: 0;
padding: 0;
appearance: none;
cursor: pointer;
border: none;
background: transparent;
// Webkit
&::-webkit-slider-runnable-track {
.range-track();
}
&::-webkit-slider-thumb {
-webkit-appearance: none;
margin-top: -((@range-thumb-height - @range-track-height) / 2);
.range-thumb();
}
// Mozilla
&::-moz-range-track {
.range-track();
}
&::-moz-range-thumb {
.range-thumb();
}
&::-moz-focus-outer {
border: 0;
}
// Microsoft
&::-ms-track {
height: @range-track-height;
background: transparent;
border: 0;
color: transparent;
}
&::-ms-fill-lower,
&::-ms-fill-upper {
.range-track();
}
&::-ms-thumb {
.range-thumb();
// For some reason, Edge uses the -webkit margin above
margin-top: 0;
}
&::-ms-tooltip {
display: none;
}
&:focus {
.tab-focus();
}
}

View File

@@ -0,0 +1,59 @@
// ==========================================================================
// Typography
// ==========================================================================
// Headings
h1,
h2 {
letter-spacing: -.025em;
color: inherit;
margin: 0 0 (@padding-base / 2);
line-height: 1.2;
.font-smoothing();
}
h1 {
.font-size(@font-size-h1);
}
// Paragraph and small
p,
small {
margin: 0 0 @padding-base;
}
small {
display: block;
padding: 0 (@padding-base / 2);
.font-size(@font-size-small);
}
// Lists
ul,
li {
list-style: none;
margin: 0;
padding: 0;
}
// Links
a {
text-decoration: none;
color: @link-color;
border-bottom: 1px dotted currentColor;
transition: background .3s ease, color .3s ease, border .3s ease;
&:hover,
&:focus {
color: @link-color-hover;
border-bottom-color: rgba(0,0,0,0);
}
&:focus {
.tab-focus();
}
&.logo {
border: 0;
}
}
.color--twitter {
color: @color-twitter;
}

View File

@@ -0,0 +1,30 @@
// ==========================================================================
// HTML5 Video Player Demo Page
// ==========================================================================
// CSS Reset
@import "lib/normalize.less";
// Mixins
@import "lib/mixins.less";
// Variables
@import "variables.less";
// Libs
@import "lib/animation.less";
@import "lib/fontface.less";
// Type
@import "components/type.less";
// Components
@import "components/base.less";
@import "components/alerts.less";
@import "components/icons.less";
@import "components/buttons.less";
@import "components/range.less";
@import "components/examples.less";
// Helpers
@import "lib/helpers.less";

View File

@@ -0,0 +1,14 @@
// ==========================================================================
// Animations
// ==========================================================================
// Fade
@keyframes fade-in {
0% { opacity: 0 }
100% { opacity: 1 }
}
@keyframes fade-in-up {
0% { opacity: 0; transform: translateY(100%); }
100% { opacity: 1; transform: translateY(0); }
}

View File

@@ -0,0 +1,44 @@
@font-face {
font-display: swap;
font-family: 'Gordita';
font-style: normal;
font-weight: @font-weight-light;
src: url('https://cdn.plyr.io/static/fonts/gordita-light.woff2') format('woff2'),
url('https://cdn.plyr.io/static/fonts/gordita-light.woff') format('woff');
}
@font-face {
font-display: swap;
font-family: 'Gordita';
font-style: normal;
font-weight: @font-weight-regular;
src: url('https://cdn.plyr.io/static/fonts/gordita-regular.woff2') format('woff2'),
url('https://cdn.plyr.io/static/fonts/gordita-regular.woff') format('woff');
}
@font-face {
font-display: swap;
font-family: 'Gordita';
font-style: normal;
font-weight: @font-weight-medium;
src: url('https://cdn.plyr.io/static/fonts/gordita-medium.woff2') format('woff2'),
url('https://cdn.plyr.io/static/fonts/gordita-medium.woff') format('woff');
}
@font-face {
font-display: swap;
font-family: 'Gordita';
font-style: normal;
font-weight: @font-weight-bold;
src: url('https://cdn.plyr.io/static/fonts/gordita-bold.woff2') format('woff2'),
url('https://cdn.plyr.io/static/fonts/gordita-bold.woff') format('woff');
}
@font-face {
font-display: swap;
font-family: 'Gordita';
font-style: normal;
font-weight: @font-weight-black;
src: url('https://cdn.plyr.io/static/fonts/gordita-black.woff2') format('woff2'),
url('https://cdn.plyr.io/static/fonts/gordita-black.woff') format('woff');
}

View File

@@ -0,0 +1,27 @@
// ==========================================================================
// Helpers
// ==========================================================================
// Hide only visually, but have it available for screen readers: h5bp.com/v
// -----------------------------------------------
.sr-only {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
// Hidden attribute
[hidden] {
display: none !important;
}
// Hide/show based on touch support
.no-touch .hidden-no-touch,
.touch .hidden-touch {
display: none;
}

View File

@@ -0,0 +1,46 @@
// ==========================================================================
// Mixins
// ==========================================================================
// Contain floats: nicolasgallagher.com/micro-clearfix-hack/
// ---------------------------------------
.clearfix() {
zoom: 1;
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
}
}
// Webkit-style focus
// ---------------------------------------
.tab-focus() {
// Default
outline: thin dotted @focus-outline-color;
// Webkit
outline-offset: 1px;
}
// Use rems for font sizing
// Leave <body> at 100%/16px
// ---------------------------------------
.font-size(@font-size: @font-size-base) {
@rem: round((@font-size / 16), 3);
// font-size: (@font-size * 1px);
font-size: ~'@{rem}rem';
}
// Font smoothing
// ---------------------------------------
.font-smoothing(@mode: on) when (@mode = on) {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
}
.font-smoothing(@mode: on) when (@mode = off) {
-moz-osx-font-smoothing: auto;
-webkit-font-smoothing: subpixel-antialiased;
}

View File

@@ -0,0 +1,406 @@
/*! normalize.css v2.1.3 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 8/9.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block;
}
/**
* Correct `inline-block` display not defined in IE 8/9.
*/
audio,
canvas,
video {
display: inline-block;
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address `[hidden]` styling not present in IE 8/9.
* Hide the `template` element in IE, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none;
}
/* ==========================================================================
Base
========================================================================== */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif; /* 1 */
-ms-text-size-adjust: 100%; /* 2 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/**
* Remove default margin.
*/
body {
margin: 0;
}
/* ==========================================================================
Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background: transparent;
}
/**
* Address `outline` inconsistency between Chrome and other browsers.
*/
a:focus {
outline: thin dotted;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* ==========================================================================
Typography
========================================================================== */
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/**
* Address styling not present in IE 8/9, Safari 5, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/**
* Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/**
* Address styling not present in Safari 5 and Chrome.
*/
dfn {
font-style: italic;
}
/**
* Address differences between Firefox and other browsers.
*/
hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}
/**
* Address styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000;
}
/**
* Correct font family set oddly in Safari 5 and Chrome.
*/
code,
kbd,
pre,
samp {
font-family: monospace, serif;
font-size: 1em;
}
/**
* Improve readability of pre-formatted text in all browsers.
*/
pre {
white-space: pre-wrap;
}
/**
* Set consistent quote types.
*/
q {
quotes: "\201C" "\201D" "\2018" "\2019";
}
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* ==========================================================================
Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9.
*/
img {
border: 0;
}
/**
* Correct overflow displayed oddly in IE 9.
*/
svg:not(:root) {
overflow: hidden;
}
/* ==========================================================================
Figures
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari 5.
*/
figure {
margin: 0;
}
/* ==========================================================================
Forms
========================================================================== */
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/**
* 1. Correct `color` not being inherited in IE 8/9.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}
/**
* 1. Correct font family not being inherited in all browsers.
* 2. Correct font size not being inherited in all browsers.
* 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome.
*/
button,
input,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 2 */
margin: 0; /* 3 */
}
/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
button,
input {
line-height: normal;
}
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+.
* Correct `select` style inheritance in Firefox 4+ and Opera.
*/
button,
select {
text-transform: none;
}
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default;
}
/**
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/**
* Remove inner padding and search cancel button in Safari 5 and Chrome
* on OS X.
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* Remove inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* 1. Remove default vertical scrollbar in IE 8/9.
* 2. Improve readability and alignment in all browsers.
*/
textarea {
overflow: auto; /* 1 */
vertical-align: top; /* 2 */
}
/* ==========================================================================
Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}

View File

@@ -0,0 +1,84 @@
// ==========================================================================
// Variables
// ==========================================================================
// Colors
// ---------------------------------------
@blue: #0081c5;
@green: #00bd9c;
@orange: #ff946a;
@gray-dark: #343f4a;
@gray: #4f5b60;
@gray-light: #6b7d86;
@gray-lighter: #8799a2;
@gray-lightest: #b6c5cd;
@gray-light-mega: #dbe3e8;
@off-white: #f7f8fa;
// Brands
// ---------------------------------------
@color-twitter: #4baaf4;
// Set brand colors
// ---------------------------------------
@brand-primary: @blue;
@brand-secondary: @green;
// Base
// ---------------------------------------
@body-background: linear-gradient(to left top, @brand-secondary, @brand-primary);
@text-color: #fff;
// Type
// ---------------------------------------
@font-stack: 'Gordita', 'Avenir', 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
@font-size-base: 15;
@font-size-large: ceil(@font-size-base * 1.2);
@font-size-small: ceil(@font-size-base * 0.85);
@font-size-h1: 54;
@font-weight-light: 300;
@font-weight-regular: 400;
@font-weight-medium: 500;
@font-weight-bold: 600;
@font-weight-black: 900;
@line-height: 1.5;
@line-height-computed: (@line-height * @font-size-base);
// Radii
// ---------------------------------------
@border-radius-base: 4px;
// Links
// ---------------------------------------
@link-color: @brand-primary;
@link-color-hover: @brand-secondary;
// Padding
// ---------------------------------------
@padding-base: 30px;
// Focus
// ---------------------------------------
@focus-outline-color: @gray-dark;
// Arrows
// ---------------------------------------
@arrow-size: 8px;
// Icons
// ---------------------------------------
@icon-size: 18px;
// Range
// ---------------------------------------
@range-track-height: 6px;
@range-track-bg: fade(@gray-dark, 50%);
@range-thumb-height: 20px;
@range-thumb-width: 20px;
@range-thumb-bg: @body-background;
@range-thumb-border: 3px solid #fff;
// Breakpoints
// ---------------------------------------
@screen-sm: 480px;
@screen-md: 768px;

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" d="M8,0.2c-4.4,0-8,3.6-8,8c0,3.5,2.3,6.5,5.5,7.6
C5.9,15.9,6,15.6,6,15.4c0-0.2,0-0.7,0-1.4C3.8,14.5,3.3,13,3.3,13c-0.4-0.9-0.9-1.2-0.9-1.2c-0.7-0.5,0.1-0.5,0.1-0.5
c0.8,0.1,1.2,0.8,1.2,0.8C4.4,13.4,5.6,13,6,12.8c0.1-0.5,0.3-0.9,0.5-1.1c-1.8-0.2-3.6-0.9-3.6-4c0-0.9,0.3-1.6,0.8-2.1
c-0.1-0.2-0.4-1,0.1-2.1c0,0,0.7-0.2,2.2,0.8c0.6-0.2,1.3-0.3,2-0.3c0.7,0,1.4,0.1,2,0.3c1.5-1,2.2-0.8,2.2-0.8
c0.4,1.1,0.2,1.9,0.1,2.1c0.5,0.6,0.8,1.3,0.8,2.1c0,3.1-1.9,3.7-3.7,3.9C9.7,12,10,12.5,10,13.2c0,1.1,0,1.9,0,2.2
c0,0.2,0.1,0.5,0.6,0.4c3.2-1.1,5.5-4.1,5.5-7.6C16,3.8,12.4,0.2,8,0.2z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<title>Twitter</title>
<path d="M16,3c-0.6,0.3-1.2,0.4-1.9,0.5c0.7-0.4,1.2-1,1.4-1.8c-0.6,0.4-1.3,0.6-2.1,0.8c-0.6-0.6-1.5-1-2.4-1
C9.3,1.5,7.8,3,7.8,4.8c0,0.3,0,0.5,0.1,0.7C5.2,5.4,2.7,4.1,1.1,2.1c-0.3,0.5-0.4,1-0.4,1.7c0,1.1,0.6,2.1,1.5,2.7
c-0.5,0-1-0.2-1.5-0.4c0,0,0,0,0,0c0,1.6,1.1,2.9,2.6,3.2C3,9.4,2.7,9.4,2.4,9.4c-0.2,0-0.4,0-0.6-0.1c0.4,1.3,1.6,2.3,3.1,2.3
c-1.1,0.9-2.5,1.4-4.1,1.4c-0.3,0-0.5,0-0.8,0c1.5,0.9,3.2,1.5,5,1.5c6,0,9.3-5,9.3-9.3c0-0.1,0-0.3,0-0.4C15,4.3,15.6,3.7,16,3z"/>
</svg>

After

Width:  |  Height:  |  Size: 981 B

View File

@@ -0,0 +1,316 @@
// ==========================================================================
// Gulp build script
// ==========================================================================
const path = require('path');
const gulp = require('gulp');
// CSS
const less = require('gulp-less');
const clean = require('gulp-clean-css');
const prefix = require('gulp-autoprefixer');
// JavaScript
const terser = require('gulp-terser');
const rollup = require('gulp-better-rollup');
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve');
const sourcemaps = require('gulp-sourcemaps');
// Images
const svgstore = require('gulp-svgstore');
const imagemin = require('gulp-imagemin');
// Utils
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const size = require('gulp-size');
const log = require('fancy-log');
// Deployment
const aws = require('aws-sdk');
const publish = require('gulp-awspublish');
const pkg = require('./package.json');
const bundles = require('./bundles.json');
const deploy = require('./deploy.json');
const { browserslist, version } = pkg;
// Get AWS config
Object.values(deploy).forEach(target => {
Object.assign(target, {
publisher: publish.create({
region: target.region,
params: {
Bucket: target.bucket,
},
credentials: new aws.SharedIniFileCredentials({ profile: 'rangetouch' }),
}),
});
});
const root = __dirname;
const paths = {
rangetouch: {
// Source paths
src: {
js: path.join(root, 'src/js/**/*'),
},
},
docs: {
// Source paths
src: {
less: path.join(root, 'docs/src/less/**/*'),
js: path.join(root, 'docs/src/js/**/*'),
sprite: path.join(root, 'docs/src/sprite/**/*'),
},
// Output paths
dist: path.join(root, 'docs/dist/'),
// Docs
root: path.join(root, 'docs/'),
},
upload: [path.join(root, 'dist/**'), path.join(root, 'docs/dist/**')],
};
// Task arrays
const tasks = {
less: [],
sass: [],
js: [],
sprite: [],
};
// Babel config
const babelrc = {
babelrc: false,
presets: [
'@babel/env',
[
'minify',
{
builtIns: false, // Temporary fix for https://github.com/babel/minify/issues/904
},
],
],
};
// Size plugin
const sizeOptions = { showFiles: true, gzip: true };
// JavaScript
const namespace = 'RangeTouch';
Object.entries(bundles.js).forEach(([filename, entry]) => {
entry.formats.forEach(format => {
const name = `js:${filename}:${format}`;
tasks.js.push(name);
gulp.task(name, () => {
return gulp
.src(entry.src)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(
rollup(
{
plugins: [resolve(), commonjs(), babel(babelrc)],
},
{
name: namespace,
// exports: 'named',
format,
},
),
)
.pipe(terser())
.pipe(
rename({
extname: `.${format === 'es' ? 'mjs' : 'js'}`,
}),
)
.pipe(size(sizeOptions))
.pipe(gulp.dest(entry.dist));
});
});
});
// CSS
Object.entries(bundles.css).forEach(([filename, entry]) => {
const name = `less:${filename}`;
tasks.less.push(name);
gulp.task(name, () => {
return gulp
.src(entry.src)
.pipe(less())
.pipe(
prefix(browserslist, {
cascade: false,
}),
)
.pipe(clean())
.pipe(size(sizeOptions))
.pipe(gulp.dest(entry.dist));
});
});
// SVG Sprite
const name = 'sprite';
tasks.sprite.push(name);
gulp.task(name, () => {
return gulp
.src(paths.docs.src.sprite)
.pipe(imagemin())
.pipe(svgstore())
.pipe(rename({ basename: 'docs' }))
.pipe(size(sizeOptions))
.pipe(gulp.dest(paths.docs.dist));
});
// Build all JS
gulp.task('js', gulp.parallel(...tasks.js));
// Watch for file changes
gulp.task('watch', () => {
// Core
gulp.watch(paths.rangetouch.src.js, gulp.parallel(...tasks.js));
// Docs
gulp.watch(paths.docs.src.js, gulp.parallel(...tasks.js));
gulp.watch(paths.docs.src.less, gulp.parallel(...tasks.less));
gulp.watch(paths.docs.src.sprite, gulp.parallel(...tasks.sprite));
});
// Default gulp task
gulp.task('default', gulp.parallel(...tasks.js, ...tasks.less, ...tasks.sprite, 'watch'));
// Publish a version to CDN and docs
// --------------------------------------------
// Some options
const maxAge = 31536000; // seconds 1 year
const headers = {
cdn: {
'Cache-Control': `max-age=${maxAge}`,
},
docs: {
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
},
};
const regex =
'(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
const semver = new RegExp(`v${regex}`, 'gi');
const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}`, 'gi');
const localpath = new RegExp('(../)?dist', 'gi');
// Publish version to CDN bucket
gulp.task('cdn', () => {
const { bucket, publisher } = deploy.cdn;
if (!publisher) {
throw new Error('No publisher instance. Check AWS configuration.');
}
log(`Uploading ${version} to ${bucket}`);
// Upload to CDN
return gulp
.src(paths.upload)
.pipe(
size({
showFiles: true,
gzip: true,
}),
)
.pipe(
rename(path => {
path.dirname = path.dirname.replace('.', version);
}),
)
.pipe(publisher.publish(headers.cdn))
.pipe(publish.reporter());
});
// Replace versioned files in readme.md
gulp.task('docs:readme', () => {
const { domain } = deploy.docs;
return gulp
.src([`${root}/readme.md`])
.pipe(replace(cdnpath, `${domain}/${version}`))
.pipe(gulp.dest(root));
});
// Replace versions in rangetouch.js
gulp.task('docs:src', () =>
gulp
.src(path.join(root, 'src/js/rangetouch.js'))
.pipe(replace(semver, `v${version}`))
.pipe(gulp.dest(path.join(root, 'src/js/'))),
);
// Replace versions in rangetouch.js
gulp.task('docs:svg', () => {
const { domain, publisher } = deploy.cdn;
if (!publisher) {
throw new Error('No publisher instance. Check AWS configuration.');
}
return gulp
.src(path.join(root, 'docs/dist/docs.js'))
.pipe(replace(localpath, `https://${domain}/${version}`))
.pipe(
rename(path => {
path.dirname = path.dirname.replace('.', version);
}),
)
.pipe(publisher.publish(headers.cdn))
.pipe(publish.reporter());
});
// Replace local file paths with remote paths in docs
// e.g. "../dist/rangetouch.js" to "https://cdn.rangetouch.com/x.x.x/rangetouch.js"
gulp.task('docs:paths', () => {
const { publisher } = deploy.docs;
const { domain } = deploy.cdn;
if (!publisher) {
throw new Error('No publisher instance. Check AWS configuration.');
}
return gulp
.src([`${paths.docs.root}*.html`])
.pipe(replace(localpath, `https://${domain}/${version}`))
.pipe(publisher.publish(headers.docs))
.pipe(publish.reporter());
});
// Upload error.html to cdn (as well as docs site)
gulp.task('docs:error', () => {
const { publisher } = deploy.docs;
const { domain } = deploy.cdn;
if (!publisher) {
throw new Error('No publisher instance. Check AWS configuration.');
}
return gulp
.src([`${paths.docs.root}error.html`])
.pipe(replace(localpath, `https://${domain}/${version}`))
.pipe(publisher.publish(headers.docs))
.pipe(publish.reporter());
});
// Publish to Docs bucket
gulp.task('docs', gulp.parallel('docs:readme', 'docs:src', 'docs:svg', 'docs:paths', 'docs:error'));
// Do everything
gulp.task('deploy', gulp.series(gulp.parallel(...tasks.js, ...tasks.less, ...tasks.sprite), 'cdn', 'docs'));

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Sam Potts
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,97 @@
{
"_from": "rangetouch@^2.0.0",
"_id": "rangetouch@2.0.0",
"_inBundle": false,
"_integrity": "sha512-y66wTFbwh7KafYligRsmIYYR1kZY8U9tGHH9PgbVhBUFmGzPMsOSjslXPedgR5D3M9W1QKVbAf1AtaVAt7JJTw==",
"_location": "/rangetouch",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "rangetouch@^2.0.0",
"name": "rangetouch",
"escapedName": "rangetouch",
"rawSpec": "^2.0.0",
"saveSpec": null,
"fetchSpec": "^2.0.0"
},
"_requiredBy": [
"/plyr"
],
"_resolved": "https://registry.npmjs.org/rangetouch/-/rangetouch-2.0.0.tgz",
"_shasum": "5459cdb38b929326c5484ab47aac9632fbe3a896",
"_spec": "rangetouch@^2.0.0",
"_where": "/home/andy/plyr/node_modules/plyr",
"author": {
"name": "Sam Potts",
"email": "sam@potts.es"
},
"browserslist": [
"> 1%"
],
"bugs": {
"url": "https://github.com/sampotts/rangetouch/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "A super tiny library to make input type='range' sliders work better on touch devices",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"aws-sdk": "^2.400.0",
"babel-eslint": "^10.0.1",
"babel-preset-minify": "^0.5.0",
"eslint": "^5.13.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.16.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.0",
"gulp-autoprefixer": "^6.0.0",
"gulp-awspublish": "^4.0.0",
"gulp-better-rollup": "^3.4.0",
"gulp-clean-css": "^4.0.0",
"gulp-imagemin": "^5.0.3",
"gulp-less": "^4.0.1",
"gulp-plumber": "^1.2.1",
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"gulp-s3": "^0.11.0",
"gulp-size": "^3.0.0",
"gulp-sourcemaps": "^2.6.4",
"gulp-svgstore": "^7.0.1",
"gulp-terser": "^1.1.7",
"prettier-eslint": "^8.8.2",
"prettier-stylelint": "^0.4.2",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"run-sequence": "^2.2.1",
"stylelint": "^9.10.1",
"stylelint-config-prettier": "^4.0.0",
"stylelint-config-recommended": "^2.1.0",
"stylelint-order": "^2.0.0"
},
"directories": {
"doc": "docs"
},
"homepage": "https://rangetouch.com",
"keywords": [
"range",
"slider",
"rangetouch"
],
"license": "MIT",
"main": "src/js/rangetouch.js",
"name": "rangetouch",
"repository": {
"type": "git",
"url": "git://github.com/sampotts/rangetouch.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "2.0.0"
}

View File

@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}

View File

@@ -0,0 +1,111 @@
# RangeTouch
A super tiny library to make `<input type="range">` sliders work better on touch devices.
[Donate](#donate) - [Demo](https://rangetouch.com) - [![npm version](https://badge.fury.io/js/rangetouch.svg)](https://badge.fury.io/js/rangetouch)
## Why bother?
While building [plyr](https://plyr.io) I noticed how bad the experience was trying to use `<input type="range">` is on a touch device (particularly iOS). Touching the track on a desktop will jump the thumb handle to that point. However on some touch devices this simply focuses the input and to adjust the value you need to touch and drag the handle. This is something that I can't help but feel will eventually be fixed by the browser vendors but for now, you can use RangeTouch to fill that gap.
## Features
- Less than 1KB minified and gzipped
- No dependencies (written in "vanilla" JavaScript)
- Uses event delgation so no need to re-run after DOM manipulation
## Quick setup
### 1. Include the lib
Either use the ES6 module:
```javascript
import RangeTouch from 'rangetouch';
```
...or include the script:
```html
<script src="https://rangetouch.com/1.0.6/rangetouch.js"></script>
```
### 2. Create instance(s)
#### Single instance
```javascript
const range = new RangeTouch('input[type="range"]', { ...options });
```
The first argument can either be:
- a [valid CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
- an [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)
The second argument is for options.
This will return a reference to the single instance.
#### Multiple instances
To setup multiple inputs at one time, you can use the following static method:
```javascript
const ranges = RangeTouch.setup('input[type="range"]', { ...options });
```
The first argument can either be:
- a [valid CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
- an [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)
- an [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList)
- an [Element](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)
The second argument is for options.
This will return an array of RangeTouch instances that it setup.
## Options
| Property | Type | Default | Description |
| ---------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| addCSS | Boolean | `true` | Whether to inject CSS to improve the usability of the inputs. It's recommended you add this yourself if you don't want RangeTouch to take care of it. |
| thumbWidth | Integer | `15` | This value is used as part of the calculation to determine the value the users selects when touching the range track. Unfortunately as JavaScript can't access the shadow DOM, this value can't be automatically determined. I would recommend customisation (and setting the size of the thumb) given all OS and browser combinations seem to render the control differently. |
| watch | Boolean | `true` | Watch for new elements added to the DOM that match your string selector. **Note**: This only applies when using the multiple instance `RangeTouch` setup method and also requires a string selector as the first argument. |
## API
| Method | Arguments | Description |
| --------- | --------- | -------------------------------------------------------- |
| destroy() | N/A | Destroy the current instance and remove event listeners. |
To call an API method, you need a reference to the instance. For example:
```javascript
const range = new RangeTouch('input[type="range"]', { ...options });
range.destroy();
```
## Issues
If you find anything weird with RangeTouch, please let us know using the [GitHub issues tracker](https://github.com/sampotts/rangetouch/issues) and be descriptive on how to reproduce, expected result, the browser (and version) used, etc.
## Author
RangeTouch is developed by [@sam_potts](https://twitter.com/sam_potts) / [sampotts.me](http://sampotts.me)
## Donate
RangeTouch costs money to run for domains, hosting and more. Any help is appreciated...
[Donate to support RangeTouch](https://www.paypal.me/pottsy/20usd)
## Thanks
[![Fastly](https://cdn.plyr.io/static/fastly-logo.png)](https://www.fastly.com/)
Thanks to [Fastly](https://www.fastly.com/) for providing the CDN services.
## Copyright and License
[The MIT license](license.md).

View File

@@ -0,0 +1,7 @@
const defaults = {
addCSS: true, // Add CSS to the element to improve usability (required here or in your CSS!)
thumbWidth: 15, // The width of the thumb handle
watch: true, // Watch for new elements that match a string target
};
export default defaults;

View File

@@ -0,0 +1,192 @@
// ==========================================================================
// rangetouch.js v2.0.0
// Making <input type="range"> work on touch devices
// https://github.com/sampotts/rangetouch
// License: The MIT License (MIT)
// ==========================================================================
import defaults from './config';
import { matches } from './utils/css';
import { trigger } from './utils/events';
import is from './utils/is';
import { round } from './utils/numbers';
class RangeTouch {
/**
* Setup a new instance
* @param {String|Element} target
* @param {Object} options
*/
constructor(target, options) {
if (is.element(target)) {
// An Element is passed, use it directly
this.element = target;
} else if (is.string(target)) {
// A CSS Selector is passed, fetch it from the DOM
this.element = document.querySelector(target);
}
if (!is.element(this.element) || !is.empty(this.element.rangeTouch)) {
return;
}
this.config = Object.assign({}, defaults, options);
this.init();
}
static get enabled() {
return 'ontouchstart' in document.documentElement;
}
/**
* Setup multiple instances
* @param {String|Element|NodeList|Array} target
* @param {Object} options
*/
static setup(target, options = {}) {
let targets = null;
if (is.empty(target) || is.string(target)) {
targets = Array.from(document.querySelectorAll(is.string(target) ? target : 'input[type="range"]'));
} else if (is.element(target)) {
targets = [target];
} else if (is.nodeList(target)) {
targets = Array.from(target);
} else if (is.array(target)) {
targets = target.filter(is.element);
}
if (is.empty(targets)) {
return null;
}
const config = Object.assign({}, defaults, options);
if (is.string(target) && config.watch) {
// Create an observer instance
const observer = new MutationObserver(mutations => {
Array.from(mutations).forEach(mutation => {
Array.from(mutation.addedNodes).forEach(node => {
if (!is.element(node) || !matches(node, target)) {
return;
}
// eslint-disable-next-line no-unused-vars
const range = new RangeTouch(node, config);
});
});
});
// Pass in the target node, as well as the observer options
observer.observe(document.body, {
childList: true,
subtree: true,
});
}
return targets.map(t => new RangeTouch(t, options));
}
init() {
// Bail if not a touch enabled device
if (!RangeTouch.enabled) {
return;
}
// Add useful CSS
if (this.config.addCSS) {
// TODO: Restore original values on destroy
this.element.style.userSelect = 'none';
this.element.style.webKitUserSelect = 'none';
this.element.style.touchAction = 'manipulation';
}
this.listeners(true);
this.element.rangeTouch = this;
}
destroy() {
// Bail if not a touch enabled device
if (!RangeTouch.enabled) {
return;
}
this.listeners(false);
this.element.rangeTouch = null;
}
listeners(toggle) {
const method = toggle ? 'addEventListener' : 'removeEventListener';
// Listen for events
['touchstart', 'touchmove', 'touchend'].forEach(type => {
this.element[method](type, event => this.set(event), false);
});
}
/**
* Get the value based on touch position
* @param {Event} event
*/
get(event) {
if (!RangeTouch.enabled || !is.event(event)) {
return null;
}
const input = event.target;
const touch = event.changedTouches[0];
const min = parseFloat(input.getAttribute('min')) || 0;
const max = parseFloat(input.getAttribute('max')) || 100;
const step = parseFloat(input.getAttribute('step')) || 1;
const delta = max - min;
// Calculate percentage
let percent;
const clientRect = input.getBoundingClientRect();
const thumbWidth = ((100 / clientRect.width) * (this.config.thumbWidth / 2)) / 100;
// Determine left percentage
percent = (100 / clientRect.width) * (touch.clientX - clientRect.left);
// Don't allow outside bounds
if (percent < 0) {
percent = 0;
} else if (percent > 100) {
percent = 100;
}
// Factor in the thumb offset
if (percent < 50) {
percent -= (100 - percent * 2) * thumbWidth;
} else if (percent > 50) {
percent += (percent - 50) * 2 * thumbWidth;
}
// Find the closest step to the mouse position
return min + round(delta * (percent / 100), step);
}
/**
* Update range value based on position
* @param {Event} event
*/
set(event) {
if (!RangeTouch.enabled || !is.event(event) || event.target.disabled) {
return;
}
// Prevent text highlight on iOS
event.preventDefault();
// Set value
event.target.value = this.get(event);
// Trigger event
trigger(event.target, event.type === 'touchend' ? 'change' : 'input');
}
}
export default RangeTouch;

View File

@@ -0,0 +1,19 @@
// Element matches a selector
export function matches(element, selector) {
const prototype = { Element };
function match() {
return Array.from(document.querySelectorAll(selector)).includes(this);
}
const matches =
prototype.matches ||
prototype.webkitMatchesSelector ||
prototype.mozMatchesSelector ||
prototype.msMatchesSelector ||
match;
return matches.call(element, selector);
}
export default {};

View File

@@ -0,0 +1,14 @@
// Trigger event
export function trigger(element, type) {
if (!element || !type) {
return;
}
// Create and dispatch the event
const event = new Event(type);
// Dispatch the event
element.dispatchEvent(event);
}
export default {};

View File

@@ -0,0 +1,35 @@
// ==========================================================================
// Type checking utils
// ==========================================================================
const getConstructor = input => (input !== null && typeof input !== 'undefined' ? input.constructor : null);
const instanceOf = (input, constructor) => Boolean(input && constructor && input instanceof constructor);
const isNullOrUndefined = input => input === null || typeof input === 'undefined';
const isObject = input => getConstructor(input) === Object;
const isNumber = input => getConstructor(input) === Number && !Number.isNaN(input);
const isString = input => getConstructor(input) === String;
const isBoolean = input => getConstructor(input) === Boolean;
const isFunction = input => getConstructor(input) === Function;
const isArray = input => Array.isArray(input);
const isNodeList = input => instanceOf(input, NodeList);
const isElement = input => instanceOf(input, Element);
const isEvent = input => instanceOf(input, Event);
const isEmpty = input =>
isNullOrUndefined(input) ||
((isString(input) || isArray(input) || isNodeList(input)) && !input.length) ||
(isObject(input) && !Object.keys(input).length);
export default {
nullOrUndefined: isNullOrUndefined,
object: isObject,
number: isNumber,
string: isString,
boolean: isBoolean,
function: isFunction,
array: isArray,
nodeList: isNodeList,
element: isElement,
event: isEvent,
empty: isEmpty,
};

View File

@@ -0,0 +1,27 @@
// Get the number of decimal places
export function getDecimalPlaces(value) {
const match = `${value}`.match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
return Math.max(
0,
// Number of digits right of decimal point.
(match[1] ? match[1].length : 0) -
// Adjust for scientific notation.
(match[2] ? +match[2] : 0),
);
}
// Round to the nearest step
export function round(number, step) {
if (step < 1) {
const places = getDecimalPlaces(step);
return parseFloat(number.toFixed(places));
}
return Math.round(number / step) * step;
}
export default {};

File diff suppressed because it is too large Load Diff