svgicons2svgfont
Advanced tools
Comparing version 13.0.0 to 14.0.0
@@ -9,4 +9,4 @@ #! /usr/bin/env node | ||
import SVGIcons2SVGFontStream from '../dist/index.js'; | ||
import SVGIconsDirStream from '../dist/iconsdir.js'; | ||
import { SVGIcons2SVGFontStream } from '../dist/index.js'; | ||
import { SVGIconsDirStream } from '../dist/iconsdir.js'; | ||
@@ -13,0 +13,0 @@ const { version } = JSON.parse((await readFile(join(import.meta.dirname, '..', 'package.json'))).toString()); |
@@ -0,1 +1,5 @@ | ||
# [14.0.0](https://github.com/nfroidure/svgicons2svgfont/compare/v13.0.0...v14.0.0) (2024-07-30) | ||
# [13.0.0](https://github.com/nfroidure/svgicons2svgfont/compare/v12.0.0...v13.0.0) (2024-07-30) | ||
@@ -2,0 +6,0 @@ |
import { Readable } from 'node:stream'; | ||
import initMetadataService, { FileMetadata, MetadataServiceOptions } from './metadata.js'; | ||
import { getMetadataService, FileMetadata, MetadataServiceOptions } from './metadata.js'; | ||
export type SVGIconsDirStreamOptions = { | ||
metadataProvider: ReturnType<typeof initMetadataService>; | ||
metadataProvider: ReturnType<typeof getMetadataService>; | ||
}; | ||
@@ -19,2 +19,2 @@ export type SVGIconStream = Readable & { | ||
} | ||
export default SVGIconsDirStream; | ||
export { SVGIconsDirStream }; |
import { Readable } from 'node:stream'; | ||
import { createReadStream, readdir } from 'node:fs'; | ||
import { fileSorter } from './filesorter.js'; | ||
import initMetadataService from './metadata.js'; | ||
import { getMetadataService, } from './metadata.js'; | ||
class SVGIconsDirStream extends Readable { | ||
@@ -13,3 +13,3 @@ _options; | ||
this._options = { | ||
metadataProvider: options.metadataProvider || initMetadataService(options), | ||
metadataProvider: options.metadataProvider || getMetadataService(options), | ||
}; | ||
@@ -37,3 +37,3 @@ if (dir instanceof Array) { | ||
if (metadata.renamed) { | ||
this._options?.log?.('Saved codepoint: ' + | ||
console.log('➕ - Saved codepoint: ' + | ||
'u' + | ||
@@ -92,3 +92,3 @@ metadata.unicode[0] | ||
} | ||
export default SVGIconsDirStream; | ||
export { SVGIconsDirStream }; | ||
//# sourceMappingURL=iconsdir.js.map |
import { Transform } from 'stream'; | ||
import { SVGPathData } from 'svg-pathdata'; | ||
export { fileSorter } from './filesorter.js'; | ||
export * from './iconsdir.js'; | ||
export * from './metadata.js'; | ||
export type SVGIcons2SVGFontStreamOptions = { | ||
@@ -30,12 +33,8 @@ fontName: string; | ||
}; | ||
declare class SVGIcons2SVGFontStream extends Transform { | ||
export declare class SVGIcons2SVGFontStream extends Transform { | ||
private _options; | ||
glyphs: Glyph[]; | ||
log: typeof console.log; | ||
constructor(options: Partial<SVGIcons2SVGFontStreamOptions> & { | ||
log?: typeof console.log; | ||
}); | ||
constructor(options: Partial<SVGIcons2SVGFontStreamOptions>); | ||
_transform(svgIconStream: any, _unused: any, svgIconStreamCallback: any): void; | ||
_flush(svgFontFlushCallback: any): void; | ||
} | ||
export default SVGIcons2SVGFontStream; |
@@ -7,2 +7,6 @@ import { ucs2 } from 'punycode'; | ||
import { Matrix } from 'transformation-matrix-js'; | ||
import { YError } from 'yerror'; | ||
export { fileSorter } from './filesorter.js'; | ||
export * from './iconsdir.js'; | ||
export * from './metadata.js'; | ||
// Transform helpers (will move elsewhere later) | ||
@@ -88,6 +92,5 @@ function parseTransforms(value) { | ||
} | ||
class SVGIcons2SVGFontStream extends Transform { | ||
export class SVGIcons2SVGFontStream extends Transform { | ||
_options; | ||
glyphs; | ||
log; | ||
constructor(options) { | ||
@@ -106,3 +109,2 @@ super({ objectMode: true }); | ||
}; | ||
this.log = options.log || console.log.bind(console); | ||
} | ||
@@ -185,3 +187,3 @@ _transform(svgIconStream, _unused, svgIconStreamCallback) { | ||
else { | ||
this.log(`Glyph "${glyph.name}" has no width attribute, using current glyph horizontal bounds.`); | ||
console.log(`Glyph "${glyph.name}" has no width attribute, using current glyph horizontal bounds.`); | ||
glyph.defaultWidth = true; | ||
@@ -193,3 +195,3 @@ } | ||
else { | ||
this.log(`Glyph "${glyph.name}" has no height attribute, using current glyph vertical bounds.`); | ||
console.log(`Glyph "${glyph.name}" has no height attribute, using current glyph vertical bounds.`); | ||
glyph.defaultHeight = true; | ||
@@ -201,3 +203,3 @@ } | ||
// Clipping path unsupported | ||
this.log(`Found a clipPath element in the icon "${glyph.name}" the result may be different than expected.`); | ||
console.log(`Found a clipPath element in the icon "${glyph.name}" the result may be different than expected.`); | ||
} | ||
@@ -208,7 +210,7 @@ else if ('rect' === tag.name && 'none' !== tag.attributes.fill) { | ||
else if ('line' === tag.name && 'none' !== tag.attributes.fill) { | ||
this.log(`Found a line element in the icon "${glyph.name}" the result could be different than expected.`); | ||
console.log(`Found a line element in the icon "${glyph.name}" the result could be different than expected.`); | ||
glyph.paths.push(applyTransform(svgShapesToPath.lineToPath(tag.attributes))); | ||
} | ||
else if ('polyline' === tag.name && 'none' !== tag.attributes.fill) { | ||
this.log(`Found a polyline element in the icon "${glyph.name}" the result could be different than expected.`); | ||
console.log(`Found a polyline element in the icon "${glyph.name}" the result could be different than expected.`); | ||
glyph.paths.push(applyTransform(svgShapesToPath.polylineToPath(tag.attributes))); | ||
@@ -291,7 +293,7 @@ } | ||
: this.glyphs[0].height)) { | ||
this.log('The provided icons do not have the same heights. This could lead' + | ||
console.log('The provided icons do not have the same heights. This could lead' + | ||
' to unexpected results. Using the normalize option may help.'); | ||
} | ||
if (1000 > fontHeight) { | ||
this.log('A fontHeight of at least than 1000 is recommended, otherwise ' + | ||
console.log('A fontHeight of at least than 1000 is recommended, otherwise ' + | ||
'further steps (rounding in svg2ttf) could lead to ugly results.' + | ||
@@ -340,4 +342,5 @@ ' Use the fontHeight option to scale icons.'); | ||
: fontHeight / maxGlyphHeight; | ||
if (!isFinite(ratio)) | ||
throw new Error('foo'); | ||
if (!isFinite(ratio)) { | ||
throw new YError('E_BAD_COMPUTED_RATIO', ratio); | ||
} | ||
glyph.width *= ratio; | ||
@@ -391,3 +394,3 @@ glyph.height *= ratio; | ||
this.push(' </font>\n' + '</defs>\n' + '</svg>\n'); | ||
this.log('Font created'); | ||
console.log('Font created'); | ||
if ('function' === typeof this._options.callback) { | ||
@@ -399,3 +402,2 @@ this._options.callback(this.glyphs); | ||
} | ||
export default SVGIcons2SVGFontStream; | ||
//# sourceMappingURL=index.js.map |
export type MetadataServiceOptions = { | ||
prependUnicode: boolean; | ||
startUnicode: number; | ||
log: typeof console.log; | ||
err: typeof console.error; | ||
}; | ||
@@ -14,2 +12,2 @@ export type FileMetadata = { | ||
declare function getMetadataService(options?: Partial<MetadataServiceOptions>): (file: string, cb: (error: Error | null, metadata?: FileMetadata) => void) => void; | ||
export default getMetadataService; | ||
export { getMetadataService }; |
@@ -9,4 +9,2 @@ import { join, dirname, basename } from 'node:path'; | ||
startUnicode: 'number' === typeof options.startUnicode ? options.startUnicode : 0xea01, | ||
log: options.log || console.log, | ||
err: options.err || console.error, | ||
}; | ||
@@ -72,3 +70,3 @@ return function getMetadataFromFile(file, cb) { | ||
} | ||
export default getMetadataService; | ||
export { getMetadataService }; | ||
//# sourceMappingURL=metadata.js.map |
@@ -7,4 +7,4 @@ import { describe, test, expect } from '@jest/globals'; | ||
import { ucs2 as ucs2 } from 'punycode'; | ||
import SVGIcons2SVGFontStream from '../index.js'; | ||
import SVGIconsDirStream from '../iconsdir.js'; | ||
import { SVGIcons2SVGFontStream } from '../index.js'; | ||
import { SVGIconsDirStream } from '../iconsdir.js'; | ||
import streamtest from 'streamtest'; | ||
@@ -11,0 +11,0 @@ import { BufferStream } from 'bufferstreams'; |
import { describe, test, expect } from '@jest/globals'; | ||
import { writeFile, readFile, unlink } from 'node:fs/promises'; | ||
import { promisify } from 'node:util'; | ||
import metadata from '../metadata.js'; | ||
import { getMetadataService } from '../metadata.js'; | ||
import { YError } from 'yerror'; | ||
@@ -17,3 +17,3 @@ import { mkdir } from 'node:fs/promises'; | ||
test('should extract right unicodes from files', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/hello.svg'); | ||
@@ -28,8 +28,4 @@ expect(infos).toEqual({ | ||
test('should append unicodes to files when the option is set', async () => { | ||
const metadataService = metadata({ | ||
const metadataService = getMetadataService({ | ||
prependUnicode: true, | ||
log: () => { }, | ||
err: () => { | ||
throw new YError('E_NOT_SUPPOSED_TO_BE_HERE'); | ||
}, | ||
}); | ||
@@ -55,9 +51,5 @@ await writeFile(join('.', 'src', 'tests', 'results', 'plop.svg'), 'plop', 'utf-8'); | ||
test('should log file rename errors', async () => { | ||
const metadataService = metadata({ | ||
const metadataService = getMetadataService({ | ||
prependUnicode: true, | ||
startUnicode: 0xea02, | ||
err: () => { }, | ||
log: () => { | ||
throw new YError('E_NOT_SUPPOSED_TO_BE_HERE'); | ||
}, | ||
}); | ||
@@ -83,3 +75,3 @@ try { | ||
test('should work for simple codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/u0001-hello.svg'); | ||
@@ -94,3 +86,3 @@ expect(infos).toEqual({ | ||
test('should work for several codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/u0001,u0002-hello.svg'); | ||
@@ -105,3 +97,3 @@ expect(infos).toEqual({ | ||
test('should work for higher codepoint codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/u1F63A-hello.svg'); | ||
@@ -116,3 +108,3 @@ expect(infos).toEqual({ | ||
test('should work for ligature codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/u0001u0002-hello.svg'); | ||
@@ -127,3 +119,3 @@ expect(infos).toEqual({ | ||
test('should work for nested codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/u0001u0002,u0001-hello.svg'); | ||
@@ -141,3 +133,3 @@ expect(infos).toEqual({ | ||
test('should not set the same codepoint twice', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/uEA01-hello.svg'); | ||
@@ -159,3 +151,3 @@ expect(infos).toEqual({ | ||
test('should not set the same codepoint twice with different cases', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/UEA01-hello.svg'); | ||
@@ -162,0 +154,0 @@ expect(infos).toEqual({ |
@@ -27,3 +27,3 @@ { | ||
"name": "svgicons2svgfont", | ||
"version": "13.0.0", | ||
"version": "14.0.0", | ||
"description": "Read a set of SVG icons and output a SVG font", | ||
@@ -30,0 +30,0 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont", |
import { Readable } from 'node:stream'; | ||
import { createReadStream, readdir } from 'node:fs'; | ||
import { fileSorter } from './filesorter.js'; | ||
import initMetadataService, { | ||
import { | ||
getMetadataService, | ||
FileMetadata, | ||
@@ -10,7 +11,7 @@ MetadataServiceOptions, | ||
export type SVGIconsDirStreamOptions = { | ||
metadataProvider: ReturnType<typeof initMetadataService>; | ||
metadataProvider: ReturnType<typeof getMetadataService>; | ||
}; | ||
export type SVGIconStream = Readable & { | ||
metadata: Pick<FileMetadata, 'name' | 'unicode'>; | ||
} | ||
}; | ||
@@ -29,4 +30,3 @@ class SVGIconsDirStream extends Readable { | ||
this._options = { | ||
metadataProvider: | ||
options.metadataProvider || initMetadataService(options), | ||
metadataProvider: options.metadataProvider || getMetadataService(options), | ||
}; | ||
@@ -57,4 +57,4 @@ | ||
if (metadata.renamed) { | ||
this._options?.log?.( | ||
'Saved codepoint: ' + | ||
console.log( | ||
'➕ - Saved codepoint: ' + | ||
'u' + | ||
@@ -93,3 +93,5 @@ metadata.unicode[0] | ||
fileInfo = this.fileInfos.shift() as FileMetadata; | ||
svgIconStream = createReadStream(fileInfo.path) as unknown as SVGIconStream; | ||
svgIconStream = createReadStream( | ||
fileInfo.path, | ||
) as unknown as SVGIconStream; | ||
svgIconStream.metadata = { | ||
@@ -121,2 +123,2 @@ name: fileInfo.name, | ||
export default SVGIconsDirStream; | ||
export { SVGIconsDirStream }; |
@@ -7,3 +7,8 @@ import { ucs2 } from 'punycode'; | ||
import { Matrix } from 'transformation-matrix-js'; | ||
import { YError } from 'yerror'; | ||
export { fileSorter } from './filesorter.js'; | ||
export * from './iconsdir.js'; | ||
export * from './metadata.js'; | ||
// Transform helpers (will move elsewhere later) | ||
@@ -138,12 +143,7 @@ function parseTransforms(value) { | ||
class SVGIcons2SVGFontStream extends Transform { | ||
export class SVGIcons2SVGFontStream extends Transform { | ||
private _options: SVGIcons2SVGFontStreamOptions; | ||
glyphs: Glyph[]; | ||
log: typeof console.log; | ||
constructor( | ||
options: Partial<SVGIcons2SVGFontStreamOptions> & { | ||
log?: typeof console.log; | ||
}, | ||
) { | ||
constructor(options: Partial<SVGIcons2SVGFontStreamOptions>) { | ||
super({ objectMode: true }); | ||
@@ -163,4 +163,2 @@ | ||
}; | ||
this.log = options.log || console.log.bind(console); | ||
} | ||
@@ -303,3 +301,3 @@ | ||
} else { | ||
this.log( | ||
console.log( | ||
`Glyph "${glyph.name}" has no width attribute, using current glyph horizontal bounds.`, | ||
@@ -312,3 +310,3 @@ ); | ||
} else { | ||
this.log( | ||
console.log( | ||
`Glyph "${glyph.name}" has no height attribute, using current glyph vertical bounds.`, | ||
@@ -321,3 +319,3 @@ ); | ||
// Clipping path unsupported | ||
this.log( | ||
console.log( | ||
`Found a clipPath element in the icon "${glyph.name}" the result may be different than expected.`, | ||
@@ -330,3 +328,3 @@ ); | ||
} else if ('line' === tag.name && 'none' !== tag.attributes.fill) { | ||
this.log( | ||
console.log( | ||
`Found a line element in the icon "${glyph.name}" the result could be different than expected.`, | ||
@@ -338,3 +336,3 @@ ); | ||
} else if ('polyline' === tag.name && 'none' !== tag.attributes.fill) { | ||
this.log( | ||
console.log( | ||
`Found a polyline element in the icon "${glyph.name}" the result could be different than expected.`, | ||
@@ -410,2 +408,3 @@ ); | ||
const bounds = glyphPath.getBounds(); | ||
if (glyph.defaultHeight || this._options.usePathBounds) { | ||
@@ -430,2 +429,3 @@ glyph.height = bounds.maxY - bounds.minY; | ||
let fontWidth = maxGlyphWidth; | ||
if (this._options.normalize) { | ||
@@ -457,3 +457,3 @@ fontWidth = this.glyphs.reduce( | ||
) { | ||
this.log( | ||
console.log( | ||
'The provided icons do not have the same heights. This could lead' + | ||
@@ -464,3 +464,3 @@ ' to unexpected results. Using the normalize option may help.', | ||
if (1000 > fontHeight) { | ||
this.log( | ||
console.log( | ||
'A fontHeight of at least than 1000 is recommended, otherwise ' + | ||
@@ -515,3 +515,7 @@ 'further steps (rounding in svg2ttf) could lead to ugly results.' + | ||
: fontHeight / maxGlyphHeight; | ||
if (!isFinite(ratio)) throw new Error('foo'); | ||
if (!isFinite(ratio)) { | ||
throw new YError('E_BAD_COMPUTED_RATIO', ratio); | ||
} | ||
glyph.width *= ratio; | ||
@@ -593,3 +597,3 @@ glyph.height *= ratio; | ||
this.push(' </font>\n' + '</defs>\n' + '</svg>\n'); | ||
this.log('Font created'); | ||
console.log('Font created'); | ||
if ('function' === typeof this._options.callback) { | ||
@@ -601,3 +605,1 @@ this._options.callback(this.glyphs); | ||
} | ||
export default SVGIcons2SVGFontStream; |
@@ -7,4 +7,2 @@ import { join, dirname, basename } from 'node:path'; | ||
startUnicode: number; | ||
log: typeof console.log; | ||
err: typeof console.error; | ||
}; | ||
@@ -26,4 +24,2 @@ export type FileMetadata = { | ||
'number' === typeof options.startUnicode ? options.startUnicode : 0xea01, | ||
log: options.log || console.log, | ||
err: options.err || console.error, | ||
}; | ||
@@ -110,2 +106,2 @@ | ||
export default getMetadataService; | ||
export { getMetadataService }; |
@@ -9,4 +9,4 @@ import { describe, test, expect } from '@jest/globals'; | ||
import SVGIcons2SVGFontStream from '../index.js'; | ||
import SVGIconsDirStream, { type SVGIconStream } from '../iconsdir.js'; | ||
import { SVGIcons2SVGFontStream } from '../index.js'; | ||
import { SVGIconsDirStream, type SVGIconStream } from '../iconsdir.js'; | ||
import streamtest from 'streamtest'; | ||
@@ -13,0 +13,0 @@ import { BufferStream } from 'bufferstreams'; |
import { describe, test, expect } from '@jest/globals'; | ||
import { writeFile, readFile, unlink } from 'node:fs/promises'; | ||
import { promisify } from 'node:util'; | ||
import metadata from '../metadata.js'; | ||
import { getMetadataService } from '../metadata.js'; | ||
import { YError } from 'yerror'; | ||
@@ -18,3 +18,3 @@ import { mkdir } from 'node:fs/promises'; | ||
test('should extract right unicodes from files', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)('/var/plop/hello.svg'); | ||
@@ -31,8 +31,4 @@ | ||
test('should append unicodes to files when the option is set', async () => { | ||
const metadataService = metadata({ | ||
const metadataService = getMetadataService({ | ||
prependUnicode: true, | ||
log: () => {}, | ||
err: () => { | ||
throw new YError('E_NOT_SUPPOSED_TO_BE_HERE'); | ||
}, | ||
}); | ||
@@ -68,9 +64,5 @@ | ||
test('should log file rename errors', async () => { | ||
const metadataService = metadata({ | ||
const metadataService = getMetadataService({ | ||
prependUnicode: true, | ||
startUnicode: 0xea02, | ||
err: () => {}, | ||
log: () => { | ||
throw new YError('E_NOT_SUPPOSED_TO_BE_HERE'); | ||
}, | ||
}); | ||
@@ -99,3 +91,3 @@ | ||
test('should work for simple codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)( | ||
@@ -114,3 +106,3 @@ '/var/plop/u0001-hello.svg', | ||
test('should work for several codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)( | ||
@@ -129,3 +121,3 @@ '/var/plop/u0001,u0002-hello.svg', | ||
test('should work for higher codepoint codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)( | ||
@@ -144,3 +136,3 @@ '/var/plop/u1F63A-hello.svg', | ||
test('should work for ligature codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)( | ||
@@ -159,3 +151,3 @@ '/var/plop/u0001u0002-hello.svg', | ||
test('should work for nested codes', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
const infos = await promisify(metadataService)( | ||
@@ -177,3 +169,3 @@ '/var/plop/u0001u0002,u0001-hello.svg', | ||
test('should not set the same codepoint twice', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
@@ -202,3 +194,3 @@ const infos = await promisify(metadataService)( | ||
test('should not set the same codepoint twice with different cases', async () => { | ||
const metadataService = metadata(); | ||
const metadataService = getMetadataService(); | ||
@@ -205,0 +197,0 @@ const infos = await promisify(metadataService)( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
0
464488
3808