1 line
1 KiB
JavaScript
1 line
1 KiB
JavaScript
import e from"postcss-value-parser";function hasFallback(e){const o=e.parent;if(!o)return!1;const t=e.prop.toLowerCase(),r=o.index(e);for(let e=0;e<r;e++){const r=o.nodes[e];if("decl"===r.type&&r.prop.toLowerCase()===t)return!0}return!1}const o=["woff","truetype","opentype","woff2","embedded-opentype","collection","svg"],creator=t=>{const r="preserve"in Object(t)&&Boolean(null==t?void 0:t.preserve);return{postcssPlugin:"postcss-font-format-keywords",Declaration(t){if("src"!==t.prop.toLowerCase())return;if(!t.value.toLowerCase().includes("format("))return;if(hasFallback(t))return;const n=t.parent;if(!n||"atrule"!==n.type)return;if("font-face"!==n.name.toLowerCase())return;const s=e(t.value);s.walk((t=>{"function"===t.type&&"format"===t.value.toLowerCase()&&t.nodes.forEach((t=>{"word"===t.type&&o.includes(t.value.toLowerCase())&&(t.value=e.stringify({type:"string",value:t.value,quote:'"'}))}))})),s.toString()!==t.value&&(t.cloneBefore({value:s.toString()}),r||t.remove())}}};creator.postcss=!0;export{creator as default};
|