@csstools/postcss-content-alt-text 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +18 -0
- package/README.md +109 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.mjs +1 -0
- package/package.json +77 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changes to PostCSS Content Alt Text
|
|
2
|
+
|
|
3
|
+
### 1.0.0
|
|
4
|
+
|
|
5
|
+
_July 7, 2024_
|
|
6
|
+
|
|
7
|
+
- Initial version
|
|
8
|
+
- Updated [`@csstools/postcss-progressive-custom-properties`](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-progressive-custom-properties) to [`3.3.0`](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-progressive-custom-properties/CHANGELOG.md#330) (minor)
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT No Attribution (MIT-0)
|
|
2
|
+
|
|
3
|
+
Copyright © CSSTools Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
18
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# PostCSS Content Alt Text [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
|
|
2
|
+
|
|
3
|
+
[<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/postcss-content-alt-text.svg" height="20">][npm-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]<br><br>[<img alt="Baseline Status" src="https://cssdb.org/images/badges-baseline/content-alt-text.svg" height="20">][css-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/content-alt-text.svg" height="20">][css-url]
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @csstools/postcss-content-alt-text --save-dev
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
[PostCSS Content Alt Text] generates fallback values for `content` with alt text following the [CSS Generated Content Module].
|
|
10
|
+
|
|
11
|
+
```pcss
|
|
12
|
+
.foo {
|
|
13
|
+
content: url(tree.jpg) / "A beautiful tree in a dark forest";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* becomes */
|
|
17
|
+
|
|
18
|
+
.foo {
|
|
19
|
+
content: url(tree.jpg) "A beautiful tree in a dark forest";
|
|
20
|
+
content: url(tree.jpg) / "A beautiful tree in a dark forest";
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Add [PostCSS Content Alt Text] to your project:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install postcss @csstools/postcss-content-alt-text --save-dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use it as a [PostCSS] plugin:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const postcss = require('postcss');
|
|
36
|
+
const postcssContentAltText = require('@csstools/postcss-content-alt-text');
|
|
37
|
+
|
|
38
|
+
postcss([
|
|
39
|
+
postcssContentAltText(/* pluginOptions */)
|
|
40
|
+
]).process(YOUR_CSS /*, processOptions */);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
[PostCSS Content Alt Text] runs in all Node environments, with special
|
|
44
|
+
instructions for:
|
|
45
|
+
|
|
46
|
+
- [Node](INSTALL.md#node)
|
|
47
|
+
- [PostCSS CLI](INSTALL.md#postcss-cli)
|
|
48
|
+
- [PostCSS Load Config](INSTALL.md#postcss-load-config)
|
|
49
|
+
- [Webpack](INSTALL.md#webpack)
|
|
50
|
+
- [Next.js](INSTALL.md#nextjs)
|
|
51
|
+
- [Gulp](INSTALL.md#gulp)
|
|
52
|
+
- [Grunt](INSTALL.md#grunt)
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
### preserve
|
|
57
|
+
|
|
58
|
+
The `preserve` option determines whether the original notation
|
|
59
|
+
is preserved. By default, it is preserved.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
postcssContentAltText({ preserve: false })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```pcss
|
|
66
|
+
.foo {
|
|
67
|
+
content: url(tree.jpg) / "A beautiful tree in a dark forest";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* becomes */
|
|
71
|
+
|
|
72
|
+
.foo {
|
|
73
|
+
content: url(tree.jpg) "A beautiful tree in a dark forest";
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### stripAltText
|
|
78
|
+
|
|
79
|
+
The `stripAltText` option determines whether the alt text is removed from the value.
|
|
80
|
+
By default, it is not removed.
|
|
81
|
+
Instead it is added to the `content` value itself to ensure content is accessible.
|
|
82
|
+
|
|
83
|
+
Only set this to `true` if you are sure the alt text is not needed.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
postcssContentAltText({ stripAltText: true })
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```pcss
|
|
90
|
+
.foo {
|
|
91
|
+
content: url(tree.jpg) / "A beautiful tree in a dark forest";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* becomes */
|
|
95
|
+
|
|
96
|
+
.foo {
|
|
97
|
+
content: url(tree.jpg) ;
|
|
98
|
+
content: url(tree.jpg) / "A beautiful tree in a dark forest";
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|
103
|
+
[css-url]: https://cssdb.org/#content-alt-text
|
|
104
|
+
[discord]: https://discord.gg/bUadyRwkJS
|
|
105
|
+
[npm-url]: https://www.npmjs.com/package/@csstools/postcss-content-alt-text
|
|
106
|
+
|
|
107
|
+
[PostCSS]: https://github.com/postcss/postcss
|
|
108
|
+
[PostCSS Content Alt Text]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-content-alt-text
|
|
109
|
+
[CSS Generated Content Module]: https://drafts.csswg.org/css-content/#content-property
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@csstools/css-parser-algorithms"),s=require("@csstools/css-tokenizer"),t=require("@csstools/postcss-progressive-custom-properties"),o=require("@csstools/utilities");const r={test:e=>e.includes("content:")&&e.includes("/")},basePlugin=t=>({postcssPlugin:"postcss-content-alt-text",Declaration(n){if("content"!==n.prop||!n.value.includes("/"))return;if(o.hasFallback(n))return;if(o.hasSupportsAtRuleAncestor(n,r))return;const i=e.parseListOfComponentValues(s.tokenize({css:n.value}));let c=0;for(let o=i.length-1;o>=0;o--){const r=i[o];if(!e.isTokenNode(r))continue;const n=r.value;s.isTokenDelim(n)&&("/"===n[4].value&&(c++,!0===t?.stripAltText?i.splice(o,i.length):i.splice(o,1)))}if(1!==c)return;const l=e.stringify([i]);l!==n.value&&(n.cloneBefore({value:l}),!1===t?.preserve&&n.remove())}});basePlugin.postcss=!0;const creator=e=>{const s=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0,stripAltText:!1},e);return s.enableProgressiveCustomProperties&&s.preserve?{postcssPlugin:"postcss-content-alt-text",plugins:[t(),basePlugin(s)]}:basePlugin(s)};creator.postcss=!0,module.exports=creator;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PluginCreator } from 'postcss';
|
|
2
|
+
|
|
3
|
+
/** postcss-content-alt-text plugin options */
|
|
4
|
+
export declare type basePluginOptions = {
|
|
5
|
+
/** Preserve the original notation. default: true */
|
|
6
|
+
preserve: boolean;
|
|
7
|
+
/** Strip alt text */
|
|
8
|
+
stripAltText: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare const creator: PluginCreator<pluginOptions>;
|
|
12
|
+
export default creator;
|
|
13
|
+
|
|
14
|
+
/** postcss-content-alt-text plugin options */
|
|
15
|
+
export declare type pluginOptions = {
|
|
16
|
+
/** Preserve the original notation. default: true */
|
|
17
|
+
preserve?: boolean;
|
|
18
|
+
/** Strip alt text */
|
|
19
|
+
stripAltText?: boolean;
|
|
20
|
+
/** Enable "@csstools/postcss-progressive-custom-properties". default: true */
|
|
21
|
+
enableProgressiveCustomProperties?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { }
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseListOfComponentValues as s,isTokenNode as e,stringify as t}from"@csstools/css-parser-algorithms";import{tokenize as o,isTokenDelim as r}from"@csstools/css-tokenizer";import n from"@csstools/postcss-progressive-custom-properties";import{hasFallback as c,hasSupportsAtRuleAncestor as i}from"@csstools/utilities";const l={test:s=>s.includes("content:")&&s.includes("/")},basePlugin=n=>({postcssPlugin:"postcss-content-alt-text",Declaration(p){if("content"!==p.prop||!p.value.includes("/"))return;if(c(p))return;if(i(p,l))return;const u=s(o({css:p.value}));let a=0;for(let s=u.length-1;s>=0;s--){const t=u[s];if(!e(t))continue;const o=t.value;r(o)&&("/"===o[4].value&&(a++,!0===n?.stripAltText?u.splice(s,u.length):u.splice(s,1)))}if(1!==a)return;const m=t([u]);m!==p.value&&(p.cloneBefore({value:m}),!1===n?.preserve&&p.remove())}});basePlugin.postcss=!0;const creator=s=>{const e=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0,stripAltText:!1},s);return e.enableProgressiveCustomProperties&&e.preserve?{postcssPlugin:"postcss-content-alt-text",plugins:[n(),basePlugin(e)]}:basePlugin(e)};creator.postcss=!0;export{creator as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@csstools/postcss-content-alt-text",
|
|
3
|
+
"description": "Generate fallback values for content with alt text",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Antonio Laguna",
|
|
8
|
+
"email": "antonio@laguna.es",
|
|
9
|
+
"url": "https://antonio.laguna.es"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "Romain Menke",
|
|
13
|
+
"email": "romainmenke@gmail.com"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT-0",
|
|
17
|
+
"funding": [
|
|
18
|
+
{
|
|
19
|
+
"type": "github",
|
|
20
|
+
"url": "https://github.com/sponsors/csstools"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "opencollective",
|
|
24
|
+
"url": "https://opencollective.com/csstools"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^14 || ^16 || >=18"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "dist/index.cjs",
|
|
32
|
+
"module": "dist/index.mjs",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"default": "./dist/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"CHANGELOG.md",
|
|
46
|
+
"LICENSE.md",
|
|
47
|
+
"README.md",
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@csstools/css-parser-algorithms": "^2.7.1",
|
|
52
|
+
"@csstools/css-tokenizer": "^2.4.1",
|
|
53
|
+
"@csstools/postcss-progressive-custom-properties": "^3.3.0",
|
|
54
|
+
"@csstools/utilities": "^1.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"postcss": "^8.4"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {},
|
|
60
|
+
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-content-alt-text#readme",
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/csstools/postcss-plugins.git",
|
|
64
|
+
"directory": "plugins/postcss-content-alt-text"
|
|
65
|
+
},
|
|
66
|
+
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
67
|
+
"keywords": [
|
|
68
|
+
"accessibility",
|
|
69
|
+
"alt",
|
|
70
|
+
"content",
|
|
71
|
+
"css",
|
|
72
|
+
"csswg",
|
|
73
|
+
"fallback",
|
|
74
|
+
"postcss-plugin",
|
|
75
|
+
"w3c"
|
|
76
|
+
]
|
|
77
|
+
}
|