@csstools/postcss-random-function 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 ADDED
@@ -0,0 +1,8 @@
1
+ # Changes to PostCSS Random Function
2
+
3
+ ### 1.0.0
4
+
5
+ _November 11, 2024_
6
+
7
+ - Initial version
8
+ - Updated [`@csstools/css-calc`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc) to [`2.1.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc/CHANGELOG.md#210) (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,121 @@
1
+ # PostCSS Random Function [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
2
+
3
+ `npm install @csstools/postcss-random-function --save-dev`
4
+
5
+ [PostCSS Random Function] lets you use the `random` function, following the [CSS Values 5] specification.
6
+
7
+ ```css
8
+ div {
9
+ color: oklch(0.7, 0.2, random(120deg, 240deg));
10
+ }
11
+
12
+ div {
13
+ color: oklch(0.7, 0.2, random(120deg, 240deg, by 7deg));
14
+ }
15
+
16
+ div {
17
+ color: oklch(0.7, 0.2, random(--text, 120deg, 240deg));
18
+ border-color: oklch(0.7, 0.2, random(--border, 120deg, 240deg));
19
+ }
20
+
21
+ /* becomes */
22
+
23
+ div {
24
+ color: oklch(0.7, 0.2, 238.66036deg);
25
+ }
26
+
27
+ div {
28
+ color: oklch(0.7, 0.2, 134deg);
29
+ }
30
+
31
+ div {
32
+ color: oklch(0.7, 0.2, 226.47057deg);
33
+ border-color: oklch(0.7, 0.2, 157.76966deg);
34
+ }
35
+ ```
36
+
37
+ > [!NOTE]
38
+ > Generated values are deterministic pseudo random numbers.
39
+ > Generating values twice with the same input will give the same result.
40
+ > The input length of the CSS source file is used as a random seed.
41
+
42
+ ## Usage
43
+
44
+ Add [PostCSS Random Function] to your project:
45
+
46
+ ```bash
47
+ npm install postcss @csstools/postcss-random-function --save-dev
48
+ ```
49
+
50
+ Use it as a [PostCSS] plugin:
51
+
52
+ ```js
53
+ const postcss = require('postcss');
54
+ const postcssRandomFunction = require('@csstools/postcss-random-function');
55
+
56
+ postcss([
57
+ postcssRandomFunction(/* pluginOptions */)
58
+ ]).process(YOUR_CSS /*, processOptions */);
59
+ ```
60
+
61
+
62
+
63
+ ## ⚠️ About custom properties
64
+
65
+ Given the dynamic nature of custom properties it's impossible to know what the variable value is, which means the plugin can't compute a final value for the stylesheet.
66
+
67
+ Because of that, any usage that contains a `var` is skipped.
68
+
69
+ ## Options
70
+
71
+ ### preserve
72
+
73
+ The `preserve` option determines whether the original notation
74
+ is preserved. By default, it is not preserved.
75
+
76
+ ```js
77
+ postcssRandomFunction({ preserve: true })
78
+ ```
79
+
80
+ ```css
81
+ div {
82
+ color: oklch(0.7, 0.2, random(120deg, 240deg));
83
+ }
84
+
85
+ div {
86
+ color: oklch(0.7, 0.2, random(120deg, 240deg, by 7deg));
87
+ }
88
+
89
+ div {
90
+ color: oklch(0.7, 0.2, random(--text, 120deg, 240deg));
91
+ border-color: oklch(0.7, 0.2, random(--border, 120deg, 240deg));
92
+ }
93
+
94
+ /* becomes */
95
+
96
+ div {
97
+ color: oklch(0.7, 0.2, 238.66036deg);
98
+ color: oklch(0.7, 0.2, random(120deg, 240deg));
99
+ }
100
+
101
+ div {
102
+ color: oklch(0.7, 0.2, 134deg);
103
+ color: oklch(0.7, 0.2, random(120deg, 240deg, by 7deg));
104
+ }
105
+
106
+ div {
107
+ color: oklch(0.7, 0.2, 226.47057deg);
108
+ color: oklch(0.7, 0.2, random(--text, 120deg, 240deg));
109
+ border-color: oklch(0.7, 0.2, 157.76966deg);
110
+ border-color: oklch(0.7, 0.2, random(--border, 120deg, 240deg));
111
+ }
112
+ ```
113
+
114
+ [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
115
+ [css-url]: https://cssdb.org/#random-function
116
+ [discord]: https://discord.gg/bUadyRwkJS
117
+ [npm-url]: https://www.npmjs.com/package/@csstools/postcss-random-function
118
+
119
+ [PostCSS]: https://github.com/postcss/postcss
120
+ [PostCSS Random Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-random-function
121
+ [CSS Values 5]: https://drafts.csswg.org/css-values-5/#random
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("@csstools/css-calc");const s=/(?<![-\w])(?:random)\(/i,creator=o=>{const c=Object.assign({preserve:!1},o);return{postcssPlugin:"postcss-random-function",Declaration(o){if(!s.test(o.value))return;const r=e.calc(o.value,{precision:5,toCanonicalUnits:!0,randomSeed:o.source?.input.css.length});r!==o.value&&(o.cloneBefore({value:r}),c.preserve||o.remove())}}};creator.postcss=!0,module.exports=creator;
@@ -0,0 +1,12 @@
1
+ import type { PluginCreator } from 'postcss';
2
+
3
+ declare const creator: PluginCreator<pluginOptions>;
4
+ export default creator;
5
+
6
+ /** postcss-random-function plugin options */
7
+ export declare type pluginOptions = {
8
+ /** Preserve the original notation. default: false */
9
+ preserve?: boolean;
10
+ };
11
+
12
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{calc as s}from"@csstools/css-calc";const e=/(?<![-\w])(?:random)\(/i,creator=o=>{const t=Object.assign({preserve:!1},o);return{postcssPlugin:"postcss-random-function",Declaration(o){if(!e.test(o.value))return;const n=s(o.value,{precision:5,toCanonicalUnits:!0,randomSeed:o.source?.input.css.length});n!==o.value&&(o.cloneBefore({value:n}),t.preserve||o.remove())}}};creator.postcss=!0;export{creator as default};
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@csstools/postcss-random-function",
3
+ "description": "Use round, rem and mod functions in CSS",
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": ">=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-calc": "^2.1.0",
52
+ "@csstools/css-parser-algorithms": "^3.0.4",
53
+ "@csstools/css-tokenizer": "^3.0.3"
54
+ },
55
+ "peerDependencies": {
56
+ "postcss": "^8.4"
57
+ },
58
+ "scripts": {},
59
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-random-function#readme",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/csstools/postcss-plugins.git",
63
+ "directory": "plugins/postcss-random-function"
64
+ },
65
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
66
+ "keywords": [
67
+ "css",
68
+ "postcss-plugin",
69
+ "random"
70
+ ]
71
+ }