vite-plugin-material-symbols 0.7.0 → 0.8.0

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,20 @@
2
2
 
3
3
  ## Version 0
4
4
 
5
+ ### v0.8.0
6
+
7
+ - Replaced `getUrl` option with two new ones:
8
+ - `fontUrl` (string): Material Symbols CSS Provider;
9
+ - `paramName` (string): The name of the query parameter to add to the `fontUrl` (default: "icon_names");
10
+ - The plugin will automatically add the query parameter with the icon names list to the font URL.
11
+
12
+ ### v0.7.1
13
+
14
+ - Added the following configuration options for flexibility:
15
+ - `moduleIdRegex` — the regex to match module IDs that should be processed for finding icon names;
16
+ - `jsxNodeRegex` — The regex to match JSX nodes that should be processed in parsed AST;
17
+ - The option `component` now also can be a regex to match multiple component names.
18
+
5
19
  ### v0.7.0
6
20
 
7
21
  - Supporting Vite 8;
package/README.md CHANGED
@@ -98,17 +98,27 @@ 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
- getUrl:
106
- type: function
113
+ fontUrl:
114
+ type: string
107
115
  description: Material Symbols CSS Provider
108
- arguments: [string] # icon_names parameter
109
- exampleArguments: ["icon_names=chevron_right,comment,home"] # can be empty string
110
- returns: string # the URL
111
- default: (iconNamesParam) => `https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&${iconNamesParam}`
116
+ # Standard settings: Outlined, no infill, 24px, weight 400
117
+ default: https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0
118
+ paramName:
119
+ type: string
120
+ description: The name of the query parameter to add to the fontUrl
121
+ default: icon_names
112
122
  preload:
113
123
  type: boolean
114
124
  description: Enables higher priority for loading symbols
package/dist/index.d.ts CHANGED
@@ -2,17 +2,32 @@ 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
8
- * @default () => `https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined...&${iconNamesParam}`
18
+ * @default "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0"
19
+ * */
20
+ fontUrl: string;
21
+ /**
22
+ * The name of the query parameter to add to the fontUrl
23
+ * @default "icon_names"
9
24
  * */
10
- getUrl: (iconNamesParam: string) => string;
25
+ paramName: string;
11
26
  /**
12
- * The name of JSX component to obtain the icon names from
13
- * @default Icon
27
+ * The name of JSX component to get the icon names from (or regex to match the component name)
28
+ * @default "Icon"
14
29
  * */
15
- component: string;
30
+ component: string | RegExp;
16
31
  /**
17
32
  * Enables higher priority for loading symbols
18
33
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload
@@ -22,8 +37,11 @@ type PluginOptions = {
22
37
  preload: boolean;
23
38
  };
24
39
  declare const plugin: ({
40
+ moduleIdRegex,
41
+ jsxNodeRegex,
25
42
  component,
26
- getUrl,
43
+ fontUrl,
44
+ paramName,
27
45
  preload
28
46
  }?: Partial<PluginOptions>) => Plugin;
29
47
  //#endregion
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,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(` > `),r=(e,t,n)=>{let r=new URL(e);if(n.size){let e=[];for(let t of n.values())e.push(t);r.searchParams.append(t,e.toSorted().join(`,`))}return decodeURIComponent(r.toString())},i=({moduleIdRegex:i=/.([jt])sx?$/i,jsxNodeRegex:a=/jsx/,component:o=`Icon`,fontUrl:s=`https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0`,paramName:c=`icon_names`,preload:l=!1}={})=>{let u=new Set;return{name:`material-symbols`,enforce:`pre`,moduleParsed:function({id:r,code:s}){if(!s||!i.test(r))return;let c=this.parse(s),l=n(a,o),d=e.query(c,l).filter(t);for(let{value:e}of d)this.debug({id:r,message:e}),u.add(e)},transformIndexHtml:e=>{let t=r(s,c,u).toString(),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{i 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.8.0",
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"