2 lines
36 KiB
JavaScript
2 lines
36 KiB
JavaScript
import{walkerIndexGenerator as e,ComponentValueType as t,TokenNode as i,parseListOfComponentValues as a,isWhitespaceNode as n,isCommentNode as r,isTokenNode as s,isSimpleBlockNode as o,parseCommaSeparatedListOfComponentValues as u}from"@csstools/css-parser-algorithms";import{stringify as d,TokenType as l,mutateIdent as h,tokenizer as m,cloneTokens as f}from"@csstools/css-tokenizer";var c;!function(e){e.CustomMedia="custom-media",e.GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid"}(c||(c={}));class MediaCondition{type=c.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===c.MediaCondition)}}class MediaInParens{type=c.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return d(...this.before)+this.media.toString()+d(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&("walk"in this.media?this.media.walk(e,i):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===c.MediaInParens)}}class MediaQueryWithType{type=c.MediaQueryWithType;modifier;mediaType;and=void 0;media=void 0;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;e<this.modifier.length;e++){const t=this.modifier[e];if(t[0]===l.Ident)return t[4].value}return""}negateQuery(){const e=new MediaQueryWithType([...this.modifier],[...this.mediaType],this.and,this.media);if(0===e.modifier.length)return e.modifier=[[l.Ident,"not",-1,-1,{value:"not"}],[l.Whitespace," ",-1,-1,void 0]],e;for(let t=0;t<e.modifier.length;t++){const i=e.modifier[t];if(i[0]===l.Ident&&"not"===i[4].value.toLowerCase()){e.modifier.splice(t,1);break}if(i[0]===l.Ident&&"only"===i[4].value.toLowerCase()){i[1]="not",i[4].value="not";break}}return e}getMediaType(){if(!this.mediaType.length)return"";for(let e=0;e<this.mediaType.length;e++){const t=this.mediaType[e];if(t[0]===l.Ident)return t[4].value}return""}tokens(){return this.and&&this.media?[...this.modifier,...this.mediaType,...this.and,...this.media.tokens()]:[...this.modifier,...this.mediaType]}toString(){return this.and&&this.media?d(...this.modifier)+d(...this.mediaType)+d(...this.and)+this.media.toString():d(...this.modifier)+d(...this.mediaType)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;if(t&&(i={...t}),this.media)return!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,string:this.toString(),modifier:this.modifier,mediaType:this.mediaType,and:this.and,media:this.media}}isMediaQueryWithType(){return MediaQueryWithType.isMediaQueryWithType(this)}static isMediaQueryWithType(e){return!!e&&(e instanceof MediaQueryWithType&&e.type===c.MediaQueryWithType)}}class MediaQueryWithoutType{type=c.MediaQueryWithoutType;media;constructor(e){this.media=e}negateQuery(){let e=this.media;if(e.media.type===c.MediaNot)return new MediaQueryWithoutType(new MediaCondition(e.media.media));e.media.type===c.MediaConditionListWithOr&&(e=new MediaCondition(new MediaInParens(e,[[l.Whitespace," ",0,0,void 0],[l.OpenParen,"(",0,0,void 0]],[[l.CloseParen,")",0,0,void 0]])));return new MediaQueryWithType([[l.Ident,"not",0,0,{value:"not"}],[l.Whitespace," ",0,0,void 0]],[[l.Ident,"all",0,0,{value:"all"}],[l.Whitespace," ",0,0,void 0]],[[l.Ident,"and",0,0,{value:"and"}]],e)}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryWithoutType(){return MediaQueryWithoutType.isMediaQueryWithoutType(this)}static isMediaQueryWithoutType(e){return!!e&&(e instanceof MediaQueryWithoutType&&e.type===c.MediaQueryWithoutType)}}class MediaQueryInvalid{type=c.MediaQueryInvalid;media;constructor(e){this.media=e}negateQuery(){return new MediaQueryInvalid(this.media)}tokens(){return this.media.flatMap((e=>e.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(t,i){if(0===this.media.length)return;const a=e(this.media);let n=0;for(;n<this.media.length;){const e=this.media[n];let r;if(i&&(r={...i}),!1===t({node:e,parent:this,state:r},n))return!1;if("walk"in e&&this.media.includes(e)&&!1===e.walk(t,r))return!1;if(n=a(this.media,e,n),-1===n)break}}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===c.MediaQueryInvalid)}}class GeneralEnclosed{type=c.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.value,parent:this,state:i},"value")&&("walk"in this.value?this.value.walk(e,i):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===c.GeneralEnclosed)}}class MediaAnd{type=c.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return d(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){return"media"===e?this.media:null}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===c.MediaAnd)}}class MediaConditionListWithAnd{type=c.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return d(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+d(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(t,i){let a;if(i&&(a={...i}),!1===t({node:this.leading,parent:this,state:a},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(t,a))return!1;if(0===this.list.length)return;const n=e(this.list);let r=0;for(;r<this.list.length;){const e=this.list[r];if(i&&(a={...i}),!1===t({node:e,parent:this,state:a},r))return!1;if("walk"in e&&this.list.includes(e)&&!1===e.walk(t,a))return!1;if(r=n(this.list,e,r),-1===r)break}}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===c.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=c.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return d(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+d(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(t,i){let a;if(i&&(a={...i}),!1===t({node:this.leading,parent:this,state:a},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(t,a))return!1;if(0===this.list.length)return;const n=e(this.list);let r=0;for(;r<this.list.length;){const e=this.list[r];if(i&&(a={...i}),!1===t({node:e,parent:this,state:a},r))return!1;if("walk"in e&&this.list.includes(e)&&!1===e.walk(t,a))return!1;if(r=n(this.list,e,r),-1===r)break}}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===c.MediaConditionListWithOr)}}function isNumber(e){return!!(e.type===t.Token&&e.value[0]===l.Number||e.type===t.Function&&M.has(e.name[4].value.toLowerCase()))}const M=new Set(["abs","acos","asin","atan","atan2","calc","clamp","cos","exp","hypot","log","max","min","mod","pow","rem","round","sign","sin","sqrt","tan"]);function isDimension(e){return e.type===t.Token&&e.value[0]===l.Dimension}function isIdent(e){return e.type===t.Token&&e.value[0]===l.Ident}const p=/^env$/i;function isEnvironmentVariable(e){return!(e.type!==t.Function||!p.test(e.name[4].value))}class MediaFeatureName{type=c.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return d(...this.before)+this.name.toString()+d(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===c.MediaFeatureName)}}function parseMediaFeatureName(e){let i=-1;for(let a=0;a<e.length;a++){const n=e[a];if(n.type!==t.Whitespace&&n.type!==t.Comment){if(!isIdent(n))return!1;if(-1!==i)return!1;i=a}}return-1!==i&&new MediaFeatureName(e[i],e.slice(0,i).flatMap((e=>e.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=c.MediaFeatureBoolean;name;constructor(e){this.name=e}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return this.name.tokens()}toString(){return this.name.toString()}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.name.toJSON(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===c.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t)}class MediaFeatureValue{type=c.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?d(...this.before)+this.value.map((e=>e.toString())).join("")+d(...this.after):d(...this.before)+this.value.toString()+d(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){return"value"===e?this.value:Array.isArray(this.value)&&"number"==typeof e?(e<0&&(e=this.value.length+e),this.value[e]):void 0}walk(t,i){if(Array.isArray(this.value)){if(0===this.value.length)return;const a=e(this.value);let n=0;for(;n<this.value.length;){const e=this.value[n];let r;if(i&&(r={...i}),!1===t({node:e,parent:this,state:r},n))return!1;if("walk"in e&&this.value.includes(e)&&!1===e.walk(t,r))return!1;if(n=a(this.value,e,n),-1===n)break}}else{let e;if(i&&(e={...i}),!1===t({node:this.value,parent:this,state:e},"value"))return!1;if("walk"in this.value)return this.value.walk(t,e)}}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===c.MediaFeatureValue)}}function parseMediaFeatureValue(e,i=!1){let a=-1,n=-1;for(let r=0;r<e.length;r++){const s=e[r];if(s.type!==t.Whitespace&&s.type!==t.Comment){if(-1!==a)return!1;if(isNumber(s)){const t=matchesRatioExactly(e.slice(r));if(-1!==t){a=t[0]+r,n=t[1]+r,r+=t[1]-t[0];continue}a=r,n=r}else if(isEnvironmentVariable(s))a=r,n=r;else if(isDimension(s))a=r,n=r;else{if(i||!isIdent(s))return!1;a=r,n=r}}}return-1!==a&&new MediaFeatureValue(e.slice(a,n+1),e.slice(0,a).flatMap((e=>e.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t<e.length;t++){const i=e[t];if("whitespace"!==i.type&&"comment"!==i.type)return-1}return[t,i]}function matchesRatio(e){let t=-1,i=-1;for(let a=0;a<e.length;a++){const n=e[a];if("whitespace"!==n.type&&"comment"!==n.type){if("token"===n.type){const e=n.value;if(e[0]===l.Delim&&"/"===e[4].value){if(-1===t)return-1;if(-1!==i)return-1;i=a;continue}}if(!isNumber(n))return-1;if(-1!==i)return[t,a];if(-1!==t)return-1;t=a}}return-1}class MediaFeaturePlain{type=c.MediaFeaturePlain;name;colon;value;constructor(e,t,i){this.name=e,this.colon=t,this.value=i}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return[...this.name.tokens(),this.colon,...this.value.tokens()]}toString(){return this.name.toString()+d(this.colon)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.value,parent:this,state:i},"value")&&this.value.walk(e,i)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeaturePlain(){return MediaFeaturePlain.isMediaFeaturePlain(this)}static isMediaFeaturePlain(e){return!!e&&(e instanceof MediaFeaturePlain&&e.type===c.MediaFeaturePlain)}}function parseMediaFeaturePlain(e){let i=[],a=[],n=null;for(let r=0;r<e.length;r++){const s=e[r];if(s.type===t.Token){const t=s.value;if(t[0]===l.Colon){i=e.slice(0,r),a=e.slice(r+1),n=t;break}}}if(!i.length||!a.length||!n)return!1;const r=parseMediaFeatureName(i);if(!1===r)return!1;const s=parseMediaFeatureValue(a);return!1!==s&&new MediaFeaturePlain(r,n,s)}var y,v,g,k;function matchesComparison(e){let i=-1;for(let a=0;a<e.length;a++){const n=e[a];if(n.type===t.Token){const e=n.value;if(e[0]===l.Delim){if(e[4].value===g.EQ)return-1!==i?[i,a]:[a,a];if(e[4].value===y.LT){i=a;continue}if(e[4].value===v.GT){i=a;continue}}}break}return-1!==i&&[i,i]}function comparisonFromTokens(e){if(0===e.length||e.length>2)return!1;if(e[0][0]!==l.Delim)return!1;if(1===e.length)switch(e[0][4].value){case g.EQ:return g.EQ;case y.LT:return y.LT;case v.GT:return v.GT;default:return!1}if(e[1][0]!==l.Delim)return!1;if(e[1][4].value!==g.EQ)return!1;switch(e[0][4].value){case y.LT:return y.LT_OR_EQ;case v.GT:return v.GT_OR_EQ;default:return!1}}function invertComparison(e){switch(e){case g.EQ:return g.EQ;case y.LT:return v.GT;case y.LT_OR_EQ:return v.GT_OR_EQ;case v.GT:return y.LT;case v.GT_OR_EQ:return y.LT_OR_EQ;default:return!1}}!function(e){e.LT="<",e.LT_OR_EQ="<="}(y||(y={})),function(e){e.GT=">",e.GT_OR_EQ=">="}(v||(v={})),function(e){e.EQ="="}(g||(g={}));class MediaFeatureRangeNameValue{type=c.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+d(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.value,parent:this,state:i},"value")&&("walk"in this.value?this.value.walk(e,i):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===c.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=c.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+d(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.value,parent:this,state:i},"value")&&("walk"in this.value?this.value.walk(e,i):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===c.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=c.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,n){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=n}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+d(...this.valueOneOperator)+this.name.toString()+d(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.valueOne,parent:this,state:i},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e,i))&&(t&&(i={...t}),!1!==e({node:this.valueTwo,parent:this,state:i},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e,i))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===c.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(e){let i=!1,a=!1;for(let n=0;n<e.length;n++){const r=e[n];if(r.type===t.Token){if(r.value[0]===l.Delim){const t=matchesComparison(e.slice(n));if(!1!==t){if(!1!==i){a=[t[0]+n,t[1]+n];break}i=[t[0]+n,t[1]+n],n+=t[1]}}}}if(!1===i)return!1;const n=[e[i[0]].value];if(i[0]!==i[1]&&n.push(e[i[1]].value),!1===a){const t=e.slice(0,i[0]),a=e.slice(i[1]+1),r=parseMediaFeatureName(t);if(r){const e=parseMediaFeatureValue(a,!0);return!!e&&new MediaFeatureRangeNameValue(r,n,e)}const s=parseMediaFeatureName(a);if(s){const e=parseMediaFeatureValue(t,!0);return!!e&&new MediaFeatureRangeValueName(s,n,e)}return!1}const r=[e[a[0]].value];a[0]!==a[1]&&r.push(e[a[1]].value);const s=e.slice(0,i[0]),o=e.slice(i[1]+1,a[0]),u=e.slice(a[1]+1),d=parseMediaFeatureValue(s,!0),h=parseMediaFeatureName(o),m=parseMediaFeatureValue(u,!0);if(!d||!h||!m)return!1;{const e=comparisonFromTokens(n);if(!1===e||e===g.EQ)return!1;const t=comparisonFromTokens(r);if(!1===t||t===g.EQ)return!1;if(!(e!==y.LT&&e!==y.LT_OR_EQ||t!==v.GT&&t!==v.GT_OR_EQ))return!1;if(!(e!==v.GT&&e!==v.GT_OR_EQ||t!==y.LT&&t!==y.LT_OR_EQ))return!1}return new MediaFeatureRangeValueNameValue(h,d,n,m,r)}class MediaFeature{type=c.MediaFeature;feature;before;after;constructor(e,t=[],i=[]){this.feature=e,this.before=t,this.after=i}getName(){return this.feature.getName()}getNameToken(){return this.feature.getNameToken()}tokens(){return[...this.before,...this.feature.tokens(),...this.after]}toString(){return d(...this.before)+this.feature.toString()+d(...this.after)}indexOf(e){return e===this.feature?"feature":-1}at(e){if("feature"===e)return this.feature}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.feature,parent:this,state:i},"feature")&&("walk"in this.feature?this.feature.walk(e,i):void 0)}toJSON(){return{type:this.type,feature:this.feature.toJSON(),before:this.before,after:this.after}}isMediaFeature(){return MediaFeature.isMediaFeature(this)}static isMediaFeature(e){return!!e&&(e instanceof MediaFeature&&e.type===c.MediaFeature)}}function parseMediaFeature(e,t=[],i=[]){if(e.startToken[0]!==l.OpenParen)return!1;const a=parseMediaFeatureBoolean(e.value);if(!1!==a)return new MediaFeature(a,t,i);const n=parseMediaFeaturePlain(e.value);if(!1!==n)return new MediaFeature(n,t,i);const r=parseMediaFeatureRange(e.value);return!1!==r&&new MediaFeature(r,t,i)}function newMediaFeatureBoolean(e){const t=[l.Ident,"",-1,-1,{value:""}];return h(t,e),new MediaFeature(new MediaFeatureBoolean(new MediaFeatureName(new i(t))),[[l.OpenParen,"(",-1,-1,void 0]],[[l.CloseParen,")",-1,-1,void 0]])}function newMediaFeaturePlain(e,...t){const n=[l.Ident,"",-1,-1,{value:""}];h(n,e);const r=a(t);return new MediaFeature(new MediaFeaturePlain(new MediaFeatureName(new i(n)),[l.Colon,":",-1,-1,void 0],new MediaFeatureValue(1===r.length?r[0]:r)),[[l.OpenParen,"(",-1,-1,void 0]],[[l.CloseParen,")",-1,-1,void 0]])}class MediaNot{type=c.MediaNot;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return d(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaNot(){return MediaNot.isMediaNot(this)}static isMediaNot(e){return!!e&&(e instanceof MediaNot&&e.type===c.MediaNot)}}class MediaOr{type=c.MediaOr;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return d(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e,t){let i;return t&&(i={...t}),!1!==e({node:this.media,parent:this,state:i},"media")&&this.media.walk(e,i)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaOr(){return MediaOr.isMediaOr(this)}static isMediaOr(e){return!!e&&(e instanceof MediaOr&&e.type===c.MediaOr)}}function modifierFromToken(e){if(e[0]!==l.Ident)return!1;switch(e[4].value.toLowerCase()){case k.Not:return k.Not;case k.Only:return k.Only;default:return!1}}function parseMediaQuery(e){{const t=parseMediaCondition(e);if(!1!==t)return new MediaQueryWithoutType(t)}{let t=-1,i=-1,a=-1;for(let o=0;o<e.length;o++){const u=e[o];if(!n(u)&&!r(u)){if(s(u)){const n=u.value;if(-1===t&&n[0]===l.Ident&&modifierFromToken(n)){t=o;continue}if(-1===i&&n[0]===l.Ident&&!modifierFromToken(n)){i=o;continue}if(-1===a&&n[0]===l.Ident&&O.test(n[4].value)){a=o;if(!1===parseMediaConditionWithoutOr(e.slice(o+1)))return!1;break}return!1}return!1}}let o=[],u=[];-1!==t?(o=e.slice(0,t+1).flatMap((e=>e.tokens())),-1!==i&&(u=e.slice(t+1,i+1).flatMap((e=>e.tokens())))):-1!==i&&(u=e.slice(0,i+1).flatMap((e=>e.tokens())));const d=parseMediaConditionWithoutOr(e.slice(Math.max(t,i,a)+1));return!1===d?new MediaQueryWithType(o,[...u,...e.slice(i+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(o,u,e.slice(i+1,a+1).flatMap((e=>e.tokens())),d)}}function parseMediaConditionListWithOr(e){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;s<e.length;s++){if(i){const t=parseMediaOr(e.slice(s));if(!1!==t){s+=t.advance,a.push(t.node),r=s;continue}}const u=e[s];if(u.type!==t.Whitespace&&u.type!==t.Comment){if(i)return!1;if(!1!==i||!o(u))return!1;if(u.normalize(),i=parseMediaInParensFromSimpleBlock(u),!1===i)return!1;n=s}}return!(!i||!a.length)&&new MediaConditionListWithOr(i,a,e.slice(0,n).flatMap((e=>e.tokens())),e.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(e){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;s<e.length;s++){if(i){const t=parseMediaAnd(e.slice(s));if(!1!==t){s+=t.advance,a.push(t.node),r=s;continue}}const u=e[s];if(u.type!==t.Whitespace&&u.type!==t.Comment){if(i)return!1;if(!1!==i||!o(u))return!1;if(u.normalize(),i=parseMediaInParensFromSimpleBlock(u),!1===i)return!1;n=s}}return!(!i||!a.length)&&new MediaConditionListWithAnd(i,a,e.slice(0,n).flatMap((e=>e.tokens())),e.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const n=parseMediaInParens(e);return!1!==n&&new MediaCondition(n)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(e){let i=-1;for(let a=0;a<e.length;a++){const n=e[a];if(n.type!==t.Whitespace&&n.type!==t.Comment){if(!o(n))return!1;if(-1!==i)return!1;i=a}}if(-1===i)return!1;const a=e[i];if(a.startToken[0]!==l.OpenParen)return!1;a.normalize();const n=[...e.slice(0,i).flatMap((e=>e.tokens())),a.startToken],r=[a.endToken,...e.slice(i+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(a,n,r);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(a.value);return!1!==u?new MediaInParens(u,n,r):new MediaInParens(new GeneralEnclosed(a),e.slice(0,i).flatMap((e=>e.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==l.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}!function(e){e.Not="not",e.Only="only"}(k||(k={}));const F=/^not$/i;function parseMediaNot(e){let i=!1,a=null;for(let n=0;n<e.length;n++){const r=e[n];if(r.type!==t.Whitespace&&r.type!==t.Comment){if(isIdent(r)){const e=r.value;if(F.test(e[4].value)){if(i)return!1;i=!0;continue}return!1}if(!i||!o(r))return!1;{r.normalize();const t=parseMediaInParensFromSimpleBlock(r);if(!1===t)return!1;a=new MediaNot(e.slice(0,n).flatMap((e=>e.tokens())),t)}}}return a||!1}const N=/^or$/i;function parseMediaOr(e){let i=!1;for(let a=0;a<e.length;a++){const n=e[a];if(n.type!==t.Whitespace&&n.type!==t.Comment){if(isIdent(n)){const e=n.value;if(N.test(e[4].value)){if(i)return!1;i=!0;continue}return!1}if(i&&o(n)){n.normalize();const t=parseMediaInParensFromSimpleBlock(n);return!1!==t&&{advance:a,node:new MediaOr(e.slice(0,a).flatMap((e=>e.tokens())),t)}}return!1}}return!1}const O=/^and$/i;function parseMediaAnd(e){let i=!1;for(let a=0;a<e.length;a++){const n=e[a];if(n.type!==t.Whitespace&&n.type!==t.Comment){if(isIdent(n)){const e=n.value;if(O.test(e[4].value)){if(i)return!1;i=!0;continue}return!1}if(i&&o(n)){n.normalize();const t=parseMediaInParensFromSimpleBlock(n);return!1!==t&&{advance:a,node:new MediaAnd(e.slice(0,a).flatMap((e=>e.tokens())),t)}}return!1}}return!1}function parseFromTokens(e,t){const i=u(e,{onParseError:t?.onParseError});return i.map(((e,a)=>{const n=parseMediaQuery(e);return!1===n&&!0===t?.preserveInvalidMediaQueries?new MediaQueryInvalid(i[a]):n})).filter((e=>!!e))}function parse(e,t){const i=m({css:e},{onParseError:t?.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)}class CustomMedia{type=c.CustomMedia;name;mediaQueryList=null;trueOrFalseKeyword=null;constructor(e,t,i){this.name=e,this.mediaQueryList=t,this.trueOrFalseKeyword=i??null}getName(){for(let e=0;e<this.name.length;e++){const t=this.name[e];if(t[0]===l.Ident)return t[4].value}return""}getNameToken(){for(let e=0;e<this.name.length;e++){const t=this.name[e];if(t[0]===l.Ident)return t}return null}hasMediaQueryList(){return!!this.mediaQueryList}hasTrueKeyword(){if(!this.trueOrFalseKeyword)return!1;for(let e=0;e<this.trueOrFalseKeyword.length;e++){const t=this.trueOrFalseKeyword[e];if(t[0]!==l.Comment&&t[0]!==l.Whitespace)return t[0]===l.Ident&&"true"===t[4].value.toLowerCase()}return!1}hasFalseKeyword(){if(!this.trueOrFalseKeyword)return!1;for(let e=0;e<this.trueOrFalseKeyword.length;e++){const t=this.trueOrFalseKeyword[e];if(t[0]!==l.Comment&&t[0]!==l.Whitespace)return t[0]===l.Ident&&"false"===t[4].value.toLowerCase()}return!1}tokens(){if(this.trueOrFalseKeyword)return[...this.name,...this.trueOrFalseKeyword];if(!this.mediaQueryList)return[...this.name];const e=[];for(let t=0;t<this.mediaQueryList.length;t++){const i=this.mediaQueryList[t];0!==t&&e.push([l.Comma,",",-1,-1,void 0]),e.push(...i.tokens())}return[...this.name,...e]}toString(){return d(...this.tokens())}toJSON(){return{type:this.type,string:this.toString(),nameValue:this.getName(),name:this.name,hasFalseKeyword:this.hasFalseKeyword(),hasTrueKeyword:this.hasTrueKeyword(),trueOrFalseKeyword:this.trueOrFalseKeyword,mediaQueryList:this.mediaQueryList?.map((e=>e.toJSON()))}}isCustomMedia(){return CustomMedia.isCustomMedia(this)}static isCustomMedia(e){return!!e&&(e instanceof CustomMedia&&e.type===c.CustomMedia)}}function parseCustomMediaFromTokens(e,t){let i=[],a=e;for(let t=0;t<e.length;t++)if(e[t][0]!==l.Comment&&e[t][0]!==l.Whitespace){if(e[t][0]===l.Ident){if(e[t][4].value.startsWith("--")){i=e.slice(0,t+1),a=e.slice(t+1);break}}return!1}let n=!0;for(let e=0;e<a.length;e++)if(a[e][0]!==l.Comment&&a[e][0]!==l.Whitespace){if(a[e][0]===l.Ident){const t=a[e][4].value.toLowerCase();if("false"===t)continue;if("true"===t)continue}if(a[e][0]===l.EOF)break;n=!1}return n?new CustomMedia(i,null,a):new CustomMedia(i,parseFromTokens(f(a),t))}function parseCustomMedia(e,t){const i=m({css:e},{onParseError:t?.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseCustomMediaFromTokens(a,t)}function isCustomMedia(e){return CustomMedia.isCustomMedia(e)}function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)}function isMediaAnd(e){return MediaAnd.isMediaAnd(e)}function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaCondition(e){return MediaCondition.isMediaCondition(e)}function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)}function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)}function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)}function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)}function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaFeature(e){return MediaFeature.isMediaFeature(e)}function isMediaInParens(e){return MediaInParens.isMediaInParens(e)}function isMediaNot(e){return MediaNot.isMediaNot(e)}function isMediaOr(e){return MediaOr.isMediaOr(e)}function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}function cloneMediaQuery(e){const t=f(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${d(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${d(...t)}"`)}var w;function typeFromToken(e){if(e[0]!==l.Ident)return!1;switch(e[4].value.toLowerCase()){case w.All:return w.All;case w.Print:return w.Print;case w.Screen:return w.Screen;case w.Tty:return w.Tty;case w.Tv:return w.Tv;case w.Projection:return w.Projection;case w.Handheld:return w.Handheld;case w.Braille:return w.Braille;case w.Embossed:return w.Embossed;case w.Aural:return w.Aural;case w.Speech:return w.Speech;default:return!1}}!function(e){e.All="all",e.Print="print",e.Screen="screen",e.Tty="tty",e.Tv="tv",e.Projection="projection",e.Handheld="handheld",e.Braille="braille",e.Embossed="embossed",e.Aural="aural",e.Speech="speech"}(w||(w={}));export{CustomMedia,GeneralEnclosed,MediaAnd,MediaCondition,MediaConditionListWithAnd,MediaConditionListWithOr,MediaFeature,MediaFeatureBoolean,g as MediaFeatureEQ,v as MediaFeatureGT,y as MediaFeatureLT,MediaFeatureName,MediaFeaturePlain,MediaFeatureRangeNameValue,MediaFeatureRangeValueName,MediaFeatureRangeValueNameValue,MediaFeatureValue,MediaInParens,MediaNot,MediaOr,MediaQueryInvalid,k as MediaQueryModifier,MediaQueryWithType,MediaQueryWithoutType,w as MediaType,c as NodeType,cloneMediaQuery,comparisonFromTokens,invertComparison,isCustomMedia,isGeneralEnclosed,isMediaAnd,isMediaCondition,isMediaConditionList,isMediaConditionListWithAnd,isMediaConditionListWithOr,isMediaFeature,isMediaFeatureBoolean,isMediaFeatureName,isMediaFeaturePlain,isMediaFeatureRange,isMediaFeatureRangeNameValue,isMediaFeatureRangeValueName,isMediaFeatureRangeValueNameValue,isMediaFeatureValue,isMediaInParens,isMediaNot,isMediaOr,isMediaQuery,isMediaQueryInvalid,isMediaQueryWithType,isMediaQueryWithoutType,matchesComparison,matchesRatio,matchesRatioExactly,modifierFromToken,newMediaFeatureBoolean,newMediaFeaturePlain,parse,parseCustomMedia,parseCustomMediaFromTokens,parseFromTokens,typeFromToken};
|