vite-plugin-material-symbols 0.7.0 → 0.7.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Version 0
4
4
 
5
+ ### v0.7.1
6
+
7
+ - Added the following configuration options for flexibility:
8
+ - `moduleIdRegex` — the regex to match module IDs that should be processed for finding icon names;
9
+ - `jsxNodeRegex` — The regex to match JSX nodes that should be processed in parsed AST;
10
+ - The option `component` now also can be a regex to match multiple component names.
11
+
5
12
  ### v0.7.0
6
13
 
7
14
  - Supporting Vite 8;
package/README.md CHANGED
@@ -98,9 +98,17 @@ The plugin substitutes the `icon_names` URL parameter **ONLY** in `vite build` m
98
98
  The plugin accepts an object of the following options:
99
99
 
100
100
  ```yaml
101
+ moduleIdRegex:
102
+ type: RegExp
103
+ description: The regex to match module IDs that should be processed for finding icon names
104
+ default: /\.([jt])sx?$/i # *.js, *.jsx, *.ts, *.tsx
105
+ jsxNodeRegex:
106
+ type: RegExp
107
+ description: The regex to match JSX nodes that should be processed in parsed AST (e.g. "jsx", "_jsx" or "jsxs")
108
+ default: /jsx/
101
109
  component:
102
- type: string
103
- description: The name of JSX component to obtain the icon names from
110
+ type: string | RegExp
111
+ description: The name of JSX component to get the icon names from (or regex to match the component name)
104
112
  default: Icon
105
113
  getUrl:
106
114
  type: function
package/dist/index.d.ts CHANGED
@@ -2,6 +2,16 @@ import { Plugin } from "vite";
2
2
 
3
3
  //#region src/index.d.ts
4
4
  type PluginOptions = {
5
+ /**
6
+ * The regex to match module IDs that should be processed for finding icon names
7
+ * @default /\.([jt])sx?$/i
8
+ * */
9
+ moduleIdRegex: RegExp;
10
+ /**
11
+ * The regex to match JSX nodes that should be processed in parsed AST (e.g. "jsx", "_jsx" or "jsxs")
12
+ * @default /jsx/
13
+ * */
14
+ jsxNodeRegex: RegExp;
5
15
  /**
6
16
  * Material Symbols CSS Provider. Default: outlined, no infill, 24px, weight 400
7
17
  * @see https://fonts.google.com/icons?icon.set=Material+Symbols
@@ -9,10 +19,10 @@ type PluginOptions = {
9
19
  * */
10
20
  getUrl: (iconNamesParam: string) => string;
11
21
  /**
12
- * The name of JSX component to obtain the icon names from
22
+ * The name of JSX component to get the icon names from (or regex to match the component name)
13
23
  * @default Icon
14
24
  * */
15
- component: string;
25
+ component: string | RegExp;
16
26
  /**
17
27
  * Enables higher priority for loading symbols
18
28
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload
@@ -22,6 +32,8 @@ type PluginOptions = {
22
32
  preload: boolean;
23
33
  };
24
34
  declare const plugin: ({
35
+ moduleIdRegex,
36
+ jsxNodeRegex,
25
37
  component,
26
38
  getUrl,
27
39
  preload
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import e from"esquery";const t=e=>e.type===`Literal`&&`value`in e&&typeof e.value==`string`,n=e=>`https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&${e}`,r=e=>[`CallExpression[callee.name=/jsx/][arguments.0.name='${e}']`,`.arguments`,`Property[key.name='children'] Literal`].join(` > `),i=e=>{if(!e.size)return``;let t=[];for(let n of e.values())t.push(n);return`icon_names=${t.toSorted().join(`,`)}`},a=({component:a=`Icon`,getUrl:o=n,preload:s=!1}={})=>{let c=new Set;return{name:`material-symbols`,enforce:`pre`,moduleParsed:function({id:n,code:i}){if(!i||!/.([jt])sx?$/i.test(n))return;let o=this.parse(i),s=r(a),l=e.query(o,s).filter(t);for(let{value:e}of l)this.debug({id:n,message:e}),c.add(e)},transformIndexHtml:e=>{let t=o(i(c)),n=[{injectTo:`head`,tag:`link`,attrs:{rel:`stylesheet`,href:t}}];return s&&n.push({injectTo:`head-prepend`,tag:`link`,attrs:{rel:`preload`,as:`style`,href:t}},{injectTo:`head-prepend`,tag:`link`,attrs:{rel:`preconnect`,href:`https://fonts.gstatic.com`}}),{html:e,tags:n}}}};export{a as default};
1
+ import e from"esquery";const t=e=>e.type===`Literal`&&`value`in e&&typeof e.value==`string`,n=e=>`https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&${e}`,r=(e,t)=>[`CallExpression[callee.name=${`/${e.source}/${e.flags}`}][arguments.0.name=${typeof t==`string`?`'${t}'`:`/${t.source}/${t.flags}`}]`,`.arguments`,`Property[key.name='children'] Literal`].join(` > `),i=e=>{if(!e.size)return``;let t=[];for(let n of e.values())t.push(n);return`icon_names=${t.toSorted().join(`,`)}`},a=({moduleIdRegex:a=/.([jt])sx?$/i,jsxNodeRegex:o=/jsx/,component:s=`Icon`,getUrl:c=n,preload:l=!1}={})=>{let u=new Set;return{name:`material-symbols`,enforce:`pre`,moduleParsed:function({id:n,code:i}){if(!i||!a.test(n))return;let c=this.parse(i),l=r(o,s),d=e.query(c,l).filter(t);for(let{value:e}of d)this.debug({id:n,message:e}),u.add(e)},transformIndexHtml:e=>{let t=c(i(u)),n=[{injectTo:`head`,tag:`link`,attrs:{rel:`stylesheet`,href:t}}];return l&&n.push({injectTo:`head-prepend`,tag:`link`,attrs:{rel:`preload`,as:`style`,href:t}},{injectTo:`head-prepend`,tag:`link`,attrs:{rel:`preconnect`,href:`https://fonts.gstatic.com`}}),{html:e,tags:n}}}};export{a as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-material-symbols",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Selective loading of Material Symbols for production",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "scripts": {
14
14
  "lint": "bun run biome check",
15
15
  "prebuild": "tsc --noEmit",
16
- "build": "tsdown",
16
+ "build": "bunx --bun tsdown",
17
17
  "mdfix": "bunx --bun prettier *.md --write",
18
18
  "version": "bun run tools/version.ts",
19
19
  "prepublishOnly": "bun lint && bun test && bun run build"