vite-svg-2-webfont
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -132,2 +132,9 @@ import _webfontGenerator, { GeneratedFontTypes } from '@vusion/webfonts-generator'; | ||
baseSelector?: string; | ||
/** | ||
* Virtual module id which is used by Vite to import the plugin artifacts. | ||
* E.g. the default value is "vite-svg-2-webfont.css" so "virtual:vite-svg-2-webfont.css" should be imported. | ||
* | ||
* @default 'vite-svg-2-webfont.css' | ||
*/ | ||
moduleId?: string; | ||
} | ||
@@ -134,0 +141,0 @@ |
@@ -1,1 +0,1 @@ | ||
import{promisify as q}from"util";import A from"@vusion/webfonts-generator";import{constants as R}from"fs";import{resolve as S,dirname as _}from"path";import{watch as C,access as D,mkdir as H,writeFile as L}from"fs/promises";var w,v={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function k(e,t){let n=S(e,t);try{return await D(n,R.R_OK),!0}catch{return!1}}async function z(e,{eventType:t,filename:n},r,l=k){t!=="rename"||!n.endsWith(".svg")||!await l(e,n)||r({eventType:t,filename:n})}async function O(e,t,n){try{w=C(e,{signal:t});for await(let r of w)z(e,r,n)}catch(r){if(r.name==="AbortError")return;throw r}}var F="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";function P(e=8){let t="";for(let n=0;n<e;n++){let r=Math.floor(Math.random()*F.length);t+=F[r]}return t}function E(e){var n;return Boolean((n=/(?:\.([^.]+))?$/.exec(e||""))==null?void 0:n[1])}async function y(e,t){let n={mode:511,recursive:!0};await H(_(t),n),await L(t,e)}import U from"glob";import{resolve as f}from"path";var u=class extends Error{},m=class extends Error{constructor(t){super(`WriteFiles option received invalid types: ${t.join(", ")}`)}};var{sync:B}=U,G=["html","css","fonts"];function Y({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function h({files:e,context:t}){e||=["*.svg"];let n=e.flatMap(r=>B(r,{cwd:t})).map(r=>`${t}/${r}`);if(!n.length)throw new u("The specified file globs did not resolve any files in the context.");return n}function I(e,t,n,r){return t?E(t)?f(e,t):f(e,t,`${n.toLowerCase()}.${r}`):f(e,`${n.toLowerCase()}.${r}`)}function j({generateFiles:e}){if(!e||typeof e=="boolean")return e?G:[];Array.isArray(e)||(e=[e]);let t=e.filter(n=>!G.includes(n));if(t.length)throw new m(t);return e}function V(e){let t=new Set(j(e));return{fonts:t.has("fonts"),html:t.has("html"),css:t.has("css")}}function W(e){let t=Y(e),n=h(e),r=V(e);return e.dest||=f(e.context,"..","artifacts"),e.fontName||="iconfont",{files:n,types:t,order:t,fontName:e.fontName,fontHeight:e.fontHeight||1e3,codepoints:e.codepoints||{},templateOptions:{baseSelector:e.baseSelector||".icon",classPrefix:e.classPrefix??"icon-"},html:r.html,css:r.css,ligature:e.ligature??!0,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,writeFiles:r.fonts,cssDest:I(e.dest,e.cssDest,e.fontName,"css"),htmlDest:I(e.dest,e.htmlDest,e.fontName,"html"),...e.cssTemplate&&{cssTemplate:f(e.dest,e.cssTemplate)},...e.cssFontsUrl&&{cssFontsUrl:f(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:f(e.dest,e.htmlTemplate)},...typeof e.fixedWidth<"u"&&{fixedWidth:e.fixedWidth},...typeof e.centerHorizontally<"u"&&{centerHorizontally:e.centerHorizontally},...typeof e.normalize<"u"&&{normalize:e.normalize},...typeof e.round<"u"&&{round:e.round},...typeof e.descent<"u"&&{descent:e.descent}}}var $=new AbortController,K=q(A),M="virtual:vite-svg-2-webfont.css",d=`\0${M}`;function J(e){let t=W(e),n,r,l,p,o,T=[],b=async s=>{s&&(t.files=h(e)),n&&(t.writeFiles=!1),o=await K(t);let a=!t.writeFiles&&(t.css||t.html);if(!n&&a){let i=[];t.css&&i.push(y(o.generateCss(),t.cssDest)),t.html&&i.push(y(o.generateHtml(),t.htmlDest)),await Promise.all(i)}if(s){let i=l==null?void 0:l.getModuleById(d);i&&p&&p(i)}};return{name:"vite-svg-2-webfont",enforce:"pre",api:{getGeneratedWebfonts(){return T}},configResolved(s){n=s.command==="build"},resolveId(s){if(s===M)return d},transform(s,a){var i;if(a===d)return((i=o==null?void 0:o.generateCss)==null?void 0:i.call(o,r))||""},load(s){if(s===d)return d},async buildStart(){if(n||O(e.context,$.signal,()=>b(!0)),await b(),n){let s=t.types.map(a=>[a,`/${this.getFileName(this.emitFile({type:"asset",fileName:`assets/${t.fontName}-${P()}.${a}`,source:o==null?void 0:o[a]}))}`]);s.forEach(([a,i])=>{T.push({type:a,href:i})}),r=Object.fromEntries(s)}},configureServer({middlewares:s,reloadModule:a,moduleGraph:i}){for(let g of t.types){let N=`${t.fontName}.${g}`;s.use(`/${N}`,(Q,c)=>{if(l=i,p=a,!o)return c.statusCode=404,c.end();let x=o[g];return c.setHeader("content-type",v[g]),c.setHeader("content-length",x.length),c.statusCode=200,c.end(x)})}},buildEnd(){$.abort()}}}var ue=J;var me=A.templates;export{ue as default,me as templates,J as viteSvgToWebfont}; | ||
import{promisify as K}from"util";import A from"@vusion/webfonts-generator";import{constants as C}from"fs";import{resolve as R,dirname as H}from"path";import{watch as _,access as D,mkdir as k,writeFile as z}from"fs/promises";var w,I={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function L(e,t){let n=R(e,t);try{return await D(n,C.R_OK),!0}catch{return!1}}async function U(e,{eventType:t,filename:n},r,l=L){t!=="rename"||!n.endsWith(".svg")||!await l(e,n)||r({eventType:t,filename:n})}async function P(e,t,n){try{w=_(e,{signal:t});for await(let r of w)U(e,r,n)}catch(r){if(r.name==="AbortError")return;throw r}}var F="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";function O(e=8){let t="";for(let n=0;n<e;n++){let r=Math.floor(Math.random()*F.length);t+=F[r]}return t}function G(e){var n;return Boolean((n=/(?:\.([^.]+))?$/.exec(e||""))==null?void 0:n[1])}async function y(e,t){let n={mode:511,recursive:!0};await k(H(t),n),await z(t,e)}import B from"glob";import{resolve as f}from"path";var u=class extends Error{},m=class extends Error{constructor(t){super(`WriteFiles option received invalid types: ${t.join(", ")}`)}};var{sync:Y}=B,E=["html","css","fonts"];function j({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function T({files:e,context:t}){e||=["*.svg"];let n=e.flatMap(r=>Y(r,{cwd:t})).map(r=>`${t}/${r}`);if(!n.length)throw new u("The specified file globs did not resolve any files in the context.");return n}function W(e,t,n,r){return t?G(t)?f(e,t):f(e,t,`${n.toLowerCase()}.${r}`):f(e,`${n.toLowerCase()}.${r}`)}function V({generateFiles:e}){if(!e||typeof e=="boolean")return e?E:[];Array.isArray(e)||(e=[e]);let t=e.filter(n=>!E.includes(n));if(t.length)throw new m(t);return e}function q(e){let t=new Set(V(e));return{fonts:t.has("fonts"),html:t.has("html"),css:t.has("css")}}function $(e){let t=j(e),n=T(e),r=q(e);return e.dest||=f(e.context,"..","artifacts"),e.fontName||="iconfont",{files:n,types:t,order:t,fontName:e.fontName,fontHeight:e.fontHeight||1e3,codepoints:e.codepoints||{},templateOptions:{baseSelector:e.baseSelector||".icon",classPrefix:e.classPrefix??"icon-"},html:r.html,css:r.css,ligature:e.ligature??!0,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,writeFiles:r.fonts,cssDest:W(e.dest,e.cssDest,e.fontName,"css"),htmlDest:W(e.dest,e.htmlDest,e.fontName,"html"),...e.cssTemplate&&{cssTemplate:f(e.dest,e.cssTemplate)},...e.cssFontsUrl&&{cssFontsUrl:f(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:f(e.dest,e.htmlTemplate)},...typeof e.fixedWidth<"u"&&{fixedWidth:e.fixedWidth},...typeof e.centerHorizontally<"u"&&{centerHorizontally:e.centerHorizontally},...typeof e.normalize<"u"&&{normalize:e.normalize},...typeof e.round<"u"&&{round:e.round},...typeof e.descent<"u"&&{descent:e.descent}}}var M=new AbortController,J=K(A),Q="vite-svg-2-webfont.css";function X(e){return`virtual:${e}`}function Z(e){return`\0${e}`}function ee(e){let t=$(e),n,r,l,p,s,h=[],N=e.moduleId??Q,x=X(N),d=Z(x),b=async o=>{o&&(t.files=T(e)),n&&(t.writeFiles=!1),s=await J(t);let a=!t.writeFiles&&(t.css||t.html);if(!n&&a){let i=[];t.css&&i.push(y(s.generateCss(),t.cssDest)),t.html&&i.push(y(s.generateHtml(),t.htmlDest)),await Promise.all(i)}if(o){let i=l==null?void 0:l.getModuleById(d);i&&p&&p(i)}};return{name:"vite-svg-2-webfont",enforce:"pre",api:{getGeneratedWebfonts(){return h}},configResolved(o){n=o.command==="build"},resolveId(o){if(o===x)return d},transform(o,a){var i;if(a===d)return((i=s==null?void 0:s.generateCss)==null?void 0:i.call(s,r))||""},load(o){if(o===d)return d},async buildStart(){if(n||P(e.context,M.signal,()=>b(!0)),await b(),n){let o=t.types.map(a=>[a,`/${this.getFileName(this.emitFile({type:"asset",fileName:`assets/${t.fontName}-${O()}.${a}`,source:s==null?void 0:s[a]}))}`]);o.forEach(([a,i])=>{h.push({type:a,href:i})}),r=Object.fromEntries(o)}},configureServer({middlewares:o,reloadModule:a,moduleGraph:i}){for(let g of t.types){let S=`${t.fontName}.${g}`;o.use(`/${S}`,(te,c)=>{if(l=i,p=a,!s)return c.statusCode=404,c.end();let v=s[g];return c.setHeader("content-type",I[g]),c.setHeader("content-length",v.length),c.statusCode=200,c.end(v)})}},buildEnd(){M.abort()}}}var ye=ee;var Te=A.templates;export{ye as default,Te as templates,ee as viteSvgToWebfont}; |
{ | ||
"name": "vite-svg-2-webfont", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A vite plugin which generates a webfont out of svg icons", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -253,2 +253,8 @@ # vite-svg-2-webfont | ||
### moduleId | ||
- **type**: `string` | ||
- **description**: Virtual module id which is used by Vite to import the plugin artifacts. E.g. the default value is "vite-svg-2-webfont.css" so "virtual:vite-svg-2-webfont.css" should be imported. | ||
- **default** `'vite-svg-2-webfont.css'` | ||
## Public API | ||
@@ -255,0 +261,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29304
194
272