@sv443-network/userutils 7.2.1 → 7.2.2

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,5 +1,11 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 7.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a171b0d: Fix color functions not being exported 🥴
8
+
3
9
  ## 7.2.1
4
10
 
5
11
  ### Patch Changes
@@ -8,7 +8,7 @@
8
8
  // ==UserLibrary==
9
9
  // @name UserUtils
10
10
  // @description Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more
11
- // @version 7.2.1
11
+ // @version 7.2.2
12
12
  // @license MIT
13
13
  // @copyright Sv443 (https://github.com/Sv443)
14
14
 
@@ -128,6 +128,55 @@ var UserUtils = (function (exports) {
128
128
  return retArray;
129
129
  }
130
130
 
131
+ // lib/colors.ts
132
+ function hexToRgb(hex) {
133
+ hex = hex.trim();
134
+ const bigint = parseInt(hex.startsWith("#") ? hex.slice(1) : hex, 16);
135
+ const r = bigint >> 16 & 255;
136
+ const g = bigint >> 8 & 255;
137
+ const b = bigint & 255;
138
+ return [clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)];
139
+ }
140
+ function rgbToHex(red, green, blue, withHash = true, upperCase = false) {
141
+ const toHexVal = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0")[upperCase ? "toUpperCase" : "toLowerCase"]();
142
+ return `${withHash ? "#" : ""}${toHexVal(red)}${toHexVal(green)}${toHexVal(blue)}`;
143
+ }
144
+ function lightenColor(color, percent) {
145
+ return darkenColor(color, percent * -1);
146
+ }
147
+ function darkenColor(color, percent) {
148
+ var _a;
149
+ color = color.trim();
150
+ const darkenRgb = (r2, g2, b2, percent2) => {
151
+ r2 = Math.max(0, Math.min(255, r2 - r2 * percent2 / 100));
152
+ g2 = Math.max(0, Math.min(255, g2 - g2 * percent2 / 100));
153
+ b2 = Math.max(0, Math.min(255, b2 - b2 * percent2 / 100));
154
+ return [r2, g2, b2];
155
+ };
156
+ let r, g, b, a;
157
+ const isHexCol = color.match(/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);
158
+ if (isHexCol)
159
+ [r, g, b] = hexToRgb(color);
160
+ else if (color.startsWith("rgb")) {
161
+ const rgbValues = (_a = color.match(/\d+(\.\d+)?/g)) == null ? void 0 : _a.map(Number);
162
+ if (rgbValues)
163
+ [r, g, b, a] = rgbValues;
164
+ else
165
+ throw new Error("Invalid RGB/RGBA color format");
166
+ } else
167
+ throw new Error("Unsupported color format");
168
+ [r, g, b] = darkenRgb(r, g, b, percent);
169
+ const upperCase = color.match(/[A-F]/) !== null;
170
+ if (isHexCol)
171
+ return rgbToHex(r, g, b, color.startsWith("#"), upperCase);
172
+ else if (color.startsWith("rgba"))
173
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
174
+ else if (color.startsWith("rgb"))
175
+ return `rgb(${r}, ${g}, ${b})`;
176
+ else
177
+ throw new Error("Unsupported color format");
178
+ }
179
+
131
180
  // lib/dom.ts
132
181
  function getUnsafeWindow() {
133
182
  try {
@@ -1376,6 +1425,7 @@ Has: ${checksum}`);
1376
1425
  exports.clamp = clamp;
1377
1426
  exports.compress = compress;
1378
1427
  exports.computeHash = computeHash;
1428
+ exports.darkenColor = darkenColor;
1379
1429
  exports.debounce = debounce;
1380
1430
  exports.decompress = decompress;
1381
1431
  exports.defaultDialogCss = defaultDialogCss;
@@ -1383,10 +1433,12 @@ Has: ${checksum}`);
1383
1433
  exports.fetchAdvanced = fetchAdvanced;
1384
1434
  exports.getSiblingsFrame = getSiblingsFrame;
1385
1435
  exports.getUnsafeWindow = getUnsafeWindow;
1436
+ exports.hexToRgb = hexToRgb;
1386
1437
  exports.insertValues = insertValues;
1387
1438
  exports.interceptEvent = interceptEvent;
1388
1439
  exports.interceptWindowEvent = interceptWindowEvent;
1389
1440
  exports.isScrollable = isScrollable;
1441
+ exports.lightenColor = lightenColor;
1390
1442
  exports.mapRange = mapRange;
1391
1443
  exports.observeElementProp = observeElementProp;
1392
1444
  exports.openDialogs = openDialogs;
@@ -1398,6 +1450,7 @@ Has: ${checksum}`);
1398
1450
  exports.randomItem = randomItem;
1399
1451
  exports.randomItemIndex = randomItemIndex;
1400
1452
  exports.randomizeArray = randomizeArray;
1453
+ exports.rgbToHex = rgbToHex;
1401
1454
  exports.setInnerHtmlUnsafe = setInnerHtmlUnsafe;
1402
1455
  exports.takeRandomItem = takeRandomItem;
1403
1456
  exports.tr = tr;
package/dist/index.js CHANGED
@@ -108,6 +108,55 @@ function randomizeArray(array) {
108
108
  return retArray;
109
109
  }
110
110
 
111
+ // lib/colors.ts
112
+ function hexToRgb(hex) {
113
+ hex = hex.trim();
114
+ const bigint = parseInt(hex.startsWith("#") ? hex.slice(1) : hex, 16);
115
+ const r = bigint >> 16 & 255;
116
+ const g = bigint >> 8 & 255;
117
+ const b = bigint & 255;
118
+ return [clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)];
119
+ }
120
+ function rgbToHex(red, green, blue, withHash = true, upperCase = false) {
121
+ const toHexVal = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0")[upperCase ? "toUpperCase" : "toLowerCase"]();
122
+ return `${withHash ? "#" : ""}${toHexVal(red)}${toHexVal(green)}${toHexVal(blue)}`;
123
+ }
124
+ function lightenColor(color, percent) {
125
+ return darkenColor(color, percent * -1);
126
+ }
127
+ function darkenColor(color, percent) {
128
+ var _a;
129
+ color = color.trim();
130
+ const darkenRgb = (r2, g2, b2, percent2) => {
131
+ r2 = Math.max(0, Math.min(255, r2 - r2 * percent2 / 100));
132
+ g2 = Math.max(0, Math.min(255, g2 - g2 * percent2 / 100));
133
+ b2 = Math.max(0, Math.min(255, b2 - b2 * percent2 / 100));
134
+ return [r2, g2, b2];
135
+ };
136
+ let r, g, b, a;
137
+ const isHexCol = color.match(/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);
138
+ if (isHexCol)
139
+ [r, g, b] = hexToRgb(color);
140
+ else if (color.startsWith("rgb")) {
141
+ const rgbValues = (_a = color.match(/\d+(\.\d+)?/g)) == null ? void 0 : _a.map(Number);
142
+ if (rgbValues)
143
+ [r, g, b, a] = rgbValues;
144
+ else
145
+ throw new Error("Invalid RGB/RGBA color format");
146
+ } else
147
+ throw new Error("Unsupported color format");
148
+ [r, g, b] = darkenRgb(r, g, b, percent);
149
+ const upperCase = color.match(/[A-F]/) !== null;
150
+ if (isHexCol)
151
+ return rgbToHex(r, g, b, color.startsWith("#"), upperCase);
152
+ else if (color.startsWith("rgba"))
153
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
154
+ else if (color.startsWith("rgb"))
155
+ return `rgb(${r}, ${g}, ${b})`;
156
+ else
157
+ throw new Error("Unsupported color format");
158
+ }
159
+
111
160
  // lib/dom.ts
112
161
  function getUnsafeWindow() {
113
162
  try {
@@ -1325,4 +1374,4 @@ tr.getLanguage = () => {
1325
1374
  return curLang;
1326
1375
  };
1327
1376
 
1328
- export { DataStore, DataStoreSerializer, Dialog, NanoEmitter, SelectorObserver, addGlobalStyle, addParent, autoPlural, clamp, compress, computeHash, currentDialogId, debounce, decompress, defaultDialogCss, defaultStrings, fetchAdvanced, getSiblingsFrame, getUnsafeWindow, insertValues, interceptEvent, interceptWindowEvent, isScrollable, mapRange, observeElementProp, openDialogs, openInNewTab, pauseFor, preloadImages, randRange, randomId, randomItem, randomItemIndex, randomizeArray, setInnerHtmlUnsafe, takeRandomItem, tr };
1377
+ export { DataStore, DataStoreSerializer, Dialog, NanoEmitter, SelectorObserver, addGlobalStyle, addParent, autoPlural, clamp, compress, computeHash, currentDialogId, darkenColor, debounce, decompress, defaultDialogCss, defaultStrings, fetchAdvanced, getSiblingsFrame, getUnsafeWindow, hexToRgb, insertValues, interceptEvent, interceptWindowEvent, isScrollable, lightenColor, mapRange, observeElementProp, openDialogs, openInNewTab, pauseFor, preloadImages, randRange, randomId, randomItem, randomItemIndex, randomizeArray, rgbToHex, setInnerHtmlUnsafe, takeRandomItem, tr };
@@ -1,4 +1,5 @@
1
1
  export * from "./array.js";
2
+ export * from "./colors.js";
2
3
  export * from "./crypto.js";
3
4
  export * from "./DataStore.js";
4
5
  export * from "./DataStoreSerializer.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
3
  "libName": "UserUtils",
4
- "version": "7.2.1",
4
+ "version": "7.2.2",
5
5
  "description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",