Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-svg-2-webfont

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-svg-2-webfont - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

6

dist/index.d.ts

@@ -149,2 +149,8 @@ import _vusion_webfonts_generator, { GeneratedFontTypes, CSSTemplateContext, WebfontsGeneratorOptions } from '@vusion/webfonts-generator';

inline?: boolean;
/**
* Allow outputting assets (HTML, CSS, and Fonts) during build.
* @see {@link https://github.com/atlowChemi/vite-svg-2-webfont/issues/32#issuecomment-2203187501}
* @default false
*/
allowWriteFilesInBuild?: boolean;
}

@@ -151,0 +157,0 @@

2

dist/index.js

@@ -1,1 +0,1 @@

import{promisify as re}from"util";import H from"@vusion/webfonts-generator";import{constants as N,rm as B,mkdtempSync as k}from"fs";import{resolve as U,dirname as z,join as L}from"path";import{watch as j,access as Y,mkdir as V,writeFile as J}from"fs/promises";import{tmpdir as q}from"node:os";import{createHash as K}from"node:crypto";var O,y={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function Q(e,t){let n=U(e,t);try{return await Y(n,N.R_OK),!0}catch{return!1}}async function X(e,{eventType:t,filename:n},s,l=Q){t!=="rename"||!(n!=null&&n.endsWith(".svg"))||!await l(e,n)||s({eventType:t,filename:n})}async function G(e,t,n){try{O=j(e,{signal:t});for await(let s of O)X(e,s,n)}catch(s){if(s.name==="AbortError")return;throw s}}function W(e){return K("sha256").update(e).digest("hex")}function E(e){var n;return!!((n=/(?:\.([^.]+))?$/.exec(e||""))!=null&&n[1])}async function p(e,t){let n={mode:511,recursive:!0};await V(z(t),n),await J(t,e)}function C(){return k(L(q(),"__vite-svg-2-webfont-"))}function $(e){B(e,{force:!0,recursive:!0},()=>{})}import{resolve as d}from"path";import{globSync as Z}from"glob";var g=class extends Error{},h=class extends Error{constructor(t){super(`WriteFiles option received invalid types: ${t.join(", ")}`)}};var S=["html","css","fonts"];function ee({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function b({files:e,context:t}){var s;e||=["*.svg"];let n=((s=Z(e,{cwd:t}))==null?void 0:s.map(l=>`${t}/${l}`))||[];if(!n.length)throw new g("The specified file globs did not resolve any files in the context.");return n}function A(e,t,n,s){return t?E(t)?d(e,t):d(e,t,`${n.toLowerCase()}.${s}`):d(e,`${n.toLowerCase()}.${s}`)}function te({generateFiles:e}){if(!e||typeof e=="boolean")return e?S:[];Array.isArray(e)||(e=[e]);let t=e.filter(n=>!S.includes(n));if(t.length)throw new h(t);return e}function ne(e){let t=new Set(te(e));return{fonts:t.has("fonts"),html:t.has("html"),css:t.has("css")}}function _(e){let t=ee(e),n=b(e),s=ne(e);return e.dest||=d(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:s.html,css:s.css,ligature:e.ligature??!0,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,writeFiles:s.fonts,cssDest:A(e.dest,e.cssDest,e.fontName,"css"),htmlDest:A(e.dest,e.htmlDest,e.fontName,"html"),...e.cssTemplate&&{cssTemplate:d(e.dest,e.cssTemplate)},...e.cssContext&&{cssContext:e.cssContext},...e.cssFontsUrl&&{cssFontsUrl:d(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:d(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}}}import{join as oe}from"node:path";var M=new AbortController,se=re(H),ie="vite-svg-2-webfont.css",D=C();function fe(e){return`virtual:${e}`}function ae(e){return`\0${e}`}function le(e){let t=_(e),n,s,l,T,i,x=[],v=[],R=e.moduleId??ie,w=fe(R),m=ae(w),F=o=>e.inline?o==null?void 0:o.replace(/url\(".*?\.([^?]+)\?[^"]+"\)/g,(f,r)=>{let a=Buffer.from((i==null?void 0:i[r])||[]);return`url("data:${y[r]};charset=utf-8;base64,${a.toString("base64")}")`}):o,P=async o=>{o&&(t.files=b(e)),n&&(t.writeFiles=!1),i=await se(t);let f=!t.writeFiles&&(t.css||t.html);if(!n&&f){let r=[];t.css&&r.push(p(F(i.generateCss()),t.cssDest)),t.html&&r.push(p(i.generateHtml(),t.htmlDest)),await Promise.all(r)}if(o){let r=l==null?void 0:l.getModuleById(m);r&&T&&T(r)}};return{name:"vite-svg-2-webfont",enforce:"pre",api:{getGeneratedWebfonts(){return x}},configResolved(o){n=o.command==="build"},resolveId(o){if(o===w)return m},generateBundle(o,f){for(let{type:r,href:a}of v)for(let c of Object.values(f))c.name&&a.endsWith(c.name)&&x.push({type:r,href:`/${c.fileName}`})},transform(o,f){var r;if(f===m)return F((r=i==null?void 0:i.generateCss)==null?void 0:r.call(i,s))||""},load(o){if(o===m)return m},async buildStart(){if(n||G(e.context,M.signal,()=>P(!0)),await P(),n&&!e.inline){let o=t.types.map(f=>{if(!(i!=null&&i[f]))throw new Error(`Failed to generate font of type ${f}`);let r=Buffer.from(i[f]),a=W(r),c=oe(D,`${t.fontName}-${a}.${f}`);return p(r,c),[f,c]});o.forEach(([f,r])=>{v.push({type:f,href:r})}),s=Object.fromEntries(o)}},configureServer({middlewares:o,reloadModule:f,moduleGraph:r}){if(!e.inline)for(let a of t.types){let c=`${t.fontName}.${a}`;o.use(`/${c}`,(ce,u)=>{if(l=r,T=f,!i)return u.statusCode=404,u.end();let I=i[a];return u.setHeader("content-type",y[a]),u.setHeader("content-length",I.length),u.statusCode=200,u.end(I)})}},buildEnd(){M.abort(),$(D)}}}var We=le;var Ee=H.templates;export{We as default,Ee as templates,le as viteSvgToWebfont};
import{promisify as re}from"util";import D from"@vusion/webfonts-generator";import{constants as R,rm as N,mkdtempSync as k}from"fs";import{resolve as U,dirname as z,join as L}from"path";import{watch as j,access as Y,mkdir as V,writeFile as J}from"fs/promises";import{tmpdir as q}from"node:os";import{createHash as K}from"node:crypto";var W,y={eot:"application/vnd.ms-fontobject",svg:"image/svg+xml",ttf:"application/x-font-ttf",woff:"application/font-woff",woff2:"font/woff2"};async function Q(e,t){let n=U(e,t);try{return await Y(n,R.R_OK),!0}catch{return!1}}async function X(e,{eventType:t,filename:n},o,l=Q){t!=="rename"||!(n!=null&&n.endsWith(".svg"))||!await l(e,n)||o({eventType:t,filename:n})}async function O(e,t,n){try{W=j(e,{signal:t});for await(let o of W)X(e,o,n)}catch(o){if(o.name==="AbortError")return;throw o}}function G(e){return K("sha256").update(e).digest("hex")}function E(e){var n;return!!((n=/(?:\.([^.]+))?$/.exec(e||""))!=null&&n[1])}async function p(e,t){let n={mode:511,recursive:!0};await V(z(t),n),await J(t,e)}function C(){return k(L(q(),"__vite-svg-2-webfont-"))}function $(e){N(e,{force:!0,recursive:!0},()=>{})}import{resolve as d}from"path";import{globSync as Z}from"glob";var g=class extends Error{},h=class extends Error{constructor(t){super(`WriteFiles option received invalid types: ${t.join(", ")}`)}};var S=["html","css","fonts"];function ee({types:e}){return Array.isArray(e)?e:e?[e]:["eot","woff","woff2","ttf","svg"]}function b({files:e,context:t}){var o;e||=["*.svg"];let n=((o=Z(e,{cwd:t}))==null?void 0:o.map(l=>`${t}/${l}`))||[];if(!n.length)throw new g("The specified file globs did not resolve any files in the context.");return n}function A(e,t,n,o){return t?E(t)?d(e,t):d(e,t,`${n.toLowerCase()}.${o}`):d(e,`${n.toLowerCase()}.${o}`)}function te({generateFiles:e}){if(!e||typeof e=="boolean")return e?S:[];Array.isArray(e)||(e=[e]);let t=e.filter(n=>!S.includes(n));if(t.length)throw new h(t);return e}function ne(e){let t=new Set(te(e));return{fonts:t.has("fonts"),html:t.has("html"),css:t.has("css")}}function _(e){let t=ee(e),n=b(e),o=ne(e);return e.dest||=d(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:o.html,css:o.css,ligature:e.ligature??!0,formatOptions:e.formatOptions||{},dest:e.dest.endsWith("/")?e.dest:`${e.dest}/`,writeFiles:o.fonts,cssDest:A(e.dest,e.cssDest,e.fontName,"css"),htmlDest:A(e.dest,e.htmlDest,e.fontName,"html"),...e.cssTemplate&&{cssTemplate:d(e.dest,e.cssTemplate)},...e.cssContext&&{cssContext:e.cssContext},...e.cssFontsUrl&&{cssFontsUrl:d(e.dest,e.cssFontsUrl)},...e.htmlTemplate&&{htmlTemplate:d(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}}}import{join as oe}from"node:path";var M=new AbortController,se=re(D),ie="vite-svg-2-webfont.css",B=C();function fe(e){return`virtual:${e}`}function ae(e){return`\0${e}`}function le(e){let t=_(e),n,o,l,T,s,x=[],w=[],H=e.moduleId??ie,v=fe(H),m=ae(v),F=r=>e.inline?r==null?void 0:r.replace(/url\(".*?\.([^?]+)\?[^"]+"\)/g,(f,i)=>{let a=Buffer.from((s==null?void 0:s[i])||[]);return`url("data:${y[i]};charset=utf-8;base64,${a.toString("base64")}")`}):r,I=async r=>{r&&(t.files=b(e)),n&&!e.allowWriteFilesInBuild&&(t.writeFiles=!1),s=await se(t);let f=!t.writeFiles&&(t.css||t.html);if(!n&&f&&await Promise.all([t.css&&p(F(s.generateCss()),t.cssDest),t.html&&p(s.generateHtml(),t.htmlDest)]),r){let i=l==null?void 0:l.getModuleById(m);i&&T&&T(i)}};return{name:"vite-svg-2-webfont",enforce:"pre",api:{getGeneratedWebfonts(){return x}},configResolved(r){n=r.command==="build"},resolveId(r){if(r===v)return m},generateBundle(r,f){for(let{type:i,href:a}of w)for(let c of Object.values(f))c.name&&a.endsWith(c.name)&&x.push({type:i,href:`/${c.fileName}`})},transform(r,f){var i;if(f===m)return F((i=s==null?void 0:s.generateCss)==null?void 0:i.call(s,o))||""},load(r){if(r===m)return m},async buildStart(){if(n||O(e.context,M.signal,()=>I(!0)),await I(),n&&!e.inline){let r=t.types.map(f=>{if(!(s!=null&&s[f]))throw new Error(`Failed to generate font of type ${f}`);let i=Buffer.from(s[f]),a=G(i),c=oe(B,`${t.fontName}-${a}.${f}`);return p(i,c),[f,c]});r.forEach(([f,i])=>{w.push({type:f,href:i})}),o=Object.fromEntries(r)}},configureServer({middlewares:r,reloadModule:f,moduleGraph:i}){if(!e.inline)for(let a of t.types){let c=`${t.fontName}.${a}`;r.use(`/${c}`,(ce,u)=>{if(l=i,T=f,!s)return u.statusCode=404,u.end();let P=s[a];return u.setHeader("content-type",y[a]),u.setHeader("content-length",P.length),u.statusCode=200,u.end(P)})}},buildEnd(){M.abort(),$(B)}}}var Ge=le;var Ee=D.templates;export{Ge as default,Ee as templates,le as viteSvgToWebfont};
{
"name": "vite-svg-2-webfont",
"version": "3.3.0",
"version": "3.4.0",
"description": "A vite plugin which generates a webfont out of svg icons",

@@ -5,0 +5,0 @@ "type": "module",

@@ -271,2 +271,8 @@ # vite-svg-2-webfont

### allowWriteFilesInBuild
- **type**: `boolean`
- **description**: Allow outputting assets (HTML, CSS, and Fonts) during build. [see](https://github.com/atlowChemi/vite-svg-2-webfont/issues/32#issuecomment-2203187501)
- **default** `false`
## Public API

@@ -273,0 +279,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc