@csstools/postcss-media-minmax 1.0.0 → 1.0.1
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 +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@csstools/css-parser-algorithms"),i=require("@csstools/css-tokenizer"),n=require("@csstools/media-query-list-parser"),t=require("@csstools/css-calc");const a=/[A-Z]/g;const r={width:"px",height:"px","device-width":"px","device-height":"px","aspect-ratio":"","device-aspect-ratio":"",color:"","color-index":"",monochrome:"",resolution:"dpi"},o={width:!1,height:!1,"device-width":!1,"device-height":!1,"aspect-ratio":!1,"device-aspect-ratio":!1,color:!0,"color-index":!0,monochrome:!0,resolution:"dpi"};function featureNamePrefix(e){return e===n.MediaFeatureLT.LT||e===n.MediaFeatureLT.LT_OR_EQ?"max-":e===n.MediaFeatureGT.GT||e===n.MediaFeatureGT.GT_OR_EQ?"min-":""}const s={">":1,"<":-1},u=.001,d=.02;function transformSingleNameValuePair(a,l,c,p){let T=c.before,m=c.after;if(p||(T=c.after,m=c.before),!p){const e=n.invertComparison(l);if(!1===e)return;l=e}if(l===n.MediaFeatureEQ.EQ||l===n.MediaFeatureLT.LT_OR_EQ||l===n.MediaFeatureGT.GT_OR_EQ)return Array.isArray(c.value)?n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,...c.value.flatMap((e=>e.tokens())),...m):n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,...c.value.tokens(),...m);let v,f,y=!1;if(Array.isArray(c.value)){if(!n.matchesRatioExactly(c.value))return;if("aspect-ratio"!==a&&"device-aspect-ratio"!==a)return;const e=n.matchesRatio(c.value);if(-1===e)return;y=!0,v=c.value[e[0]],f=[...c.value.slice(e[0]+1).flatMap((e=>e.tokens()))]}else v=c.value,f=[];const h=r[a.toLowerCase()];if(e.isFunctionNode(v)
|
|
1
|
+
"use strict";var e=require("@csstools/css-parser-algorithms"),i=require("@csstools/css-tokenizer"),n=require("@csstools/media-query-list-parser"),t=require("@csstools/css-calc");const a=/[A-Z]/g;function toLowerCaseAZ(e){return e.replace(a,(e=>String.fromCharCode(e.charCodeAt(0)+32)))}const r={width:"px",height:"px","device-width":"px","device-height":"px","aspect-ratio":"","device-aspect-ratio":"",color:"","color-index":"",monochrome:"",resolution:"dpi"},o={width:!1,height:!1,"device-width":!1,"device-height":!1,"aspect-ratio":!1,"device-aspect-ratio":!1,color:!0,"color-index":!0,monochrome:!0,resolution:"dpi"};function featureNamePrefix(e){return e===n.MediaFeatureLT.LT||e===n.MediaFeatureLT.LT_OR_EQ?"max-":e===n.MediaFeatureGT.GT||e===n.MediaFeatureGT.GT_OR_EQ?"min-":""}const s={">":1,"<":-1},u=.001,d=.02;function transformSingleNameValuePair(a,l,c,p){let T=c.before,m=c.after;if(p||(T=c.after,m=c.before),!p){const e=n.invertComparison(l);if(!1===e)return;l=e}if(l===n.MediaFeatureEQ.EQ||l===n.MediaFeatureLT.LT_OR_EQ||l===n.MediaFeatureGT.GT_OR_EQ)return Array.isArray(c.value)?n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,...c.value.flatMap((e=>e.tokens())),...m):n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,...c.value.tokens(),...m);let v,f,y=!1;if(Array.isArray(c.value)){if(!n.matchesRatioExactly(c.value))return;if("aspect-ratio"!==a&&"device-aspect-ratio"!==a)return;const e=n.matchesRatio(c.value);if(-1===e)return;y=!0,v=c.value[e[0]],f=[...c.value.slice(e[0]+1).flatMap((e=>e.tokens()))]}else v=c.value,f=[];const h=r[a.toLowerCase()];if(e.isFunctionNode(v)){const r=toLowerCaseAZ(v.getName());if(t.mathFunctionNames.has(r)||"env"===r){const[[r]]=t.calcFromComponentValues([[v]],{precision:5,toCanonicalUnits:!0});if(!r||!e.isTokenNode(r)||r.value[0]!==i.TokenType.Number&&r.value[0]!==i.TokenType.Percentage&&r.value[0]!==i.TokenType.Dimension||!Number.isInteger(r.value[4].value)){let e;if(void 0!==h){const n=s[l]*("px"===h?d:u);e=[i.TokenType.Dimension,`${n.toString()}${h}`,-1,-1,{value:n,unit:h,type:i.NumberType.Integer}]}else if(!0===o[a]){const n=s[l];e=[i.TokenType.Number,n.toString(),-1,-1,{value:n,type:i.NumberType.Integer}]}else if(y){const n=s[l]*u;e=[i.TokenType.Number,n.toString(),-1,-1,{value:n,type:i.NumberType.Integer}]}else{const n=s[l];e=[i.TokenType.Number,n.toString(),-1,-1,{value:n,type:i.NumberType.Integer}]}return n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,[i.TokenType.Function,"calc(",-1,-1,{value:"calc("}],[i.TokenType.OpenParen,"(",-1,-1,void 0],...v.tokens().slice(1),[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.Delim,"+",-1,-1,{value:"+"}],[i.TokenType.Whitespace," ",-1,-1,void 0],e,[i.TokenType.CloseParen,")",-1,-1,void 0],...f,...m)}v=r}}if(!e.isTokenNode(v))return;let k,g=v.value,M="";if(void 0!==h&&g[0]===i.TokenType.Number&&0===g[4].value)k=s[l],M=h;else if(g[0]===i.TokenType.Number&&0===g[4].value)k=s[l],M="";else if(g[0]===i.TokenType.Dimension&&0===g[4].value)k=s[l],M=g[4].unit;else if(g[0]===i.TokenType.Number&&!0===o[a])k=g[4].value+s[l];else if(g[0]===i.TokenType.Dimension&&"px"===g[4].unit&&g[4].type===i.NumberType.Integer)k=Number(Math.round(Number(g[4].value+d*s[l]+"e6"))+"e-6");else{if(g[0]!==i.TokenType.Dimension&&g[0]!==i.TokenType.Number)return;k=Number(Math.round(Number(g[4].value+u*s[l]+"e6"))+"e-6")}return M&&(g=[i.TokenType.Dimension,g[1],g[2],g[3],{value:g[4].value,unit:M,type:g[4].type}]),g[4].value=k,g[0]===i.TokenType.Dimension?g[1]=g[4].value.toString()+g[4].unit:g[1]=g[4].value.toString(),n.newMediaFeaturePlain(featureNamePrefix(l)+a,...T,g,...f,...m)}const l=new Set(["aspect-ratio","color","color-index","device-aspect-ratio","device-height","device-width","height","horizontal-viewport-segments","monochrome","resolution","vertical-viewport-segments","width"]);function transform(t){return t.map(((t,a)=>{const r=e.gatherNodeAncestry(t);t.walk((e=>{const a=e.node;if(!n.isMediaFeatureRange(a))return;const o=e.parent;if(!n.isMediaFeature(o))return;const s=toLowerCaseAZ(a.name.getName());if(!l.has(s))return;if(n.isMediaFeatureRangeNameValue(a)||n.isMediaFeatureRangeValueName(a)){const e=a.operatorKind();if(!1===e)return;const i=transformSingleNameValuePair(s,e,a.value,n.isMediaFeatureRangeNameValue(a));return void(i&&(o.feature=i.feature))}const u=r.get(o);if(!n.isMediaInParens(u))return;let d=null,c=null;{const e=a.valueOneOperatorKind();if(!1===e)return;const i=transformSingleNameValuePair(s,e,a.valueOne,!1);if(!i)return;e===n.MediaFeatureLT.LT||e===n.MediaFeatureLT.LT_OR_EQ?(d=i,d.before=o.before):(c=i,c.after=o.after)}{const e=a.valueTwoOperatorKind();if(!1===e)return;const i=transformSingleNameValuePair(s,e,a.valueTwo,!0);if(!i)return;e===n.MediaFeatureLT.LT||e===n.MediaFeatureLT.LT_OR_EQ?(c=i,c.before=o.before):(d=i,d.after=o.after)}if(!d||!c)return;const p=new n.MediaInParens(d),T=new n.MediaInParens(c),m=getMediaConditionListWithAndFromAncestry(u,r);if(m)return m.leading===u?(m.leading=p,void(m.list=[new n.MediaAnd([[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.Ident,"and",-1,-1,{value:"and"}],[i.TokenType.Whitespace," ",-1,-1,void 0]],T),...m.list])):void m.list.splice(m.indexOf(r.get(u)),1,new n.MediaAnd([[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.Ident,"and",-1,-1,{value:"and"}],[i.TokenType.Whitespace," ",-1,-1,void 0]],p),new n.MediaAnd([[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.Ident,"and",-1,-1,{value:"and"}],[i.TokenType.Whitespace," ",-1,-1,void 0]],T));const v=new n.MediaConditionListWithAnd(p,[new n.MediaAnd([[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.Ident,"and",-1,-1,{value:"and"}],[i.TokenType.Whitespace," ",-1,-1,void 0]],T)],[[i.TokenType.Whitespace," ",-1,-1,void 0]]),f=getMediaConditionInShallowMediaQueryFromAncestry(u,t,r);f?f.media=v:u.media=new n.MediaCondition(new n.MediaInParens(new n.MediaCondition(v),[[i.TokenType.Whitespace," ",-1,-1,void 0],[i.TokenType.OpenParen,"(",-1,-1,void 0]],[[i.TokenType.CloseParen,")",-1,-1,void 0]]))}));const o=t.tokens();return i.stringify(...o.filter(((e,n)=>(0!==n||0!==a||e[0]!==i.TokenType.Whitespace)&&(e[0]!==i.TokenType.Whitespace||!o[n+1]||o[n+1][0]!==i.TokenType.Whitespace))))})).join(",")}function getMediaConditionListWithAndFromAncestry(e,i){let t=e;if(t){if(t=i.get(t),n.isMediaConditionListWithAnd(t))return t;if(n.isMediaAnd(t))return t=i.get(t),n.isMediaConditionListWithAnd(t)?t:void 0}}function getMediaConditionInShallowMediaQueryFromAncestry(e,i,t){let a=e;if(!a)return;if(a=t.get(a),!n.isMediaCondition(a))return;const r=a;return a=t.get(a),n.isMediaQuery(a)&&a===i?r:void 0}const creator=()=>({postcssPlugin:"postcss-media-minmax",AtRule:{media:e=>{if(!(e.params.includes("<")||e.params.includes(">")||e.params.includes("=")))return;const i=transform(n.parse(e.params,{preserveInvalidMediaQueries:!0,onParseError:()=>{throw e.error(`Unable to parse media query "${e.params}"`)}}));e.params!==i&&(e.params=i)}}});creator.postcss=!0,module.exports=creator;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isFunctionNode as e,isTokenNode as t,gatherNodeAncestry as r}from"@csstools/css-parser-algorithms";import{TokenType as i,NumberType as n,stringify as a}from"@csstools/css-tokenizer";import{invertComparison as o,MediaFeatureEQ as s,MediaFeatureLT as u,MediaFeatureGT as l,newMediaFeaturePlain as c,matchesRatioExactly as d,matchesRatio as f,isMediaFeatureRange as
|
|
1
|
+
import{isFunctionNode as e,isTokenNode as t,gatherNodeAncestry as r}from"@csstools/css-parser-algorithms";import{TokenType as i,NumberType as n,stringify as a}from"@csstools/css-tokenizer";import{invertComparison as o,MediaFeatureEQ as s,MediaFeatureLT as u,MediaFeatureGT as l,newMediaFeaturePlain as c,matchesRatioExactly as d,matchesRatio as f,isMediaFeatureRange as v,isMediaFeature as m,isMediaFeatureRangeNameValue as p,isMediaFeatureRangeValueName as h,isMediaInParens as g,MediaInParens as w,MediaAnd as N,MediaConditionListWithAnd as b,MediaCondition as y,isMediaConditionListWithAnd as x,isMediaAnd as W,isMediaCondition as A,isMediaQuery as P,parse as C}from"@csstools/media-query-list-parser";import{mathFunctionNames as S,calcFromComponentValues as I}from"@csstools/css-calc";const L=/[A-Z]/g;function toLowerCaseAZ(e){return e.replace(L,(e=>String.fromCharCode(e.charCodeAt(0)+32)))}const O={width:"px",height:"px","device-width":"px","device-height":"px","aspect-ratio":"","device-aspect-ratio":"",color:"","color-index":"",monochrome:"",resolution:"dpi"},T={width:!1,height:!1,"device-width":!1,"device-height":!1,"aspect-ratio":!1,"device-aspect-ratio":!1,color:!0,"color-index":!0,monochrome:!0,resolution:"dpi"};function featureNamePrefix(e){return e===u.LT||e===u.LT_OR_EQ?"max-":e===l.GT||e===l.GT_OR_EQ?"min-":""}const _={">":1,"<":-1},M=.001,Q=.02;function transformSingleNameValuePair(r,a,v,m){let p=v.before,h=v.after;if(m||(p=v.after,h=v.before),!m){const e=o(a);if(!1===e)return;a=e}if(a===s.EQ||a===u.LT_OR_EQ||a===l.GT_OR_EQ)return Array.isArray(v.value)?c(featureNamePrefix(a)+r,...p,...v.value.flatMap((e=>e.tokens())),...h):c(featureNamePrefix(a)+r,...p,...v.value.tokens(),...h);let g,w,N=!1;if(Array.isArray(v.value)){if(!d(v.value))return;if("aspect-ratio"!==r&&"device-aspect-ratio"!==r)return;const e=f(v.value);if(-1===e)return;N=!0,g=v.value[e[0]],w=[...v.value.slice(e[0]+1).flatMap((e=>e.tokens()))]}else g=v.value,w=[];const b=O[r.toLowerCase()];if(e(g)){const e=toLowerCaseAZ(g.getName());if(S.has(e)||"env"===e){const[[e]]=I([[g]],{precision:5,toCanonicalUnits:!0});if(!e||!t(e)||e.value[0]!==i.Number&&e.value[0]!==i.Percentage&&e.value[0]!==i.Dimension||!Number.isInteger(e.value[4].value)){let e;if(void 0!==b){const t=_[a]*("px"===b?Q:M);e=[i.Dimension,`${t.toString()}${b}`,-1,-1,{value:t,unit:b,type:n.Integer}]}else if(!0===T[r]){const t=_[a];e=[i.Number,t.toString(),-1,-1,{value:t,type:n.Integer}]}else if(N){const t=_[a]*M;e=[i.Number,t.toString(),-1,-1,{value:t,type:n.Integer}]}else{const t=_[a];e=[i.Number,t.toString(),-1,-1,{value:t,type:n.Integer}]}return c(featureNamePrefix(a)+r,...p,[i.Function,"calc(",-1,-1,{value:"calc("}],[i.OpenParen,"(",-1,-1,void 0],...g.tokens().slice(1),[i.Whitespace," ",-1,-1,void 0],[i.Delim,"+",-1,-1,{value:"+"}],[i.Whitespace," ",-1,-1,void 0],e,[i.CloseParen,")",-1,-1,void 0],...w,...h)}g=e}}if(!t(g))return;let y,x=g.value,W="";if(void 0!==b&&x[0]===i.Number&&0===x[4].value)y=_[a],W=b;else if(x[0]===i.Number&&0===x[4].value)y=_[a],W="";else if(x[0]===i.Dimension&&0===x[4].value)y=_[a],W=x[4].unit;else if(x[0]===i.Number&&!0===T[r])y=x[4].value+_[a];else if(x[0]===i.Dimension&&"px"===x[4].unit&&x[4].type===n.Integer)y=Number(Math.round(Number(x[4].value+Q*_[a]+"e6"))+"e-6");else{if(x[0]!==i.Dimension&&x[0]!==i.Number)return;y=Number(Math.round(Number(x[4].value+M*_[a]+"e6"))+"e-6")}return W&&(x=[i.Dimension,x[1],x[2],x[3],{value:x[4].value,unit:W,type:x[4].type}]),x[4].value=y,x[0]===i.Dimension?x[1]=x[4].value.toString()+x[4].unit:x[1]=x[4].value.toString(),c(featureNamePrefix(a)+r,...p,x,...w,...h)}const D=new Set(["aspect-ratio","color","color-index","device-aspect-ratio","device-height","device-width","height","horizontal-viewport-segments","monochrome","resolution","vertical-viewport-segments","width"]);function transform(e){return e.map(((e,t)=>{const n=r(e);e.walk((t=>{const r=t.node;if(!v(r))return;const a=t.parent;if(!m(a))return;const o=toLowerCaseAZ(r.name.getName());if(!D.has(o))return;if(p(r)||h(r)){const e=r.operatorKind();if(!1===e)return;const t=transformSingleNameValuePair(o,e,r.value,p(r));return void(t&&(a.feature=t.feature))}const s=n.get(a);if(!g(s))return;let l=null,c=null;{const e=r.valueOneOperatorKind();if(!1===e)return;const t=transformSingleNameValuePair(o,e,r.valueOne,!1);if(!t)return;e===u.LT||e===u.LT_OR_EQ?(l=t,l.before=a.before):(c=t,c.after=a.after)}{const e=r.valueTwoOperatorKind();if(!1===e)return;const t=transformSingleNameValuePair(o,e,r.valueTwo,!0);if(!t)return;e===u.LT||e===u.LT_OR_EQ?(c=t,c.before=a.before):(l=t,l.after=a.after)}if(!l||!c)return;const d=new w(l),f=new w(c),x=getMediaConditionListWithAndFromAncestry(s,n);if(x)return x.leading===s?(x.leading=d,void(x.list=[new N([[i.Whitespace," ",-1,-1,void 0],[i.Ident,"and",-1,-1,{value:"and"}],[i.Whitespace," ",-1,-1,void 0]],f),...x.list])):void x.list.splice(x.indexOf(n.get(s)),1,new N([[i.Whitespace," ",-1,-1,void 0],[i.Ident,"and",-1,-1,{value:"and"}],[i.Whitespace," ",-1,-1,void 0]],d),new N([[i.Whitespace," ",-1,-1,void 0],[i.Ident,"and",-1,-1,{value:"and"}],[i.Whitespace," ",-1,-1,void 0]],f));const W=new b(d,[new N([[i.Whitespace," ",-1,-1,void 0],[i.Ident,"and",-1,-1,{value:"and"}],[i.Whitespace," ",-1,-1,void 0]],f)],[[i.Whitespace," ",-1,-1,void 0]]),A=getMediaConditionInShallowMediaQueryFromAncestry(s,e,n);A?A.media=W:s.media=new y(new w(new y(W),[[i.Whitespace," ",-1,-1,void 0],[i.OpenParen,"(",-1,-1,void 0]],[[i.CloseParen,")",-1,-1,void 0]]))}));const o=e.tokens();return a(...o.filter(((e,r)=>(0!==r||0!==t||e[0]!==i.Whitespace)&&(e[0]!==i.Whitespace||!o[r+1]||o[r+1][0]!==i.Whitespace))))})).join(",")}function getMediaConditionListWithAndFromAncestry(e,t){let r=e;if(r){if(r=t.get(r),x(r))return r;if(W(r))return r=t.get(r),x(r)?r:void 0}}function getMediaConditionInShallowMediaQueryFromAncestry(e,t,r){let i=e;if(!i)return;if(i=r.get(i),!A(i))return;const n=i;return i=r.get(i),P(i)&&i===t?n:void 0}const creator=()=>({postcssPlugin:"postcss-media-minmax",AtRule:{media:e=>{if(!(e.params.includes("<")||e.params.includes(">")||e.params.includes("=")))return;const t=transform(C(e.params,{preserveInvalidMediaQueries:!0,onParseError:()=>{throw e.error(`Unable to parse media query "${e.params}"`)}}));e.params!==t&&(e.params=t)}}});creator.postcss=!0;export{creator as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csstools/postcss-media-minmax",
|
|
3
3
|
"description": "Use the range notation in CSS media queries",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@csstools/css-calc": "^1.0
|
|
45
|
+
"@csstools/css-calc": "^1.1.0",
|
|
46
46
|
"@csstools/css-parser-algorithms": "^2.1.0",
|
|
47
47
|
"@csstools/css-tokenizer": "^2.1.0",
|
|
48
|
-
"@csstools/media-query-list-parser": "^2.0.
|
|
48
|
+
"@csstools/media-query-list-parser": "^2.0.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"postcss": "^8.4"
|