import{tokenizer as t,TokenType as e,stringify as o}from"@csstools/css-tokenizer";function hasFeature(o){{const t=o.toLowerCase();if(!t.includes("vb")&&!t.includes("vi"))return!1}const r=t({css:o});for(;;){const t=r.nextToken();if(!t)break;if(t[0]===e.EOF)break;if(t[0]!==e.Dimension)continue;const o=t[4].unit.toLowerCase();if("vb"===o||"vi"===o)return!0}return!1}function hasSupportsAtRuleAncestor(t){let e=t.parent;for(;e;)if("atrule"===e.type){if("supports"===e.name.toLowerCase()&&hasFeature(e.params))return!0;e=e.parent}else e=e.parent;return!1}var r;function transform(r,n){const i=t({css:r}),s=[];let a=!1;for(;;){const t=i.nextToken();if(!t)break;if(s.push(t),t[0]===e.EOF)break;if(t[0]!==e.Dimension)continue;const o=t[4].unit.toLowerCase();let r;"vi"===o?r=n.vi:"vb"===o&&(r=n.vb),r&&(t[1]=t[4].value.toString()+r,t[4].unit=r,a=!0)}return a?o(...s):r}!function(t){t.TopToBottom="top-to-bottom",t.BottomToTop="bottom-to-top",t.RightToLeft="right-to-left",t.LeftToRight="left-to-right"}(r||(r={}));const n=/(?:vi|vb)\b/i,creator=t=>{const e=Object.assign({inlineDirection:r.LeftToRight,preserve:!0},t);switch(e.inlineDirection){case r.LeftToRight:case r.RightToLeft:case r.TopToBottom:case r.BottomToTop:break;default:throw new Error(`[postcss-logical-viewport-units] "inlineDirection" must be one of ${Object.values(r).join(", ")}`)}const o=[r.LeftToRight,r.RightToLeft].includes(e.inlineDirection),i={vb:"vh",vi:"vw"};return o||(i.vb="vw",i.vi="vh"),{postcssPlugin:"postcss-logical-viewport-units",Declaration(t,{atRule:o}){{if(!n.test(t.value))return;const e=t.prev();if(e&&"decl"===e.type&&e.prop===t.prop)return;if(hasSupportsAtRuleAncestor(t))return}const r=transform(t.value,i);if(r===t.value)return;if(t.cloneBefore({value:r}),!e.preserve)return void t.remove();if(!t.variable)return;const s=o({name:"supports",params:"(top: 1vi)",source:t.source}),a=t.parent;if(!a)return;const c=a.cloneAfter({nodes:[]});c.append(t),s.append(c),a.after(s)}}};creator.postcss=!0;export{creator as default};
