diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-30 16:45:38 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-30 16:45:38 +0800 |
| commit | a0579f91bbdf0de62b59df381d97a008bb98df57 (patch) | |
| tree | 69c21333750c7bc7358f9383560438048d9adebf /node_modules/css-mediaquery | |
| parent | 2d8aeba452672bcda2096e5d76bf37131c34075e (diff) | |
update/upgrade
Diffstat (limited to 'node_modules/css-mediaquery')
| -rw-r--r-- | node_modules/css-mediaquery/.npmignore | 6 | ||||
| -rw-r--r-- | node_modules/css-mediaquery/HISTORY.md | 22 | ||||
| -rw-r--r-- | node_modules/css-mediaquery/LICENSE | 27 | ||||
| -rw-r--r-- | node_modules/css-mediaquery/README.md | 94 | ||||
| -rw-r--r-- | node_modules/css-mediaquery/index.js | 157 | ||||
| -rw-r--r-- | node_modules/css-mediaquery/package.json | 36 |
6 files changed, 342 insertions, 0 deletions
diff --git a/node_modules/css-mediaquery/.npmignore b/node_modules/css-mediaquery/.npmignore new file mode 100644 index 00000000..37904a9d --- /dev/null +++ b/node_modules/css-mediaquery/.npmignore @@ -0,0 +1,6 @@ +.DS_Store +.gitignore +.travis.yml +coverage/ +node_modules/ +test/ diff --git a/node_modules/css-mediaquery/HISTORY.md b/node_modules/css-mediaquery/HISTORY.md new file mode 100644 index 00000000..d1915aa8 --- /dev/null +++ b/node_modules/css-mediaquery/HISTORY.md @@ -0,0 +1,22 @@ +CSS Media Query Change History +============================== + +0.1.2 (2014-01-21) +------------------ + +* Fixed issue with parsing media queries that do not have expressions. ([#5][]) + + +[#5]: https://github.com/ericf/css-mediaquery/issues/5 + + +0.1.1 (2014-01-08) +------------------ + +* Added docs to README for `parse()`. + + +0.1.0 (2014-01-08) +------------------ + +* Initial public release. diff --git a/node_modules/css-mediaquery/LICENSE b/node_modules/css-mediaquery/LICENSE new file mode 100644 index 00000000..263382ae --- /dev/null +++ b/node_modules/css-mediaquery/LICENSE @@ -0,0 +1,27 @@ +Copyright 2014 Yahoo! Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the Yahoo! Inc. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/css-mediaquery/README.md b/node_modules/css-mediaquery/README.md new file mode 100644 index 00000000..4c346229 --- /dev/null +++ b/node_modules/css-mediaquery/README.md @@ -0,0 +1,94 @@ +CSS Media Query +=============== + +[](https://travis-ci.org/ericf/css-mediaquery) +[](https://gemnasium.com/ericf/css-mediaquery) +[](https://npmjs.org/package/css-mediaquery) + +Parses and determines if a given CSS Media Query matches a set of values via +JavaScript. + +Installation +------------ + +Install via npm: + +```shell +$ npm install css-mediaquery +``` + +Usage +----- + +This package has two exports: `parse()`, and `match()` which can parse CSS Media +Queries and determine if a media query matches a given set of values. + +### Matching + +The `match()` method lets you compare a media query expression with a JavaScript +object and determine if a media query matches a given set of values. + +```javascript +var mediaQuery = require('css-mediaquery'); + +var isMatch = mediaQuery.match('screen and (min-width: 40em)', { + type : 'screen', + width: '1024px' +}); + +console.log(isMatch); // => true +``` + +The values specified to check a media query string against should be thought of +as if they are the current state of a device/browser. A `type` value _must_ be +specified, and it can _not_ be `"all"`. + +### Parsing + +Existing CSS Parsers don't do a great job at parsing the details of media +queries. That's where `css-mediaquery` shines. You can parse a media query +expression and get an AST back by using the `parse()` method. + +```javascript +var mediaQuery = require('css-mediaquery'), + ast = mediaQuery.parse('screen and (min-width: 48em)'); +``` + +The `ast` variable will have the following payload: + +```javascript +[ + { + inverse: false, + type : 'screen', + + expressions: [ + { + modifier: 'min', + feature : 'width', + value : '48em' + } + ] + } +] +``` + +This package was written with care to following the W3C Recommendations for +[CSS3 Media Queries][w3c-mq] and [CSS3 Values and Units][w3c-vu]. It supports +all of the [Media Features][w3c-mq-features] and will properly convert values to +a common unit before comparing them. + + +[w3c-mq]: http://www.w3.org/TR/css3-mediaqueries/ +[w3c-mq-features]: http://www.w3.org/TR/css3-mediaqueries/#media1 +[w3c-vu]: http://www.w3.org/TR/css3-values/ + + +License +------- + +This software is free to use under the Yahoo! Inc. BSD license. +See the [LICENSE file][] for license text and copyright information. + + +[LICENSE file]: https://github.com/ericf/css-mediaquery/blob/master/LICENSE diff --git a/node_modules/css-mediaquery/index.js b/node_modules/css-mediaquery/index.js new file mode 100644 index 00000000..b1d9b0d3 --- /dev/null +++ b/node_modules/css-mediaquery/index.js @@ -0,0 +1,157 @@ +/* +Copyright (c) 2014, Yahoo! Inc. All rights reserved. +Copyrights licensed under the New BSD License. +See the accompanying LICENSE file for terms. +*/ + +'use strict'; + +exports.match = matchQuery; +exports.parse = parseQuery; + +// ----------------------------------------------------------------------------- + +var RE_MEDIA_QUERY = /(?:(only|not)?\s*([^\s\(\)]+)(?:\s*and)?\s*)?(.+)?/i, + RE_MQ_EXPRESSION = /\(\s*([^\s\:\)]+)\s*(?:\:\s*([^\s\)]+))?\s*\)/, + RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/, + RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?$/, + RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?$/; + +function matchQuery(mediaQuery, values) { + return parseQuery(mediaQuery).some(function (query) { + var inverse = query.inverse; + + // Either the parsed or specified `type` is "all", or the types must be + // equal for a match. + var typeMatch = query.type === 'all' || values.type === query.type; + + // Quit early when `type` doesn't match, but take "not" into account. + if ((typeMatch && inverse) || !(typeMatch || inverse)) { + return false; + } + + var expressionsMatch = query.expressions.every(function (expression) { + var feature = expression.feature, + modifier = expression.modifier, + expValue = expression.value, + value = values[feature]; + + // Missing or falsy values don't match. + if (!value) { return false; } + + switch (feature) { + case 'orientation': + case 'scan': + return value.toLowerCase() === expValue.toLowerCase(); + + case 'width': + case 'height': + case 'device-width': + case 'device-height': + expValue = toPx(expValue); + value = toPx(value); + break; + + case 'resolution': + expValue = toDpi(expValue); + value = toDpi(value); + break; + + case 'aspect-ratio': + case 'device-aspect-ratio': + case /* Deprecated */ 'device-pixel-ratio': + expValue = toDecimal(expValue); + value = toDecimal(value); + break; + + case 'grid': + case 'color': + case 'color-index': + case 'monochrome': + expValue = parseInt(expValue, 10) || 1; + value = parseInt(value, 10) || 0; + break; + } + + switch (modifier) { + case 'min': return value >= expValue; + case 'max': return value <= expValue; + default : return value === expValue; + } + }); + + return (expressionsMatch && !inverse) || (!expressionsMatch && inverse); + }); +} + +function parseQuery(mediaQuery) { + return mediaQuery.split(',').map(function (query) { + query = query.trim(); + + var captures = query.match(RE_MEDIA_QUERY), + modifier = captures[1], + type = captures[2], + expressions = captures[3] || '', + parsed = {}; + + parsed.inverse = !!modifier && modifier.toLowerCase() === 'not'; + parsed.type = type ? type.toLowerCase() : 'all'; + + // Split expressions into a list. + expressions = expressions.match(/\([^\)]+\)/g) || []; + + parsed.expressions = expressions.map(function (expression) { + var captures = expression.match(RE_MQ_EXPRESSION), + feature = captures[1].toLowerCase().match(RE_MQ_FEATURE); + + return { + modifier: feature[1], + feature : feature[2], + value : captures[2] + }; + }); + + return parsed; + }); +} + +// -- Utilities ---------------------------------------------------------------- + +function toDecimal(ratio) { + var decimal = Number(ratio), + numbers; + + if (!decimal) { + numbers = ratio.match(/^(\d+)\s*\/\s*(\d+)$/); + decimal = numbers[1] / numbers[2]; + } + + return decimal; +} + +function toDpi(resolution) { + var value = parseFloat(resolution), + units = String(resolution).match(RE_RESOLUTION_UNIT)[1]; + + switch (units) { + case 'dpcm': return value / 2.54; + case 'dppx': return value * 96; + default : return value; + } +} + +function toPx(length) { + var value = parseFloat(length), + units = String(length).match(RE_LENGTH_UNIT)[1]; + + switch (units) { + case 'em' : return value * 16; + case 'rem': return value * 16; + case 'cm' : return value * 96 / 2.54; + case 'mm' : return value * 96 / 2.54 / 10; + case 'in' : return value * 96; + case 'pt' : return value * 72; + case 'pc' : return value * 72 / 12; + default : return value; + } +} diff --git a/node_modules/css-mediaquery/package.json b/node_modules/css-mediaquery/package.json new file mode 100644 index 00000000..623f7950 --- /dev/null +++ b/node_modules/css-mediaquery/package.json @@ -0,0 +1,36 @@ +{ + "name": "css-mediaquery", + "version": "0.1.2", + "description": "Parses and determines if a given CSS Media Query matches a set of values.", + "main": "index.js", + "scripts": { + "test": "istanbul cover -- ./node_modules/mocha/bin/_mocha test/ --reporter spec" + }, + "repository": { + "type": "git", + "url": "git://github.com/ericf/css-mediaquery.git" + }, + "keywords": [ + "css", + "media", + "query", + "mediaquery", + "mobile", + "parse", + "match" + ], + "author": "Eric Ferraiuolo <eferraiuolo@gmail.com>", + "contributors": [ + "Tilo Mitra <tilomitra@gmail.com>" + ], + "license": "BSD", + "bugs": { + "url": "https://github.com/ericf/css-mediaquery/issues" + }, + "homepage": "https://github.com/ericf/css-mediaquery", + "devDependencies": { + "mocha": "~1.16.2", + "chai": "~1.8.1", + "istanbul": "~0.2.3" + } +} |
