Compare commits

..

No commits in common. "2b465341957804b456885fa31d036bd5ac4eb21c" and "f1017d5ba64898771a65780eb5fa81b5161e07c5" have entirely different histories.

5 changed files with 560 additions and 683 deletions

1181
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,29 @@
{ {
"name": "webpack-svg-sprite-generator", "name": "webpack-svg-sprite-generator",
"version": "5.0.7", "version": "5.0.6",
"description": "", "description": "",
"main": "plugin.js", "main": "plugin.js",
"types": "ts/index.d.ts", "types": "ts/index.d.ts",
"scripts": { "scripts": {
"build": "webpack" "build": "webpack",
"build-demo": "webpack --config demo/webpack.config.js",
"serve-demo": "webpack-dev-server --config demo/webpack.config.js"
}, },
"keywords": [], "keywords": [],
"author": "WolverinDEV", "author": "WolverinDEV",
"license": "GPL-3.0", "license": "GPL-3.0",
"bugs": { "bugs": {
"url": "https://git.kle.li/TeaSpeak/webpack-svg-sprites/issues" "url": "https://github.com/WolverinDEV/webpack-svg-sprites/issues"
}, },
"repository": { "repository": {
"url": "https://git.kle.li/TeaSpeak/webpack-svg-sprites.git", "url": "https://github.com/WolverinDEV/webpack-svg-sprites",
"type": "git" "type": "git"
}, },
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/tapable": "^2.2.7", "@types/tapable": "^2.2.7",
"@types/webpack": "^5.28.5", "@types/webpack": "^5.28.5",
"change-case": "^4.1.2", "change-case": "^5.1.2",
"clean-webpack-plugin": "^4.0.0", "clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^11.0.0", "copy-webpack-plugin": "^11.0.0",
"html-webpack-plugin": "^5.5.3", "html-webpack-plugin": "^5.5.3",

View file

@ -99,6 +99,15 @@ export async function generateSpriteCss(options: SpriteCssOptions, classPrefix:
result += `width:${defaultWidth * scaleX}${options.unit}`; result += `width:${defaultWidth * scaleX}${options.unit}`;
result += `}`; result += `}`;
/*
const unit = (value: number) => {
let valStr = value.toString();
if(valStr.length < 5)
valStr = " ".substr(valStr.length - 5) + valStr;
return value === 0 ? `${valStr} ` : `${valStr}${options.unit}`;
};
*/
const unit = (value: number) => { const unit = (value: number) => {
let valStr = value.toString(); let valStr = value.toString();
return value === 0 ? `${valStr}` : `${valStr}${options.unit}`; return value === 0 ? `${valStr}` : `${valStr}${options.unit}`;
@ -159,7 +168,7 @@ export async function generateSpriteDts(options: SpriteDtsOptions, moduleName: s
for(const file of sprite.entries) for(const file of sprite.entries)
union += ` | "${cssClassPrefix}${file.name}"`; union += ` | "${cssClassPrefix}${file.name}"`;
lines.push(`export type ${options.classUnionName} = ${union.substring(3)};`); lines.push(`export type ${options.classUnionName} = ${union.substr(3)};`);
} }
lines.push(``); lines.push(``);
@ -215,6 +224,7 @@ export async function generateSpriteJs(options: SpriteDtsOptions, sprite: Genera
lines.push(`EnumClassList[EnumClassList["${key}"] = "${members[key]}"] = "${key}";`); lines.push(`EnumClassList[EnumClassList["${key}"] = "${members[key]}"] = "${key}";`);
} }
{
lines.push(``); lines.push(``);
lines.push(`let SpriteEntries = [`); lines.push(`let SpriteEntries = [`);
for(const entry of sprite.entries) { for(const entry of sprite.entries) {
@ -231,6 +241,7 @@ export async function generateSpriteJs(options: SpriteDtsOptions, sprite: Genera
lines.push(` }),`); lines.push(` }),`);
} }
lines.push(`];`); lines.push(`];`);
}
lines.push(``); lines.push(``);
lines.push(`let SpriteUrl = decodeURIComponent("${encodeURIComponent(publicUrl)}");`); lines.push(`let SpriteUrl = decodeURIComponent("${encodeURIComponent(publicUrl)}");`);
@ -299,8 +310,13 @@ export async function generateSprite(files: string[]) : Promise<GeneratedSprite>
result.entries.push(svg); result.entries.push(svg);
} }
/* take the element height/with divided by two since that's a good number to work with */
//const svgSpaceWidth = result.elementWidth / 2;
//const svgSpaceHeight = result.elementHeight / 2;
//result.entries.forEach(e => { e.bounds.w += svgSpaceWidth; e.bounds.h += svgSpaceHeight });
const spriteDim = potpack(result.entries.map(e => e.bounds)); const spriteDim = potpack(result.entries.map(e => e.bounds));
//result.entries.forEach(e => { e.bounds.w -= svgSpaceWidth; e.bounds.h -= svgSpaceHeight });
result.width = spriteDim.w; result.width = spriteDim.w;
result.height = spriteDim.h; result.height = spriteDim.h;

View file

@ -205,7 +205,7 @@ export class SpriteGenerator {
return; return;
} }
const configName = resolveData.request.substring(this.options.modulePrefix.length); const configName = resolveData.request.substr(this.options.modulePrefix.length);
if(!this.options.configurations[configName]) { if(!this.options.configurations[configName]) {
return; return;
} }

View file

@ -3,7 +3,7 @@ import {Configuration} from "webpack";
import {CleanWebpackPlugin} from "clean-webpack-plugin"; import {CleanWebpackPlugin} from "clean-webpack-plugin";
import CopyWebpackPlugin from "copy-webpack-plugin"; import CopyWebpackPlugin from "copy-webpack-plugin";
export default { export = {
entry: "./plugin/index.ts", entry: "./plugin/index.ts",
module: { module: {
rules: [ rules: [