-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
postcss-rewrite-url: url modifiers and docs (#1526)
- Loading branch information
1 parent
b22c242
commit e3f064c
Showing
10 changed files
with
218 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"use strict";var e=require("@csstools/css-tokenizer"),r=require("@csstools/css-parser-algorithms");function serializeString(e){let r="";for(const t of e){const e=t.codePointAt(0);if(void 0!==e)switch(e){case 0:r+=String.fromCodePoint(65533);break;case 127:r+=`\\${e.toString(16)}`;break;case 34:case 39:case 92:r+=`\\${t}`;break;default:if(1<=e&&e<=31){r+=`\\${e.toString(16)} `;break}r+=t}else r+=String.fromCodePoint(65533)}return r}const t=/rewrite-url\(/i,o=/^rewrite-url$/i,creator=e=>{const r=e?.rewriter??(e=>e);return{postcssPlugin:"postcss-rewrite-url",Once(e,{result:t}){e.walkDecls((e=>{rewriteDeclaration(e,t,r)})),e.walkAtRules((e=>{rewriteAtRule(e,t,r)}))},Declaration(e,{result:t}){rewriteDeclaration(e,t,r)},AtRule(e,{result:t}){rewriteAtRule(e,t,r)}}};function rewriteDeclaration(e,r,o){if(!t.test(e.value))return;const s={type:"declaration-value",rootFrom:r.opts.from,from:e.source?.input.from,property:e.prop},i=rewrite(o,e.value,s);i!==e.value&&(e.value=i)}function rewriteAtRule(e,r,o){if(!t.test(e.params))return;const s={type:"at-rule-prelude",rootFrom:r.opts.from,from:e.source?.input.from,atRuleName:e.name},i=rewrite(o,e.params,s);i!==e.params&&(e.params=i)}function rewrite(t,s,i){const a=r.parseCommaSeparatedListOfComponentValues(e.tokenize({css:s})),n=r.replaceComponentValues(a,(s=>{if(r.isFunctionNode(s)&&o.test(s.getName()))for(const o of s.value)if(!r.isWhitespaceNode(o)&&!r.isCommentNode(o)&&r.isTokenNode(o)&&e.isTokenString(o.value)){const e=o.value[4].value.trim(),r=t({url:e},i);if(!1===r)return;if(r.url===e)break;return o.value[4].value=r.url,o.value[1]=`"${serializeString(r.url)}"`,s.name[1]="url(",s.name[4].value="url",s}}));return r.stringify(n)}creator.postcss=!0,module.exports=creator; | ||
"use strict";var e=require("@csstools/css-tokenizer"),r=require("@csstools/css-parser-algorithms");function serializeString(e){let r="";for(const t of e){const e=t.codePointAt(0);if(void 0!==e)switch(e){case 0:r+=String.fromCodePoint(65533);break;case 127:r+=`\\${e.toString(16)}`;break;case 34:case 39:case 92:r+=`\\${t}`;break;default:if(1<=e&&e<=31){r+=`\\${e.toString(16)} `;break}r+=t}else r+=String.fromCodePoint(65533)}return r}const t=/rewrite-url\(/i,o=/^rewrite-url$/i,creator=e=>{const r=e?.rewriter??(e=>e);return{postcssPlugin:"postcss-rewrite-url",Once(e,{result:t}){e.walkDecls((e=>{rewriteDeclaration(e,t,r)})),e.walkAtRules((e=>{rewriteAtRule(e,t,r)}))},Declaration(e,{result:t}){rewriteDeclaration(e,t,r)},AtRule(e,{result:t}){rewriteAtRule(e,t,r)}}};function rewriteDeclaration(e,r,o){if(!t.test(e.value))return;const s={type:"declaration-value",rootFrom:r.opts.from,from:e.source?.input.from,property:e.prop},i=rewrite(o,e.value,s);i!==e.value&&(e.value=i)}function rewriteAtRule(e,r,o){if(!t.test(e.params))return;const s={type:"at-rule-prelude",rootFrom:r.opts.from,from:e.source?.input.from,atRuleName:e.name},i=rewrite(o,e.params,s);i!==e.params&&(e.params=i)}function rewrite(t,s,i){const n=r.parseCommaSeparatedListOfComponentValues(e.tokenize({css:s})),a=r.replaceComponentValues(n,(s=>{if(!r.isFunctionNode(s)||!o.test(s.getName()))return;const n=s.value.filter((e=>!r.isWhiteSpaceOrCommentNode(e)));for(let o=0;o<n.length;o++){const a=n[o];if(r.isTokenNode(a)&&e.isTokenString(a.value)){const u=a.value[4].value.trim(),l=n.slice(o+1),c=t({url:u,urlModifiers:l.map((e=>e.toString()))},i);if(!1===c)return;const m=r.parseListOfComponentValues(e.tokenize({css:[`"${serializeString(c.url)}"`,...c.urlModifiers??l].join(" ")}));return s.value=m,s.name[1]="url(",s.name[4].value="url",s}return}}));return r.stringify(a)}creator.postcss=!0,module.exports=creator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import{tokenize as r,isTokenString as e}from"@csstools/css-tokenizer";import{parseCommaSeparatedListOfComponentValues as t,replaceComponentValues as o,isFunctionNode as s,isWhitespaceNode as a,isCommentNode as i,isTokenNode as l,stringify as u}from"@csstools/css-parser-algorithms";function serializeString(r){let e="";for(const t of r){const r=t.codePointAt(0);if(void 0!==r)switch(r){case 0:e+=String.fromCodePoint(65533);break;case 127:e+=`\\${r.toString(16)}`;break;case 34:case 39:case 92:e+=`\\${t}`;break;default:if(1<=r&&r<=31){e+=`\\${r.toString(16)} `;break}e+=t}else e+=String.fromCodePoint(65533)}return e}const n=/rewrite-url\(/i,c=/^rewrite-url$/i,creator=r=>{const e=r?.rewriter??(r=>r);return{postcssPlugin:"postcss-rewrite-url",Once(r,{result:t}){r.walkDecls((r=>{rewriteDeclaration(r,t,e)})),r.walkAtRules((r=>{rewriteAtRule(r,t,e)}))},Declaration(r,{result:t}){rewriteDeclaration(r,t,e)},AtRule(r,{result:t}){rewriteAtRule(r,t,e)}}};function rewriteDeclaration(r,e,t){if(!n.test(r.value))return;const o={type:"declaration-value",rootFrom:e.opts.from,from:r.source?.input.from,property:r.prop},s=rewrite(t,r.value,o);s!==r.value&&(r.value=s)}function rewriteAtRule(r,e,t){if(!n.test(r.params))return;const o={type:"at-rule-prelude",rootFrom:e.opts.from,from:r.source?.input.from,atRuleName:r.name},s=rewrite(t,r.params,o);s!==r.params&&(r.params=s)}function rewrite(n,f,m){const p=t(r({css:f})),w=o(p,(r=>{if(s(r)&&c.test(r.getName()))for(const t of r.value)if(!a(t)&&!i(t)&&l(t)&&e(t.value)){const e=t.value[4].value.trim(),o=n({url:e},m);if(!1===o)return;if(o.url===e)break;return t.value[4].value=o.url,t.value[1]=`"${serializeString(o.url)}"`,r.name[1]="url(",r.name[4].value="url",r}}));return u(w)}creator.postcss=!0;export{creator as default}; | ||
import{tokenize as r,isTokenString as e}from"@csstools/css-tokenizer";import{parseCommaSeparatedListOfComponentValues as t,replaceComponentValues as o,isFunctionNode as s,isWhiteSpaceOrCommentNode as i,isTokenNode as a,parseListOfComponentValues as l,stringify as n}from"@csstools/css-parser-algorithms";function serializeString(r){let e="";for(const t of r){const r=t.codePointAt(0);if(void 0!==r)switch(r){case 0:e+=String.fromCodePoint(65533);break;case 127:e+=`\\${r.toString(16)}`;break;case 34:case 39:case 92:e+=`\\${t}`;break;default:if(1<=r&&r<=31){e+=`\\${r.toString(16)} `;break}e+=t}else e+=String.fromCodePoint(65533)}return e}const u=/rewrite-url\(/i,c=/^rewrite-url$/i,creator=r=>{const e=r?.rewriter??(r=>r);return{postcssPlugin:"postcss-rewrite-url",Once(r,{result:t}){r.walkDecls((r=>{rewriteDeclaration(r,t,e)})),r.walkAtRules((r=>{rewriteAtRule(r,t,e)}))},Declaration(r,{result:t}){rewriteDeclaration(r,t,e)},AtRule(r,{result:t}){rewriteAtRule(r,t,e)}}};function rewriteDeclaration(r,e,t){if(!u.test(r.value))return;const o={type:"declaration-value",rootFrom:e.opts.from,from:r.source?.input.from,property:r.prop},s=rewrite(t,r.value,o);s!==r.value&&(r.value=s)}function rewriteAtRule(r,e,t){if(!u.test(r.params))return;const o={type:"at-rule-prelude",rootFrom:e.opts.from,from:r.source?.input.from,atRuleName:r.name},s=rewrite(t,r.params,o);s!==r.params&&(r.params=s)}function rewrite(u,f,m){const p=t(r({css:f})),w=o(p,(t=>{if(!s(t)||!c.test(t.getName()))return;const o=t.value.filter((r=>!i(r)));for(let s=0;s<o.length;s++){const i=o[s];if(a(i)&&e(i.value)){const e=i.value[4].value.trim(),a=o.slice(s+1),n=u({url:e,urlModifiers:a.map((r=>r.toString()))},m);if(!1===n)return;const c=l(r({css:[`"${serializeString(n.url)}"`,...n.urlModifiers??a].join(" ")}));return t.value=c,t.name[1]="url(",t.name[4].value="url",t}return}}));return n(w)}creator.postcss=!0;export{creator as default}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters