@open-xchange/vite-plugin-icon-sprite 0.0.2 → 0.0.4

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 CHANGED
@@ -1,9 +1,17 @@
1
1
  # Changelog
2
2
 
3
- ## [0.0.2] - 2024-08-08
3
+ ## `0.0.4` 2024-Sep-13
4
+
5
+ - chore: bump jimp
6
+
7
+ ## `0.0.3` – 2024-Sep-08
8
+
9
+ - chore: bump jimp
10
+
11
+ ## `0.0.2` – 2024-Aug-08
4
12
 
5
13
  - chore: bump @open-xchange/vite-helper
6
14
 
7
- ## [0.0.1] - 2024-08-08
15
+ ## `0.0.1` 2024-Aug-08
8
16
 
9
17
  - initial release
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`.
@@ -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.read(buffer);
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 pngColorType = { source: 6, monochrome: 4, alpha: 0 }[spriteColorType];
112
- const spriteBuffer = await sprite.colorType(pngColorType).getBufferAsync(Jimp.MIME_PNG);
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
- "name": "@open-xchange/vite-plugin-icon-sprite",
3
- "version": "0.0.2",
4
- "description": "Vite plugin that builds icon sprites from SVG or PNG icon files",
5
- "repository": {
6
- "url": "https://gitlab.open-xchange.com/fspd/npm-packages/vite-plugin-icon-sprite"
7
- },
8
- "license": "MIT",
9
- "engines": {
10
- "node": "18.18.0 || ^20.9.0 || >=21.1.0"
11
- },
12
- "packageManager": "yarn@4.4.0",
13
- "type": "module",
14
- "exports": "./dist/index.js",
15
- "scripts": {
16
- "prepare": "husky",
17
- "prepack": "yarn build && yarn lint",
18
- "build": "npx --yes rimraf dist && tsc && npx --yes cpy-cli --flat src/*.json dist/",
19
- "lint": "eslint ."
20
- },
21
- "lint-staged": {
22
- "*.{js,ts,json}": "yarn lint"
23
- },
24
- "dependencies": {
25
- "@open-xchange/vite-helper": "0.1.1",
26
- "jimp": "0.22.12",
27
- "svg-sprite": "2.0.4"
28
- },
29
- "devDependencies": {
30
- "@open-xchange/linter-presets": "0.4.3",
31
- "@types/node": "22.1.0",
32
- "@types/svg-sprite": "0.0.39",
33
- "@types/vinyl": "2.0.12",
34
- "eslint": "9.8.0",
35
- "husky": "9.1.4",
36
- "typescript": "5.5.4",
37
- "vite": "5.4.0"
38
- },
39
- "peerDependencies": {
40
- "vite": "^5.3"
41
- },
42
- "resolutions": {
43
- "semver": "^7.6.2"
44
- }
45
- }
2
+ "name": "@open-xchange/vite-plugin-icon-sprite",
3
+ "version": "0.0.4",
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.6.0",
25
+ "svg-sprite": "2.0.4"
26
+ },
27
+ "devDependencies": {
28
+ "@open-xchange/linter-presets": "0.8.3",
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.10.0",
35
+ "rimraf": "6.0.1",
36
+ "typescript": "5.6.2",
37
+ "vite": "5.4.4"
38
+ },
39
+ "peerDependencies": {
40
+ "vite": "^5.3"
41
+ },
42
+ "resolutions": {
43
+ "semver": "^7.6.2"
44
+ }
45
+ }
@@ -1,3 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules/typescript/lib"
3
- }
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.