parseCssVars.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. // https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.clearComments = exports.parseCssVars = void 0;
  5. const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g;
  6. const commentReg1 = /\/\*([\s\S]*?)\*\//g;
  7. const commentReg2 = /\/\/([\s\S]*?)\n/g;
  8. function* parseCssVars(styleContent) {
  9. styleContent = clearComments(styleContent);
  10. const matchs = styleContent.matchAll(vBindCssVarReg);
  11. for (const match of matchs) {
  12. if (match.index !== undefined) {
  13. const matchText = match[1] ?? match[2] ?? match[3];
  14. if (matchText !== undefined) {
  15. const offset = match.index + styleContent.slice(match.index).indexOf(matchText);
  16. yield { offset, text: matchText };
  17. }
  18. }
  19. }
  20. }
  21. exports.parseCssVars = parseCssVars;
  22. function clearComments(css) {
  23. return css
  24. .replace(commentReg1, match => `/*${' '.repeat(match.length - 4)}*/`)
  25. .replace(commentReg2, match => `//${' '.repeat(match.length - 3)}\n`);
  26. }
  27. exports.clearComments = clearComments;
  28. //# sourceMappingURL=parseCssVars.js.map