// 模板 CSS 使用 Taro 的 750 设计宽度,转换到预览容器单位。 export function templatePreviewCss() { return { postcssPlugin: "template-preview-css", Once(root) { const file = root.source?.input.file || ""; if (!file.includes("/packages/template-") || !file.endsWith("/taro/style.css")) return; root.walkRules((rule) => { rule.selector = rule.selector .split(",") .map( (selector) => ".component-template-preview__canvas " + selector .trim() .replace( /(^|[ >+~])(image|text|view)(?=[ .#:[>+~)]|$)/g, (_, prefix, tag) => prefix + { image: "img", text: "span", view: "div" }[tag], ), ) .join(", "); }); root.walkDecls((declaration) => { declaration.value = declaration.value.replace( /(-?(?:[0-9]*[.])?[0-9]+)px/g, (_, value) => Number((Number(value) / 7.5).toFixed(8)) + "cqw", ); }); }, }; }