vite-plugin-css-svg-mask-image 1.0.2 → 1.0.4

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 +12 -3
  2. package/package.json +3 -2
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) {
@@ -75,10 +76,15 @@ export function svgMaskPlugin(options = {}) {
75
76
  }
76
77
  },
77
78
  async transform(code, id) {
78
- if (!id.match(/\.(css|scss|sass)$/)) {
79
+ const idPath = id.replace(/\?.*$/, "");
80
+ if (!idPath.match(/\.(css|scss|sass)$/)) {
79
81
  return null;
80
82
  }
81
- const ast = postcss.parse(code);
83
+ const syntax = /\.(scss|sass)$/.test(idPath) ? postcssScss : undefined;
84
+ const ast = postcss.parse(code, {
85
+ from: id,
86
+ ...(syntax && { parser: syntax }),
87
+ });
82
88
  let has_svg_functions = false;
83
89
  ast.walkDecls("mask-image", (decl) => {
84
90
  const value = decl.value.trim();
@@ -125,7 +131,10 @@ export function svgMaskPlugin(options = {}) {
125
131
  if (!has_svg_functions) {
126
132
  return null;
127
133
  }
128
- const result = await postcss().process(ast, { from: id, to: id });
134
+ const processOpts = { from: id, to: id };
135
+ if (syntax)
136
+ processOpts.stringifier = postcssScss;
137
+ const result = await postcss().process(ast, processOpts);
129
138
  processed_files.add(id);
130
139
  return {
131
140
  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.2",
3
+ "version": "1.0.4",
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,7 +38,8 @@
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
45
  "vite": "^7.0.0"