This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

21
node_modules/sort-css-media-queries/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Oleg Dutchenko <dutchenko.o.dev@gmail.com>
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.

194
node_modules/sort-css-media-queries/README.md generated vendored Normal file
View File

@@ -0,0 +1,194 @@
# sort-css-media-queries
![types](https://img.shields.io/badge/types-TypeScript-blue)
![npm](https://img.shields.io/badge/node-6.3.0-yellow.svg)
![license](https://img.shields.io/badge/License-MIT-orange.svg)
![Test](https://github.com/dutchenkoOleg/sort-css-media-queries/workflows/Test/badge.svg)
[![Build Status](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries.svg?branch=master)](https://travis-ci.org/dutchenkoOleg/sort-css-media-queries)
> The custom `sort` method (mobile-first / desktop-first) for [`css-mqpacker`](https://www.npmjs.com/package/css-mqpacker) or [`pleeease`](https://www.npmjs.com/package/pleeease) (which uses css-mqpacker) or, perhaps, something else ))
[![image](https://raw.githubusercontent.com/WezomCompany/code-style/main/assets/code-style-badge-white.svg)](https://github.com/WezomCompany/code-style)
| Statements | Branches | Functions | Lines |
| --------------------------------------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------- |
| ![Statements](https://img.shields.io/badge/statements-95.68%25-brightgreen.svg) | ![Branches](https://img.shields.io/badge/branches-96.48%25-brightgreen.svg) | ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg) | ![Lines](https://img.shields.io/badge/lines-95.68%25-brightgreen.svg) |
---
## Table of Contents
English
|
[Русский язык](https://github.com/dutchenkoOleg/sort-css-media-queries/blob/master/README-RU.md)
- [Alternative to `mqpacker`](#alternative-to-mqpacker)
- [Available in CSS-in-JS](#available-in-css-in-js-)
- [Installing](#installing)
- [Usage](#usage)
- [mobile-first](#mobile-first)
- [desktop-first](#desktop-first)
- [Sort configuration](#sort-configuration)
- [Configuration options](#configuration-options)
- [Project info](#project-info)
## Alternative to `mqpacker`
https://github.com/hail2u/node-css-mqpacker is deprecated.
One of the alternative plugins may be - [postcss-sort-media-queries](https://github.com/solversgroup/postcss-sort-media-queries)
## Available in CSS-in-JS 🚀
This package now is a part of the [jss-plugin-sort-css-media-queries](https://www.npmjs.com/package/jss-plugin-sort-css-media-queries)
## Installing
```shell
npm install --save sort-css-media-queries
# or using yarn cli
yarn add sort-css-media-queries
```
## Usage
See the original docs at first https://www.npmjs.com/package/css-mqpacker#sort;
```js
const sortCSSmq = require('sort-css-media-queries');
// your cool code
// ...
postcss([
mqpacker({
sort: sortCSSmq
})
]).process(css);
```
### mobile-first
The plugin will sort your media-queries according to the mobile-first methodology. The sequence of media requests:
1. `min-width` and `min-height` from smallest to largest,
1. `max-width` and `max-height` from largest to smallest,
1. `min-device-width` and `min-device-height` from smallest to largest,
1. `max-device-width` and `max-device-height` from largest to smallest
1. media queries without dimension values, for example `print, tv, ...`,
1. at the end:
- `print`
- `print and (orientation: landscape)`
- `print and (orientation: portrait)`
Example
Media-queries list:
```js
// min-width/-height -> from smallest to largest
'screen and (min-width: 320px) and (max-width: 767px)',
'screen and (min-height: 480px)',
'screen and (min-height: 480px) and (min-width: 320px)',
'screen and (min-width: 640px)',
'screen and (min-width: 1024px)',
'screen and (min-width: 1280px)',
// device
'screen and (min-device-width: 320px) and (max-device-width: 767px)',
// max-width/-height <- from largest to smallest
'screen and (max-width: 1023px)',
'screen and (max-height: 767px) and (min-height: 320px)',
'screen and (max-width: 767px) and (min-width: 320px)',
'screen and (max-width: 639px)',
// no units
'screen and (orientation: landscape)',
'screen and (orientation: portrait)',
'print',
'tv'
```
Sort result:
```js
'screen and (min-width: 320px) and (max-width: 767px)',
'screen and (min-height: 480px)',
'screen and (min-height: 480px) and (min-width: 320px)',
'screen and (min-width: 640px)',
'screen and (min-width: 1024px)',
'screen and (min-width: 1280px)',
'screen and (min-device-width: 320px) and (max-device-width: 767px)',
'screen and (max-width: 1023px)',
'screen and (max-height: 767px) and (min-height: 320px)',
'screen and (max-width: 767px) and (min-width: 320px)',
'screen and (max-width: 639px)',
'print',
'screen and (orientation: landscape)',
'screen and (orientation: portrait)',
'tv'
```
### desktop-first
```js
const sortCSSmq = require('sort-css-media-queries');
// your cool code
// ...
postcss([
mqpacker({
sort: sortCSSmq.desktopFirst
})
]).process(css);
```
The plugin will sort your media-queries according to the desktop-first methodology. The sequence of media requests:
1. `max-width` and `max-height` from largest to smallest,
1. `max-device-width` and `max-device-height` from largest to smallest
1. `min-width` and `min-height` from smallest to largest,
1. `min-device-width` and `min-device-height` from smallest to largest,
1. media queries without dimension values, `tv, ...`,
1. at the end:
- `print`
- `print and (orientation: landscape)`
- `print and (orientation: portrait)`
---
## Sort configuration
You can import a separate sorting helper from a package
and create your own sorting method with config as needed:
```js
const createSort = require("sort-css-media-queries/lib/create-sort");
const sortCSSmq = createSort({ ...configuration });
```
Or alternatively create a `sort-css-mq.config.json` file in the root of your project.
Or add property `sortCssMQ: {}` in your `package.json`.
By this configuration you can control sorting behaviour.
### Configuration options
#### `unitlessMqAlwaysFirst`
- type: `boolean | undefined`
- default value: `undefined`
---
## Project Info
* [Release notes](https://github.com/dutchenkoOleg/sort-css-media-queries/releases)
* [Contributor Covenant Code of Conduct](https://github.com/dutchenkoOleg/sort-css-media-queries/blob/master/CODE_OF_CONDUCT.md)
* [License MIT](https://github.com/dutchenkoOleg/sort-css-media-queries/blob/master/LICENSE)

265
node_modules/sort-css-media-queries/lib/create-sort.js generated vendored Normal file
View File

@@ -0,0 +1,265 @@
// ----------------------------------------
// Private
// ----------------------------------------
const minMaxWidth = /(!?\(\s*min(-device-)?-width)(.|\n)+\(\s*max(-device)?-width/i;
const minWidth = /\(\s*min(-device)?-width/i;
const maxMinWidth = /(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width/i;
const maxWidth = /\(\s*max(-device)?-width/i;
const isMinWidth = _testQuery(minMaxWidth, maxMinWidth, minWidth);
const isMaxWidth = _testQuery(maxMinWidth, minMaxWidth, maxWidth);
const minMaxHeight = /(!?\(\s*min(-device)?-height)(.|\n)+\(\s*max(-device)?-height/i;
const minHeight = /\(\s*min(-device)?-height/i;
const maxMinHeight = /(!?\(\s*max(-device)?-height)(.|\n)+\(\s*min(-device)?-height/i;
const maxHeight = /\(\s*max(-device)?-height/i;
const isMinHeight = _testQuery(minMaxHeight, maxMinHeight, minHeight);
const isMaxHeight = _testQuery(maxMinHeight, minMaxHeight, maxHeight);
const isPrint = /print/i;
const isPrintOnly = /^print$/i;
const maxValue = Number.MAX_VALUE;
/**
* Obtain the length of the media request in pixels.
* Copy from original source `function inspectLength (length)`
* {@link https://github.com/hail2u/node-css-mqpacker/blob/master/index.js#L58}
* @private
* @param {string} length
* @return {number}
*/
function _getQueryLength(query) {
let length = /(-?\d*\.?\d+)(ch|em|ex|px|rem)/.exec(query);
if (length === null && (isMinWidth(query) || isMinHeight(query))) {
length = /(\d)/.exec(query);
}
if (length === '0') {
return 0;
}
if (length === null) {
return maxValue;
}
let number = length[1];
const unit = length[2];
switch (unit) {
case 'ch':
number = parseFloat(number) * 8.8984375;
break;
case 'em':
case 'rem':
number = parseFloat(number) * 16;
break;
case 'ex':
number = parseFloat(number) * 8.296875;
break;
case 'px':
number = parseFloat(number);
break;
}
return +number;
}
/**
* Wrapper for creating test functions
* @private
* @param {RegExp} doubleTestTrue
* @param {RegExp} doubleTestFalse
* @param {RegExp} singleTest
* @return {Function}
*/
function _testQuery(doubleTestTrue, doubleTestFalse, singleTest) {
/**
* @param {string} query
* @return {boolean}
*/
return function (query) {
if (doubleTestTrue.test(query)) {
return true;
} else if (doubleTestFalse.test(query)) {
return false;
}
return singleTest.test(query);
};
}
/**
* @private
* @param {string} a
* @param {string} b
* @return {number|null}
*/
function _testIsPrint(a, b) {
const isPrintA = isPrint.test(a);
const isPrintOnlyA = isPrintOnly.test(a);
const isPrintB = isPrint.test(b);
const isPrintOnlyB = isPrintOnly.test(b);
if (isPrintA && isPrintB) {
if (!isPrintOnlyA && isPrintOnlyB) {
return 1;
}
if (isPrintOnlyA && !isPrintOnlyB) {
return -1;
}
return a.localeCompare(b);
}
if (isPrintA) {
return 1;
}
if (isPrintB) {
return -1;
}
return null;
}
// ----------------------------------------
// Public
// ----------------------------------------
/**
* @param {Object} [configuration]
* @param {boolean} [configuration.unitlessMqAlwaysFirst]
* @returns {(function(string, string): number)|*}
*/
module.exports = function createSort(configuration) {
const config = configuration || {};
const UNITLESS_MQ_ALWAYS_FIRST = config.unitlessMqAlwaysFirst;
/**
* Sorting an array with media queries
* according to the mobile-first methodology.
* @param {string} a
* @param {string} b
* @return {number} 1 / 0 / -1
*/
function sortCSSmq(a, b) {
const testIsPrint = _testIsPrint(a, b);
if (testIsPrint !== null) {
return testIsPrint;
}
const minA = isMinWidth(a) || isMinHeight(a);
const maxA = isMaxWidth(a) || isMaxHeight(a);
const minB = isMinWidth(b) || isMinHeight(b);
const maxB = isMaxWidth(b) || isMaxHeight(b);
if (UNITLESS_MQ_ALWAYS_FIRST && ((!minA && !maxA) || (!minB && !maxB))) {
if (!minA && !maxA && !minB && !maxB) {
return a.localeCompare(b);
}
return !minB && !maxB ? 1 : -1;
} else {
if (minA && maxB) {
return -1;
}
if (maxA && minB) {
return 1;
}
const lengthA = _getQueryLength(a);
const lengthB = _getQueryLength(b);
if (lengthA === maxValue && lengthB === maxValue) {
return a.localeCompare(b);
} else if (lengthA === maxValue) {
return 1;
} else if (lengthB === maxValue) {
return -1;
}
if (lengthA > lengthB) {
if (maxA) {
return -1;
}
return 1;
}
if (lengthA < lengthB) {
if (maxA) {
return 1;
}
return -1;
}
return a.localeCompare(b);
}
}
/**
* Sorting an array with media queries
* according to the desktop-first methodology.
* @param {string} a
* @param {string} b
* @return {number} 1 / 0 / -1
*/
sortCSSmq.desktopFirst = function (a, b) {
const testIsPrint = _testIsPrint(a, b);
if (testIsPrint !== null) {
return testIsPrint;
}
const minA = isMinWidth(a) || isMinHeight(a);
const maxA = isMaxWidth(a) || isMaxHeight(a);
const minB = isMinWidth(b) || isMinHeight(b);
const maxB = isMaxWidth(b) || isMaxHeight(b);
if (UNITLESS_MQ_ALWAYS_FIRST && ((!minA && !maxA) || (!minB && !maxB))) {
if (!minA && !maxA && !minB && !maxB) {
return a.localeCompare(b);
}
return !minB && !maxB ? 1 : -1;
} else {
if (minA && maxB) {
return 1;
}
if (maxA && minB) {
return -1;
}
const lengthA = _getQueryLength(a);
const lengthB = _getQueryLength(b);
if (lengthA === maxValue && lengthB === maxValue) {
return a.localeCompare(b);
} else if (lengthA === maxValue) {
return 1;
} else if (lengthB === maxValue) {
return -1;
}
if (lengthA > lengthB) {
if (maxA) {
return -1;
}
return 1;
}
if (lengthA < lengthB) {
if (maxA) {
return 1;
}
return -1;
}
return -a.localeCompare(b);
}
};
return sortCSSmq;
};

5
node_modules/sort-css-media-queries/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
export = sortCSSmq;
declare function sortCSSmq<T = string>(a: T, b: T): number;
declare namespace sortCSSmq {
function desktopFirst<T = string>(a: T, b: T): number;
}

3
node_modules/sort-css-media-queries/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
const createSort = require('./create-sort');
const loadConfig = require('./load-config');
module.exports = createSort(loadConfig());

28
node_modules/sort-css-media-queries/lib/load-config.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
module.exports = function loadConfig(
configFile = 'sort-css-mq.config.json',
pkgFile = 'package.json'
) {
let config = {};
try {
const cwd = process.cwd();
const configPath = path.join(cwd, configFile);
const pkgPath = path.join(cwd, pkgFile);
if (fs.existsSync(configPath)) {
config = JSON.parse(fs.readFileSync(configPath).toString());
} else if (fs.existsSync(pkgPath)) {
config = JSON.parse(fs.readFileSync(pkgPath).toString()).sortCssMQ;
}
} catch (e) {
console.log(e);
}
if (typeof config === 'object' && config !== null && !Array.isArray(config)) {
return config;
} else {
return {};
}
};

64
node_modules/sort-css-media-queries/package.json generated vendored Normal file
View File

@@ -0,0 +1,64 @@
{
"name": "sort-css-media-queries",
"version": "2.1.0",
"description": "The custom `sort` method (mobile-first / desktop-first) of CSS media queries for `postcss-sort-media-queries`, `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"test": "npm run prettier && npm run eslint && npm run jest",
"test:fix": "npm run prettier:fix && npm run eslint:fix && npm run jest:coverage",
"prettier": "prettier \"./{lib,tests}/**\" --check",
"prettier:fix": "npm run prettier -- --write",
"eslint": "eslint \"./{lib,tests}/**/*.js\"",
"eslint:fix": "npm run eslint -- --fix",
"jest": "jest",
"jest:coverage": "npm run jest -- --coverage && istanbul-badges-readme"
},
"jest": {
"verbose": true,
"testURL": "http://localhost"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dutchenkoOleg/sort-css-media-queries.git"
},
"keywords": [
"postcss",
"css-mqpacker",
"node-css-mqpacker",
"pleeease",
"mobile-first",
"combine",
"mq",
"media",
"queries",
"mobile-first",
"desktop-first",
"sort"
],
"author": "Oleg Dutchenko <dutchenko.o.dev@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/dutchenkoOleg/sort-css-media-queries/issues"
},
"engines": {
"node": ">= 6.3.0"
},
"homepage": "https://github.com/dutchenkoOleg/sort-css-media-queries#readme",
"devDependencies": {
"@wezom/eslint-config": "^8.0.0",
"chalk": "^2.4.1",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"istanbul-badges-readme": "^1.4.0",
"jest": "^26.4.2",
"mkdirp": "^1.0.4",
"prettier": "^2.3.0"
}
}