@open-xchange/vite-plugin-icon-sprite 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -2
- package/README.md +4 -0
- package/dist/plugin-png.js +10 -6
- package/package.json +44 -44
- package/.vscode/settings.json +0 -3
- package/LICENSE +0 -21
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -322,3 +322,7 @@ Add the path to the schema file in a `yaml-language-server` directive to the map
|
|
|
322
322
|
Adjust the number of parent path fragments according to the location of the mapping file in the project.
|
|
323
323
|
|
|
324
324
|
In VS Code, the plugin [redhat.vscode-yaml](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) needs to be installed to support this directive.
|
|
325
|
+
|
|
326
|
+
### Logging
|
|
327
|
+
|
|
328
|
+
By default, warning messages and error messages will be logged to the shell. The environment variable `PLUGIN_REPLACE_ICON_SPRITE` can be used to change the log level of this plugin. Possible values are `info`, `warn`, `error`, and `silent`.
|
package/dist/plugin-png.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Jimp from "jimp";
|
|
1
|
+
import { Jimp, PNGColorType } from "jimp";
|
|
2
2
|
import { onceFn } from "@open-xchange/vite-helper/utils";
|
|
3
3
|
import { Cache } from "@open-xchange/vite-helper/cache";
|
|
4
4
|
import { SpritePluginHelper } from "./helper.js";
|
|
@@ -85,7 +85,7 @@ class PngSpritePluginHelper extends SpritePluginHelper {
|
|
|
85
85
|
// parse mapping file which collects icon paths, CSS selectors, and entry positions
|
|
86
86
|
const { cssSpriteWidth, cssSpriteHeight, entries } = await this.#parseMappingOnce();
|
|
87
87
|
// new image data is not clean out-of-the-box, explicitly fill with zeros
|
|
88
|
-
const sprite = new Jimp(cssSpriteWidth * factor, cssSpriteHeight * factor, 0);
|
|
88
|
+
const sprite = new Jimp({ width: cssSpriteWidth * factor, height: cssSpriteHeight * factor, color: 0 });
|
|
89
89
|
// process all entries in the mapping configuration
|
|
90
90
|
for (const { iconPath, x, y } of entries) {
|
|
91
91
|
// expected pixel size for the current scaling factor
|
|
@@ -93,12 +93,12 @@ class PngSpritePluginHelper extends SpritePluginHelper {
|
|
|
93
93
|
// load and parse the source image file
|
|
94
94
|
const path = imagesPath + "/" + srcPattern.replace("[path]", iconPath);
|
|
95
95
|
const buffer = await this.readBuffer(path);
|
|
96
|
-
const image = await Jimp.
|
|
96
|
+
const image = await Jimp.fromBuffer(buffer);
|
|
97
97
|
// validate the image size
|
|
98
98
|
const { width, height } = image.bitmap;
|
|
99
99
|
this.ensure((width === size) && (height === size), "wrong image width in %f (expected %s but got %s)", path, `${size}x${size}`, `${width}x${height}`);
|
|
100
100
|
// insert source image into the sprite
|
|
101
|
-
sprite.blit(image, (x + cssIconPadding) * factor, (y + cssIconPadding) * factor);
|
|
101
|
+
sprite.blit({ src: image, x: (x + cssIconPadding) * factor, y: (y + cssIconPadding) * factor });
|
|
102
102
|
}
|
|
103
103
|
// copy alpha of all pixels to RGB channels (alpha channel will be exported as greyscale without alpha)
|
|
104
104
|
if (spriteColorType === "alpha") {
|
|
@@ -108,8 +108,12 @@ class PngSpritePluginHelper extends SpritePluginHelper {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
// generate the binary PNG data (no preset constants for PNG color types in Jimp)
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const colorType = {
|
|
112
|
+
source: PNGColorType.COLOR_ALPHA,
|
|
113
|
+
monochrome: PNGColorType.GRAYSCALE_ALPHA,
|
|
114
|
+
alpha: PNGColorType.GRAYSCALE,
|
|
115
|
+
}[spriteColorType];
|
|
116
|
+
const spriteBuffer = await sprite.getBuffer("image/png", { colorType });
|
|
113
117
|
// convert to base64 encoded data URL
|
|
114
118
|
const spriteDataUrl = `data:image/png;base64,${spriteBuffer.toString("base64")}`;
|
|
115
119
|
const moduleSource = `export default ${JSON.stringify(spriteDataUrl)};`;
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
2
|
+
"name": "@open-xchange/vite-plugin-icon-sprite",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Vite plugin that builds icon sprites from SVG or PNG icon files",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://gitlab.open-xchange.com/fspd/commons/plugins/-/tree/main/packages/vite-plugin-icon-sprite"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": "18.18.0 || ^20.9.0 || >=21.1.0"
|
|
12
|
+
},
|
|
13
|
+
"packageManager": "yarn@4.4.1",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": "./dist/index.js",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepare": "yarn build",
|
|
18
|
+
"prepack": "yarn build && yarn lint",
|
|
19
|
+
"build": "rimraf dist && tsc && cpy --flat src/*.json dist/",
|
|
20
|
+
"lint": "eslint ."
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@open-xchange/vite-helper": "0.1.1",
|
|
24
|
+
"jimp": "1.3.0",
|
|
25
|
+
"svg-sprite": "2.0.4"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@open-xchange/linter-presets": "0.8.1",
|
|
29
|
+
"@types/node": "22.5.4",
|
|
30
|
+
"@types/pngjs": "6.0.5",
|
|
31
|
+
"@types/svg-sprite": "0.0.39",
|
|
32
|
+
"@types/vinyl": "2.0.12",
|
|
33
|
+
"cpy-cli": "5.0.0",
|
|
34
|
+
"eslint": "9.9.1",
|
|
35
|
+
"rimraf": "6.0.1",
|
|
36
|
+
"typescript": "5.5.4",
|
|
37
|
+
"vite": "5.4.3"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vite": "^5.3"
|
|
41
|
+
},
|
|
42
|
+
"resolutions": {
|
|
43
|
+
"semver": "^7.6.2"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/.vscode/settings.json
DELETED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 OX Software GmbH, Germany <info@open-xchange.com>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|