epiphany/node_modules/postcss-logical/dist/index.cjs

2 lines
12 KiB
JavaScript
Raw Normal View History

2023-12-09 22:48:07 -08:00
"use strict";var r,e,n=require("postcss-value-parser");!function(r){r.Block="block",r.Inline="inline"}(r||(r={})),function(r){r.Start="start",r.End="end"}(e||(e={}));const o={BlockStart:"block-start",BlockEnd:"block-end",InlineStart:"inline-start",InlineEnd:"inline-end"};var t,i;function directionFlowToAxes(r){switch(r){case t.TopToBottom:return[i.Top,i.Bottom];case t.BottomToTop:return[i.Bottom,i.Top];case t.RightToLeft:return[i.Right,i.Left];case t.LeftToRight:return[i.Left,i.Right]}}function cloneDeclaration(r,e,n){return r.parent&&r.parent.some((r=>"decl"==r.type&&r.prop===n&&r.value===e))?[]:[r.clone({value:e,prop:n})]}function transformTransition(r,e,o){const{prop:t,value:i}=r,l=n(i),a=[];let s=[];l.nodes.forEach((r=>{if("div"===r.type&&","===r.value)return a.push(s),void(s=[]);s.push(r)})),a.push(s);for(let r=0;r<a.length;r++){const n=a[r];for(let t=0;t<n.length;t++){const i=n[t];if("word"!==i.type)continue;const l=i.value.toLowerCase(),s=o[l];if(!s)continue;const d=s(e.decl({prop:l,value:"initial"}));if(0!==d.length){for(let e=d.length-1;e>=0;e--){const o=JSON.parse(JSON.stringify(n));o[t].value=d[e].prop,a.splice(r+1,0,o)}a.splice(r,1),r++}}}const d=[];for(let r=0;r<a.length;r++){const e=a[r];d.push(...e),r!==a.length-1&&d.push({type:"div",value:",",sourceIndex:0,sourceEndIndex:0,before:"",after:" "})}const c=n.stringify(d);return c!==i?cloneDeclaration(r,c,t):[]}function parseValueCouple(r){const e=n(r.value).nodes.filter((r=>"space"!==r.type));if(e.length>2||0===e.length){const n=`[postcss-logical] Invalid number of values for ${r.prop}. Found ${e.length} values, expected 1 or 2.`;throw r.error(n)}let o,t;return 1===e.length?(o=n.stringify(e[0]),t=o):(o=n.stringify(e[0]),t=n.stringify(e[1])),[o,t]}function transformBorder(r,e){return n=>cloneDeclaration(n,n.value,`border-${e}-${r}`)}function transformBorderProperty(r,e){return n=>{const[o,t]=e,[i,l]=parseValueCouple(n);return[...cloneDeclaration(n,i,`border-${o}-${r}`),...cloneDeclaration(n,l,`border-${t}-${r}`)]}}function transformBorderShorthand(r){return e=>r.flatMap((r=>cloneDeclaration(e,e.value,`border-${r}`)))}function transformBorderRadius(r){return e=>{let n;switch(e.prop.toLowerCase()){case"border-start-start-radius":n=`border-${r.inlineIsHorizontal?`${r.block[0]}-${r.inline[0]}`:`${r.inline[0]}-${r.block[0]}`}-radius`;break;case"border-start-end-radius":n=`border-${r.inlineIsHorizontal?`${r.block[0]}-${r.inline[1]}`:`${r.inline[1]}-${r.block[0]}`}-radius`;break;case"border-end-start-radius":n=`border-${r.inlineIsHorizontal?`${r.block[1]}-${r.inline[0]}`:`${r.inline[0]}-${r.block[1]}`}-radius`;break;case"border-end-end-radius":n=`border-${r.inlineIsHorizontal?`${r.block[1]}-${r.inline[1]}`:`${r.inline[1]}-${r.block[1]}`}-radius`;break}return n?cloneDeclaration(e,e.value,n):[]}}function transformLogicalSize(r){return e=>{const{value:n}=e,o=r.inlineIsHorizontal?"width":"height",t=r.inlineIsHorizontal?"height":"width",i=e.prop.toLowerCase().replace("inline-size",o).replace("block-size",t);return cloneDeclaration(e,n,i)}}function transformOffset(r){return e=>cloneDeclaration(e,e.value,r)}function transformOffsetShorthand(r){return e=>{const[n,o]=r,[t,i]=parseValueCouple(e);return[...cloneDeclaration(e,t,n),...cloneDeclaration(e,i,o)]}}function transformSide(r,e){return n=>cloneDeclaration(n,n.value,`${r}-${e}`)}function transformSideShorthand(r,e){return n=>{const[o,t]=e,[i,l]=parseValueCouple(n);return[...cloneDeclaration(n,i,`${r}-${o}`),...cloneDeclaration(n,l,`${r}-${t}`)]}}function logicalToPhysical(r,e){const[n,t]=e.block,[i,l]=e.inline;switch(r){case o.BlockStart:return n;case o.BlockEnd:return t;case o.InlineStart:return i;case o.InlineEnd:return l;default:throw new Error("Unsupported logical direction")}}function doTransform(r,e,o){const{prop:t,value:i}=r,l=n(i);l.nodes.forEach((r=>{if("word"===r.type){const n=r.value.toLowerCase();e.includes(n)&&(r.value=logicalToPhysical(n,o))}}));const a=l.toString();return a!==i?cloneDeclaration(r,a,t):[]}function prepareTransforms(r,t,i,l,a){return{"caption-side":(d=r,r=>doTransform(r,Object.values(o),d)),