// Chrome 86 supports logical spacing, but not logical insets or corner radii. // Only legacy browsers use these root-direction fallbacks. Modern browsers keep // native logical properties, including nested direction overrides. const mappings = { "inset-inline-start": ["left", "right"], "inset-inline-end": ["right", "left"], "border-start-start-radius": ["border-top-left-radius", "border-top-right-radius"], "border-start-end-radius": ["border-top-right-radius", "border-top-left-radius"], "border-end-start-radius": ["border-bottom-left-radius", "border-bottom-right-radius"], "border-end-end-radius": ["border-bottom-right-radius", "border-bottom-left-radius"], } module.exports = { postcssPlugin: "admin-chrome86-logical-fallbacks", OnceExit(root, { postcss }) { root.walkDecls("inset", (decl) => { const values = postcss.list.space(decl.value) const [top, right = top, bottom = top, left = right] = values for (const [prop, value] of Object.entries({ top, right, bottom, left })) { decl.cloneBefore({ prop, value }) } }) root.walkRules((rule) => { const declarations = rule.nodes.filter((node) => node.type === "decl" && mappings[node.prop]) if (!declarations.length) return for (const feature of ["inset-inline-start", "border-start-start-radius"]) { const group = declarations.filter((decl) => decl.prop.startsWith(feature.startsWith("inset") ? "inset" : "border")) if (!group.length) continue const fallback = postcss.atRule({ name: "supports", params: `not (${feature}: 0)` }) for (const [index, direction] of ["ltr", "rtl"].entries()) { const prefix = direction === "rtl" ? 'html[dir="rtl"]' : 'html:not([dir="rtl"])' const copy = rule.clone({ nodes: [] }) copy.selectors = rule.selectors.map((selector) => `${prefix} ${selector}`) for (const decl of group) copy.append(decl.clone({ prop: mappings[decl.prop][index] })) fallback.append(copy) } rule.after(fallback) } }) }, }