vite-plugin-css-svg-mask-image 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +10 -2
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync, existsSync, writeFileSync, mkdirSync } from "fs";
2
2
  import { join, resolve, dirname } from "path";
3
3
  import postcss, { Declaration } from "postcss";
4
+ import postcssScss from "postcss-scss";
4
5
  function parse_svg_function(value) {
5
6
  const match = value.match(/^['"]?([^'",]+)['"]?\s*(?:,\s*['"]?([^'"]+)['"]?)?$/);
6
7
  if (!match) {
@@ -78,7 +79,11 @@ export function svgMaskPlugin(options = {}) {
78
79
  if (!id.match(/\.(css|scss|sass)$/)) {
79
80
  return null;
80
81
  }
81
- const ast = postcss.parse(code);
82
+ const syntax = /\.(scss|sass)$/.test(id) ? postcssScss : undefined;
83
+ const ast = postcss.parse(code, {
84
+ from: id,
85
+ ...(syntax && { parser: syntax }),
86
+ });
82
87
  let has_svg_functions = false;
83
88
  ast.walkDecls("mask-image", (decl) => {
84
89
  const value = decl.value.trim();
@@ -125,7 +130,10 @@ export function svgMaskPlugin(options = {}) {
125
130
  if (!has_svg_functions) {
126
131
  return null;
127
132
  }
128
- const result = await postcss().process(ast, { from: id, to: id });
133
+ const processOpts = { from: id, to: id };
134
+ if (syntax)
135
+ processOpts.stringifier = postcssScss;
136
+ const result = await postcss().process(ast, processOpts);
129
137
  processed_files.add(id);
130
138
  return {
131
139
  code: result.css,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-css-svg-mask-image",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Vite plugin to transform CSS/SCSS files with svg() mask-image function calls to CSS variables",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,9 +38,10 @@
38
38
  "vitest": "^4.0.18"
39
39
  },
40
40
  "dependencies": {
41
- "postcss": "^8.5.6"
41
+ "postcss": "^8.5.6",
42
+ "postcss-scss": "^4.0.9"
42
43
  },
43
44
  "peerDependencies": {
44
- "vite": "^4.0.0 || ^5.0.0"
45
+ "vite": "^7.0.0"
45
46
  }
46
47
  }