vite-svg-2-webfont
Advanced tools
Comparing version 0.0.8 to 0.1.0
@@ -1,1 +0,1 @@ | ||
import{promisify as H}from"util";import S from"@vusion/webfonts-generator";import{resolve as I}from"path";import{constants as D}from"fs";import{watch as M,access as P}from"fs/promises";var h,b={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function W(e,t){let n=I(e,t);try{return await P(n,D.R_OK),!0}catch{return!1}}async function E(e,{eventType:t,filename:n},s,i=W){t!=="rename"||!n.endsWith(".svg")||!await i(e,n)||s({eventType:t,filename:n})}async function w(e,t,n){try{h=M(e,{signal:t});for await(let s of h)E(e,s,n)}catch(s){if(s.name==="AbortError")return;throw s}}var y="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";function x(e=8){let t="";for(let n=0;n<e;n++){let s=Math.floor(Math.random()*y.length);t+=y[s]}return t}import N from"glob";import{resolve as l}from"path";var{sync:R}=N;function C({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function g({files:e,context:t}){return e||=["*.svg"],e.flatMap(n=>R(n,{cwd:t})).map(n=>`${t}/${n}`)}function v(e){let t=C(e),n=g(e);return e.dest||=l(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:Boolean(e.html??e.htmlDest),css:Boolean(e.css??e.cssDest),ligature:e.ligature??!0,writeFiles:e.writeFiles??!1,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,...e.cssDest&&{cssDest:l(e.dest,e.cssDest,e.fontName.toLowerCase()+".css")},...e.cssTemplate&&{cssTemplate:l(e.dest,e.cssTemplate)},...e.cssFontsUrl&&{cssFontsUrl:l(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:l(e.dest,e.htmlTemplate)},...e.htmlDest&&{htmlDest:l(e.dest,e.htmlDest,e.fontName.toLowerCase()+".html")},...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 F=new AbortController,_=H(S),O="virtual:vite-svg-2-webfont.css",c=`\0${O}`;function $(e){let t=v(e),n,s,i,u,o,p=async r=>{if(r&&(t.files=g(e)),o=await _(t),r){let a=i==null?void 0:i.getModuleById(c);a&&u&&u(a)}};return{name:"vite-svg-2-webfont",configResolved(r){n=r.command==="build"},resolveId(r){if(r===O)return c},transform(r,a){var d;if(a===c)return((d=o==null?void 0:o.generateCss)==null?void 0:d.call(o,s))||""},load(r){if(r===c)return c},async buildStart(){if(n||w(e.context,F.signal,()=>p(!0)),await p(),n){let r=t.types.map(a=>[a,`/${this.getFileName(this.emitFile({type:"asset",fileName:`assets/${t.fontName}-${x()}.${a}`,source:o==null?void 0:o[a]}))}`]);s=Object.fromEntries(r)}},configureServer({middlewares:r,reloadModule:a,moduleGraph:d}){for(let m of t.types){let G=`${t.fontName}.${m}`;r.use(`/${G}`,(z,f)=>{if(i=d,u=a,!o)return f.statusCode=404,f.end();let T=o[m];return f.setHeader("content-type",b[m]),f.setHeader("content-length",T.length),f.statusCode=200,f.end(T)})}},buildEnd(){F.abort()}}}var X=$;export{X as default,$ as viteSvgToWebfont}; | ||
import{promisify as S}from"util";import _ from"@vusion/webfonts-generator";import{resolve as M}from"path";import{constants as P}from"fs";import{watch as R,access as W}from"fs/promises";var T,b={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function D(e,t){let n=M(e,t);try{return await W(n,P.R_OK),!0}catch{return!1}}async function N(e,{eventType:t,filename:n},r,a=D){t!=="rename"||!n.endsWith(".svg")||!await a(e,n)||r({eventType:t,filename:n})}async function x(e,t,n){try{T=R(e,{signal:t});for await(let r of T)N(e,r,n)}catch(r){if(r.name==="AbortError")return;throw r}}var y="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";function w(e=8){let t="";for(let n=0;n<e;n++){let r=Math.floor(Math.random()*y.length);t+=y[r]}return t}function v(e){var n;return Boolean((n=/(?:\.([^.]+))?$/.exec(e||""))==null?void 0:n[1])}import $ from"glob";import{resolve as l}from"path";var{sync:C}=$;function H({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function g({files:e,context:t}){return e||=["*.svg"],e.flatMap(n=>C(n,{cwd:t})).map(n=>`${t}/${n}`)}function F(e,t,n,r){return v(t)?l(e,t):l(e,t,`${n.toLowerCase()}.${r}`)}function O(e){let t=H(e),n=g(e);return e.dest||=l(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:Boolean(e.html??e.htmlDest),css:Boolean(e.css??e.cssDest),ligature:e.ligature??!0,writeFiles:e.writeFiles??!1,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,...e.cssDest&&{cssDest:F(e.dest,e.cssDest,e.fontName,"css")},...e.cssTemplate&&{cssTemplate:l(e.dest,e.cssTemplate)},...e.cssFontsUrl&&{cssFontsUrl:l(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:l(e.dest,e.htmlTemplate)},...e.htmlDest&&{htmlDest:F(e.dest,e.htmlDest,e.fontName.toLowerCase(),"html")},...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 G=new AbortController,z=S(_),I="virtual:vite-svg-2-webfont.css",c=`\0${I}`;function U(e){let t=O(e),n,r,a,u,o,p=async s=>{if(s&&(t.files=g(e)),o=await z(t),s){let i=a==null?void 0:a.getModuleById(c);i&&u&&u(i)}};return{name:"vite-svg-2-webfont",enforce:"pre",configResolved(s){n=s.command==="build"},resolveId(s){if(s===I)return c},transform(s,i){var d;if(i===c)return((d=o==null?void 0:o.generateCss)==null?void 0:d.call(o,r))||""},load(s){if(s===c)return c},async buildStart(){if(n||x(e.context,G.signal,()=>p(!0)),await p(),n){let s=t.types.map(i=>[i,`/${this.getFileName(this.emitFile({type:"asset",fileName:`assets/${t.fontName}-${w()}.${i}`,source:o==null?void 0:o[i]}))}`]);r=Object.fromEntries(s)}},configureServer({middlewares:s,reloadModule:i,moduleGraph:d}){for(let m of t.types){let E=`${t.fontName}.${m}`;s.use(`/${E}`,(A,f)=>{if(a=d,u=i,!o)return f.statusCode=404,f.end();let h=o[m];return f.setHeader("content-type",b[m]),f.setHeader("content-length",h.length),f.statusCode=200,f.end(h)})}},buildEnd(){G.abort()}}}var te=U;export{te as default,U as viteSvgToWebfont}; |
{ | ||
"name": "vite-svg-2-webfont", | ||
"version": "0.0.8", | ||
"version": "0.1.0", | ||
"description": "A vite plugin which generates a webfont out of svg icons", | ||
@@ -53,2 +53,3 @@ "type": "module", | ||
"@types/node": "^18.11.18", | ||
"@types/node-fetch": "^2.6.2", | ||
"@types/vusion__webfonts-generator": "^0.8.0", | ||
@@ -59,2 +60,3 @@ "@typescript-eslint/eslint-plugin": "^5.47.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
"node-fetch": "^3.3.0", | ||
"prettier": "^2.8.1", | ||
@@ -61,0 +63,0 @@ "tsup": "^6.5.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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25312
0
14