2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
|
import r from"postcss";var t=(t,e)=>{const o="rule"===Object(t.parent).type?t.parent.cloneBefore({raws:{}}).removeAll():r.rule({selector:"&"});return o.selectors=o.selectors.map((r=>`${r}:dir(${e})`)),o};const e=/^border-(block|block-start|block-end|inline|inline-start|inline-end)(-(width|style|color))?$/i;var o=(r,t,o,l)=>{r.cloneBefore({prop:`border-top${r.prop.replace(e,"$2")}`,value:t[0]}),r.cloneBefore({prop:`border-bottom${r.prop.replace(e,"$2")}`,value:t[1]||t[0]}),a(r,l)},l=(r,t,o,l)=>{r.cloneBefore({prop:`border-top${r.prop.replace(e,"$2")}`}),a(r,l)},n=(r,t,o,l)=>{r.cloneBefore({prop:`border-bottom${r.prop.replace(e,"$2")}`}),a(r,l)},i=(r,o,l,n)=>{const i=()=>[r.cloneBefore({prop:`border-left${r.prop.replace(e,"$2")}`,value:o[0]}),r.cloneBefore({prop:`border-right${r.prop.replace(e,"$2")}`,value:o[1]||o[0]})],d=()=>[r.clone({prop:`border-right${r.prop.replace(e,"$2")}`,value:o[0]}),r.clone({prop:`border-left${r.prop.replace(e,"$2")}`,value:o[1]||o[0]})];return 1===o.length||2===o.length&&o[0]===o[1]||"ltr"===l?(i(),void a(r,n)):"rtl"===l?(d(),void a(r,n)):(t(r,"ltr").append(i()),t(r,"rtl").append(d()),void a(r,n))},d=(r,o,l,n)=>{const i=()=>r.cloneBefore({prop:`border-left${r.prop.replace(e,"$2")}`}),d=()=>r.cloneBefore({prop:`border-right${r.prop.replace(e,"$2")}`});return"ltr"===l?(i(),void a(r,n)):"rtl"===l?(d(),void a(r,n)):(t(r,"ltr").append(i()),t(r,"rtl").append(d()),void a(r,n))},p=(r,o,l,n)=>{const i=()=>r.cloneBefore({prop:`border-right${r.prop.replace(e,"$2")}`}),d=()=>r.cloneBefore({prop:`border-left${r.prop.replace(e,"$2")}`});return"ltr"===l?(i(),void a(r,n)):"rtl"===l?(d(),void a(r,n)):(t(r,"ltr").append(i()),t(r,"rtl").append(d()),void a(r,n))};function a(r,t){t||r.remove()}const b=/^(border-)(end-end|end-start|start-end|start-start)(-radius)$/i,c={"end-end":"bottom-right","end-start":"bottom-left","start-end":"top-right","start-start":"top-left"},s={"end-end":"bottom-left","end-start":"bottom-right","start-end":"top-left","start-start":"top-right"};var g=(r,e,o,l)=>"ltr"===o?(f(r),void h(r,l)):"rtl"===o?(u(r),void h(r,l)):(t(r,"ltr").append(f(r)),t(r,"rtl").append(u(r)),void h(r,l));function f(r){return r.cloneBefore({prop:r.prop.replace(b,((r,t,e,o)=>`${t}${c[e]}${o}`))})}function u(r){return r.cloneBefore({prop:r.prop.replace(b,((r,t,e,o)=>`${t}${s[e]}${o}`))})}function h(r,t){t||r.remove()}var v=r=>{const t=r.slice();return 4===t.length&&t[3]===t[1]&&t.pop(),3===t.length&&t[2]===t[0]&&t.pop(),2===t.length&&t[1]===t[0]&&t.pop(),t},m=(r,e,o,l)=>{if("logical"!==e[0])return null;const[,n,i,d,p]=e,a=v([n,p||i||n,d||n,i||n]),b=()=>r.cloneBefore({value:a.join(" ")});if(a.length<4||"ltr"===o)return b(),void k(r,l);const c=v([n,i||n,d||n,p||i||n]),s=()=>r.cloneBefore({value:c.join(" ")});if("rtl"===o)return s(),void k(r,l);t(r,"ltr").append(b()),t(r,"rtl").append(s()),k(r,l)};function k(r,t){t||r.remove()}var $=(r,e,o,l)=>/^inline-start$/i.test(r.value)?"ltr"===o?(B(r),void w(r,l)):"rtl"===o?(y(r),void w(r,l)):(t(r,"ltr").append(B(r)),t(r,"rtl").append(y(r)),void w(r,l)):/^inline-end$/i.test(r.value)?"ltr"===o?(y(r),void w(r,l)):"rtl"===o?(B(r),void w(r,l)):(t(r,"ltr").append(y(r)),t(r,"rtl").append(B(r)),void w(r,l)):void 0;function B(r){return r.cloneBefore({value:"left"})}function y(r){return r.cloneBefore({value:"right"})}function w(r,t){t||r.remove()}var j=(r,e,o,l)=>{if("logical"!==e[0])return r.cloneBefore({prop:"top",value:e[0]}),r.cloneBefore({prop:"right",value:e[1]||e[0]}),r.cloneBefore({prop:"bottom",value:e[2]||e[0]}),r.cloneBefore({prop:"left",value:e[3]||e[1]||e[0]}),void E(r,l);return!e[4]||e[4]===e[2]||"ltr"===o?(z(r,e),void E(r,l)):"rtl"===o?(x(r,e),void E(r,l)):(t(r,"ltr").append(z(r,e)),t(r,"rtl").append(x(r,e)),void E(r,l))};function z(r,t){return[r.cloneBefore({prop:"top",value:t[1]}),r.cloneBefore({prop:"left",value:t[2]||t[1]}),r.cloneBefore({prop:"bottom",value:t[3]||t[1]}),r.cloneBefore({prop:"right",value:t[4]||t[2]||t[1]})]}function x(r,t){return[r.cloneBefore({prop:"top",value:t[1]}),r.cloneBefore({prop:"right",value:t[2]||t[1]}),r.cloneBefore({prop:"bottom",value:t[3]||
|