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

78
node_modules/srcset/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,78 @@
/* eslint-disable no-redeclare */
declare namespace srcset {
interface SrcSetDefinition {
url: string;
width?: number;
density?: number;
}
interface Options {
/**
When strict mode is enabled, errors will be thrown on invalid input.
When disabled, a best effort will be made to handle invalid input and no errors will be thrown. The output may be invalid.
@default false
*/
strict?: boolean;
}
}
declare const srcset: {
/**
Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Accepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `density`, and `height`.
@param srcset - A “srcset” string.
@example
```
import srcset = require('srcset');
console.log(srcset.parse('banner-HD.jpg 2x, banner-phone.jpg 100w'));
// [
// {
// url: 'banner-HD.jpg',
// density: 2
// },
// {
// url: 'banner-phone.jpg',
// width: 100
// }
// ]
```
*/
parse: (srcset: string, options?: srcset.Options) => srcset.SrcSetDefinition[];
/**
Stringify `SrcSetDefinition`s.
@param SrcSetDefinitions - Each object should have a `url` field and may have either `width` or `density`. When the `strict` option is `true`, only `width` or `density` is accepted.
@returns A “srcset” string.
@example
```
import srcset = require('srcset');
const stringified = srcset.stringify([
{
url: 'banner-HD.jpg',
density: 2
},
{
url: 'banner-phone.jpg',
width: 100
}
]);
console.log(stringified);
// banner-HD.jpg 2x, banner-phone.jpg 100w
```
*/
stringify: (srcSetDefinitions: readonly srcset.SrcSetDefinition[], options?: srcset.Options) => string;
};
export = srcset;

186
node_modules/srcset/index.js generated vendored Normal file
View File

@@ -0,0 +1,186 @@
'use strict';
/**
This regex represents a loose rule of an “image candidate string”.
@see https://html.spec.whatwg.org/multipage/images.html#srcset-attribute
An “image candidate string” roughly consists of the following:
1. Zero or more whitespace characters.
2. A non-empty URL that does not start or end with `,`.
3. Zero or more whitespace characters.
4. An optional “descriptor” that starts with a whitespace character.
5. Zero or more whitespace characters.
6. Each image candidate string is separated by a `,`.
We intentionally implement a loose rule here so that we can perform more aggressive error handling and reporting in the below code.
*/
const imageCandidateRegex = /\s*([^,]\S*[^,](?:\s+[^,]+)?)\s*(?:,|$)/;
const duplicateDescriptorCheck = (allDescriptors, value, postfix) => {
allDescriptors[postfix] = allDescriptors[postfix] || {};
if (allDescriptors[postfix][value]) {
throw new Error(`No more than one image candidate is allowed for a given descriptor: ${value}${postfix}`);
}
allDescriptors[postfix][value] = true;
};
const fallbackDescriptorDuplicateCheck = allDescriptors => {
if (allDescriptors.fallback) {
throw new Error('Only one fallback image candidate is allowed');
}
if (allDescriptors.x['1']) {
throw new Error('A fallback image is equivalent to a 1x descriptor, providing both is invalid.');
}
allDescriptors.fallback = true;
};
const descriptorCountCheck = (allDescriptors, currentDescriptors) => {
if (currentDescriptors.length === 0) {
fallbackDescriptorDuplicateCheck(allDescriptors);
} else if (currentDescriptors.length > 1) {
throw new Error(`Image candidate may have no more than one descriptor, found ${currentDescriptors.length}: ${currentDescriptors.join(' ')}`);
}
};
const validDescriptorCheck = (value, postfix, descriptor) => {
if (Number.isNaN(value)) {
throw new TypeError(`${descriptor || value} is not a valid number`);
}
switch (postfix) {
case 'w': {
if (value <= 0) {
throw new Error('Width descriptor must be greater than zero');
} else if (!Number.isInteger(value)) {
throw new TypeError('Width descriptor must be an integer');
}
break;
}
case 'x': {
if (value <= 0) {
throw new Error('Pixel density descriptor must be greater than zero');
}
break;
}
case 'h': {
throw new Error('Height descriptor is no longer allowed');
}
default: {
throw new Error(`Invalid srcset descriptor: ${descriptor}`);
}
}
};
exports.parse = (string, {strict = false} = {}) => {
const allDescriptors = strict ? {} : undefined;
return string.split(imageCandidateRegex)
.filter((part, index) => index % 2 === 1)
.map(part => {
const [url, ...descriptors] = part.trim().split(/\s+/);
const result = {url};
if (strict) {
descriptorCountCheck(allDescriptors, descriptors);
}
for (const descriptor of descriptors) {
const postfix = descriptor[descriptor.length - 1];
const value = Number.parseFloat(descriptor.slice(0, -1));
if (strict) {
validDescriptorCheck(value, postfix, descriptor);
duplicateDescriptorCheck(allDescriptors, value, postfix);
}
switch (postfix) {
case 'w': {
result.width = value;
break;
}
case 'h': {
result.height = value;
break;
}
case 'x': {
result.density = value;
break;
}
// No default
}
}
return result;
});
};
const knownDescriptors = new Set(['width', 'height', 'density']);
exports.stringify = (array, {strict = false} = {}) => {
const allDescriptors = strict ? {} : null;
return array.map(element => {
if (!element.url) {
if (strict) {
throw new Error('URL is required');
}
return '';
}
const descriptorKeys = Object.keys(element).filter(key => knownDescriptors.has(key));
if (strict) {
descriptorCountCheck(allDescriptors, descriptorKeys);
}
const result = [element.url];
for (const descriptorKey of descriptorKeys) {
const value = element[descriptorKey];
let postfix;
switch (descriptorKey) {
case 'width': {
postfix = 'w';
break;
}
case 'height': {
postfix = 'h';
break;
}
case 'density': {
postfix = 'x';
break;
}
// No default
}
const descriptor = `${value}${postfix}`;
if (strict) {
validDescriptorCheck(value, postfix);
duplicateDescriptorCheck(allDescriptors, value, postfix);
}
result.push(descriptor);
}
return result.join(' ');
}).join(', ');
};

9
node_modules/srcset/license generated vendored Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.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.

41
node_modules/srcset/package.json generated vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "srcset",
"version": "4.0.0",
"description": "Parse and stringify the HTML `<img>` srcset attribute",
"license": "MIT",
"repository": "sindresorhus/srcset",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"html",
"attribute",
"image",
"img",
"src",
"parse",
"stringify",
"srcset",
"responsive",
"picture",
"element"
],
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.39.0"
}
}

114
node_modules/srcset/readme.md generated vendored Normal file
View File

@@ -0,0 +1,114 @@
# srcset
> Parse and stringify the HTML `<img>` [srcset](https://www.smashingmagazine.com/2013/08/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Can be useful if you're creating a build-tool.
## Install
```
$ npm install srcset
```
## Usage
How an image with `srcset` might look like:
```html
<img
alt="The Breakfast Combo"
src="banner.jpg"
srcset="banner-HD.jpg 2x, banner-phone.jpg 100w"
>
```
Then have some fun with it:
```js
const srcset = require('srcset');
const parsed = srcset.parse('banner-HD.jpg 2x, banner-phone.jpg 100w');
console.log(parsed);
/*
[
{
url: 'banner-HD.jpg',
density: 2
},
{
url: 'banner-phone.jpg',
width: 100
}
]
*/
parsed.push({
url: 'banner-super-HD.jpg',
density: 3
});
const stringified = srcset.stringify(parsed);
console.log(stringified);
/*
banner-HD.jpg 2x, banner-phone.jpg 100w, banner-super-HD.jpg 3x
*/
```
## API
### .parse(string, options?)
Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Accepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `height`, and `density`.
#### string
Type: `string`
A “srcset” string.
#### options
Type: `object`
##### strict
Type: `boolean`\
Default: `false`
When enabled, an invalid “srcset” string will cause an error to be thrown. When disabled, a best effort will be made to parse the string, potentially resulting in invalid or nonsensical output.
### .stringify(SrcSetDefinitions, options?)
Stringify `SrcSetDefinition`s. Accepts an array of `SrcSetDefinition` objects and returns a “srcset” string.
#### srcsetDescriptors
Type: `array`
An array of `SrcSetDefinition` objects. Each object should have a `url` field and may have `width`, `height` or `density` fields. When the `strict` option is `true`, only `width` or `density` is accepted.
#### options
Type: `object`
##### strict
Type: `boolean`
Default: `false`
Enable or disable validation of the SrcSetDefinitions. When true, invalid input will cause an error to be thrown. When false, a best effort will be made to stringify invalid input, likely resulting in invalid srcset value.
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-srcset?utm_source=npm-srcset&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>