@csstools/postcss-progressive-custom-properties 1.0.0 → 1.1.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 +6 -1
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/match.d.ts +1 -0
- package/dist/matchers.d.ts +30 -0
- package/dist/support-conditions-from-values.d.ts +1 -0
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changes to PostCSS Progressive Custom Properties
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.1.0 (February 12, 2022)
|
|
4
|
+
|
|
5
|
+
- No longer uses custom properties in `@supports` rules.
|
|
6
|
+
- Implement AST matching for values and units and generate minimal `@supports` for select features.
|
|
7
|
+
|
|
8
|
+
## 1.0.0 (February 6, 2022)
|
|
4
9
|
|
|
5
10
|
Initial release
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ The solution is to wrap Custom Property declarations in an `@supports` rule.
|
|
|
28
28
|
--a-color: red;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
@supports (
|
|
31
|
+
@supports (color: oklch(0% 0 0)) {
|
|
32
32
|
:root {
|
|
33
33
|
--a-color: oklch(40% 0.234 0.39 / var(--opacity-50));
|
|
34
34
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=()=>({postcssPlugin:"postcss-progressive-custom-properties",RuleExit:(e,{postcss:r})=>{const s=[],t=new Set;e.each((o=>{if("decl"!==o.type)return;if(!o.variable)return;if("initial"===o.value.trim())return;if(""===o.value.trim())return;if(!t.has(o.prop.toString()))return void t.add(o.prop.toString());const n=r.atRule({name:"supports",params:`(${o.prop}: ${o.value})`,source:e.source,raws:{before:"\n\n",after:"\n"}}),p=e.clone();p.removeAll(),p.raws.before="\n",p.append(o.clone()),o.remove(),n.append(p),s.push(n)})),0!==s.length&&s.reverse().forEach((r=>{e.after(r)}))}});e.postcss=!0,module.exports=e;
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=e(require("postcss-value-parser"));const r=[{supports:"color(srgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"srgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"srgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(srgb-linear 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"srgb-linear"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"srgb-linear"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(a98-rgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"a98-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"a98-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(prophoto-rgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"prophoto-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"prophoto-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(display-p3 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"display-p3"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"display-p3"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(rec2020 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"rec2020"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"rec2020"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz-d50 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d50"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d50"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz-d65 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d65"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d65"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hsl(0, 0%, 0%)",property:"color",sniff:"hsl",matchers:[{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]},{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]}]},{supports:"hsl(0 0% 0% / 0)",property:"color",sniff:"hsl",matchers:[{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hsla(0 0% 0% / 0)",property:"color",sniff:"hsla",matchers:[{type:"function",value:"hsla",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hwb(0 0% 0%)",property:"color",sniff:"hwb",matchers:[{type:"function",value:"hwb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"hwb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"lab(0% 0 0)",property:"color",sniff:"lab",matchers:[{type:"function",value:"lab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"lab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"lch(0% 0 0)",property:"color",sniff:"lch",matchers:[{type:"function",value:"lch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"lch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"oklab(0% 0 0)",property:"color",sniff:"oklab",matchers:[{type:"function",value:"oklab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"oklab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"oklch(0% 0 0)",property:"color",sniff:"oklch",matchers:[{type:"function",value:"oklch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"oklch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"rgb(0, 0, 0, 0)",property:"color",sniff:"rgb",matchers:[{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]},{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]}]},{supports:"rgb(0 0 0 / 0)",property:"color",sniff:"rgb",matchers:[{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"rgba(0 0 0 / 0)",property:"color",sniff:"rgba",matchers:[{type:"function",value:"rgba",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"1ic",property:"font-size",sniff:"ic",matchers:[{type:"word",value:"1ic",dimension:{number:"1",unit:"ic"}}]}];function p(e,a){if(e.isVariable&&a)return!0;if(e.type!==a.type)return!1;if(function(e,a){if("space"===e.type&&"space"===a.type&&e.value.trim()===a.value.trim())return!1;if(e.dimension&&a.dimension)return e.dimension.unit!==a.dimension.unit;if(e.value!==a.value)return!0;return!1}(e,a))return!1;if(e.nodes&&a.nodes){if(e.nodes.length!==a.nodes.length)return!1;for(let r=0;r<e.nodes.length;r++)if(!p(e.nodes[r],a.nodes[r]))return!1;return!0}return!0}const t=()=>({postcssPlugin:"postcss-progressive-custom-properties",RuleExit:(e,{postcss:t})=>{const o=[],i=new Set;e.each((l=>{if("decl"!==l.type)return;if(!l.variable)return;if("initial"===l.value.trim())return;if(""===l.value.trim())return;if(!i.has(l.prop.toString()))return void i.add(l.prop.toString());const s=function(e){const t=[],o=[];r.forEach((a=>{e.indexOf(a.sniff)>-1&&o.push(a)}));try{a.default(e).walk((e=>{try{e.dimension=a.default.unit(e.value)}finally{!1===e.dimension&&delete e.dimension}for(let a=0;a<o.length;a++){const r=o[a];for(let a=0;a<r.matchers.length;a++)if(p(r.matchers[a],e))return void t.push(`(${r.property}: ${r.supports})`)}if("function"===e.type&&("conic-gradient"===e.value||"linear-gradient"===e.value)){let a=0,r=!1;for(let p=0;p<e.nodes.length;p++){const o=e.nodes[p];if("div"!==o.type||","!==o.value.trim()){if("word"!==o.type&&"function"!==o.type||a++,r&&3===a)return"conic-gradient"===e.value?void t.push("(background: conic-gradient(red 0%, red 0deg 1%, red 2deg))"):void t.push("(background: linear-gradient(0deg, red 0% 1%, red 2%))")}else a=0,r=!0}}}))}catch(e){}return t}(l.value);if(!s.length)return;const y=t.atRule({name:"supports",params:s.join(" and "),source:e.source,raws:{before:"\n\n",after:"\n"}}),u=e.clone();u.removeAll(),u.raws.before="\n",u.append(l.clone()),l.remove(),y.append(u),o.push(y)})),0!==o.length&&o.reverse().forEach((a=>{e.after(a)}))}});t.postcss=!0,module.exports=t;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=()=>({postcssPlugin:"postcss-progressive-custom-properties",RuleExit:(e,{postcss:r})=>{const t=[],s=new Set;e.each((o=>{if("decl"!==o.type)return;if(!o.variable)return;if("initial"===o.value.trim())return;if(""===o.value.trim())return;if(!s.has(o.prop.toString()))return void s.add(o.prop.toString());const n=r.atRule({name:"supports",params:`(${o.prop}: ${o.value})`,source:e.source,raws:{before:"\n\n",after:"\n"}}),p=e.clone();p.removeAll(),p.raws.before="\n",p.append(o.clone()),o.remove(),n.append(p),t.push(n)})),0!==t.length&&t.reverse().forEach((r=>{e.after(r)}))}});e.postcss=!0;export{e as default};
|
|
1
|
+
import e from"postcss-value-parser";const a=[{supports:"color(srgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"srgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"srgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(srgb-linear 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"srgb-linear"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"srgb-linear"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(a98-rgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"a98-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"a98-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(prophoto-rgb 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"prophoto-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"prophoto-rgb"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(display-p3 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"display-p3"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"display-p3"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(rec2020 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"rec2020"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"rec2020"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz-d50 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d50"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d50"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz-d65 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d65"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz-d65"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"color(xyz 0 0 0)",property:"color",sniff:"color",matchers:[{type:"function",value:"color",nodes:[{type:"word",value:"xyz"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"color",nodes:[{type:"word",value:"xyz"},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hsl(0, 0%, 0%)",property:"color",sniff:"hsl",matchers:[{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]},{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]}]},{supports:"hsl(0 0% 0% / 0)",property:"color",sniff:"hsl",matchers:[{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"hsl",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hsla(0 0% 0% / 0)",property:"color",sniff:"hsla",matchers:[{type:"function",value:"hsla",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"hwb(0 0% 0%)",property:"color",sniff:"hwb",matchers:[{type:"function",value:"hwb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"hwb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"lab(0% 0 0)",property:"color",sniff:"lab",matchers:[{type:"function",value:"lab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"lab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"lch(0% 0 0)",property:"color",sniff:"lch",matchers:[{type:"function",value:"lch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"lch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"oklab(0% 0 0)",property:"color",sniff:"oklab",matchers:[{type:"function",value:"oklab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"oklab",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"oklch(0% 0 0)",property:"color",sniff:"oklch",matchers:[{type:"function",value:"oklch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"oklch",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"rgb(0, 0, 0, 0)",property:"color",sniff:"rgb",matchers:[{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]},{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0},{type:"div",value:","},{type:"word",isVariable:!0}]}]},{supports:"rgb(0 0 0 / 0)",property:"color",sniff:"rgb",matchers:[{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0}]},{type:"function",value:"rgb",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"rgba(0 0 0 / 0)",property:"color",sniff:"rgba",matchers:[{type:"function",value:"rgba",nodes:[{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"space",value:" "},{type:"word",isVariable:!0},{type:"div",value:"/"},{type:"word",isVariable:!0}]}]},{supports:"1ic",property:"font-size",sniff:"ic",matchers:[{type:"word",value:"1ic",dimension:{number:"1",unit:"ic"}}]}];function r(e,a){if(e.isVariable&&a)return!0;if(e.type!==a.type)return!1;if(function(e,a){if("space"===e.type&&"space"===a.type&&e.value.trim()===a.value.trim())return!1;if(e.dimension&&a.dimension)return e.dimension.unit!==a.dimension.unit;if(e.value!==a.value)return!0;return!1}(e,a))return!1;if(e.nodes&&a.nodes){if(e.nodes.length!==a.nodes.length)return!1;for(let p=0;p<e.nodes.length;p++)if(!r(e.nodes[p],a.nodes[p]))return!1;return!0}return!0}const p=()=>({postcssPlugin:"postcss-progressive-custom-properties",RuleExit:(p,{postcss:t})=>{const o=[],i=new Set;p.each((l=>{if("decl"!==l.type)return;if(!l.variable)return;if("initial"===l.value.trim())return;if(""===l.value.trim())return;if(!i.has(l.prop.toString()))return void i.add(l.prop.toString());const s=function(p){const t=[],o=[];a.forEach((e=>{p.indexOf(e.sniff)>-1&&o.push(e)}));try{e(p).walk((a=>{try{a.dimension=e.unit(a.value)}finally{!1===a.dimension&&delete a.dimension}for(let e=0;e<o.length;e++){const p=o[e];for(let e=0;e<p.matchers.length;e++)if(r(p.matchers[e],a))return void t.push(`(${p.property}: ${p.supports})`)}if("function"===a.type&&("conic-gradient"===a.value||"linear-gradient"===a.value)){let e=0,r=!1;for(let p=0;p<a.nodes.length;p++){const o=a.nodes[p];if("div"!==o.type||","!==o.value.trim()){if("word"!==o.type&&"function"!==o.type||e++,r&&3===e)return"conic-gradient"===a.value?void t.push("(background: conic-gradient(red 0%, red 0deg 1%, red 2deg))"):void t.push("(background: linear-gradient(0deg, red 0% 1%, red 2%))")}else e=0,r=!0}}}))}catch(e){}return t}(l.value);if(!s.length)return;const y=t.atRule({name:"supports",params:s.join(" and "),source:p.source,raws:{before:"\n\n",after:"\n"}}),u=p.clone();u.removeAll(),u.raws.before="\n",u.append(l.clone()),l.remove(),y.append(u),o.push(y)})),0!==o.length&&o.reverse().forEach((e=>{p.after(e)}))}});p.postcss=!0;export{p as default};
|
package/dist/match.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function matches(a: any, b: any): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const matchers: ({
|
|
2
|
+
supports: string;
|
|
3
|
+
property: string;
|
|
4
|
+
sniff: string;
|
|
5
|
+
matchers: {
|
|
6
|
+
type: string;
|
|
7
|
+
value: string;
|
|
8
|
+
nodes: ({
|
|
9
|
+
type: string;
|
|
10
|
+
value: string;
|
|
11
|
+
isVariable?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
type: string;
|
|
14
|
+
isVariable: boolean;
|
|
15
|
+
value?: undefined;
|
|
16
|
+
})[];
|
|
17
|
+
}[];
|
|
18
|
+
} | {
|
|
19
|
+
supports: string;
|
|
20
|
+
property: string;
|
|
21
|
+
sniff: string;
|
|
22
|
+
matchers: {
|
|
23
|
+
type: string;
|
|
24
|
+
value: string;
|
|
25
|
+
dimension: {
|
|
26
|
+
number: string;
|
|
27
|
+
unit: string;
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
30
|
+
})[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function supportConditionsFromValue(value: string): Array<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csstools/postcss-progressive-custom-properties",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Correctly declare progressive enhancements for CSS Custom Properties.",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "rollup -c ../../rollup/default.js",
|
|
27
|
+
"build": "node ./generate/matchers.mjs && eslint --fix ./src/matchers.ts && rollup -c ../../rollup/default.js",
|
|
28
28
|
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
|
|
29
29
|
"lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
|
|
30
30
|
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
"test:cli": "bash ./test/cli/test.sh",
|
|
35
35
|
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
|
|
36
36
|
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"postcss-value-parser": "^4.2.0"
|
|
39
|
+
},
|
|
37
40
|
"peerDependencies": {
|
|
38
41
|
"postcss": "^8.3"
|
|
39
42
|
},
|