@reliverse/relico 1.3.6 → 1.3.8

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.
Files changed (2) hide show
  1. package/bin/mod.js +41 -6
  2. package/package.json +1 -1
package/bin/mod.js CHANGED
@@ -144,18 +144,46 @@ const mixWithWhite = (rgb, factor) => {
144
144
  };
145
145
  const fromNamed = (name) => {
146
146
  const hex = NAMED_COLORS[name];
147
+ if (!hex || typeof hex !== "string") {
148
+ return { r: 0, g: 0, b: 0 };
149
+ }
147
150
  const clean = hex.startsWith("#") ? hex.slice(1) : hex;
148
- const r = Number.parseInt(clean.slice(HEX_RED_START, HEX_BYTE_LENGTH), HEX_RADIX);
149
- const g = Number.parseInt(clean.slice(HEX_GREEN_START, HEX_BLUE_START), HEX_RADIX);
150
- const b = Number.parseInt(clean.slice(HEX_BLUE_START, HEX_BLUE_END), HEX_RADIX);
151
+ if (clean.length !== HEX_BLUE_END && clean.length !== 3) {
152
+ return { r: 0, g: 0, b: 0 };
153
+ }
154
+ let rHex, gHex, bHex;
155
+ if (clean.length === 3) {
156
+ rHex = clean[0].repeat(2);
157
+ gHex = clean[1].repeat(2);
158
+ bHex = clean[2].repeat(2);
159
+ } else {
160
+ rHex = clean.slice(HEX_RED_START, HEX_BYTE_LENGTH);
161
+ gHex = clean.slice(HEX_GREEN_START, HEX_BLUE_START);
162
+ bHex = clean.slice(HEX_BLUE_START, HEX_BLUE_END);
163
+ }
164
+ const r = Number.parseInt(rHex, HEX_RADIX);
165
+ const g = Number.parseInt(gHex, HEX_RADIX);
166
+ const b = Number.parseInt(bHex, HEX_RADIX);
167
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
168
+ return { r: 0, g: 0, b: 0 };
169
+ }
151
170
  return { r, g, b };
152
171
  };
153
172
  const toBaseName = (compound) => {
173
+ if (!compound || typeof compound !== "string") {
174
+ return "black";
175
+ }
154
176
  const base = compound.replace(BRIGHT_SUFFIX_REGEX, "");
177
+ if (!base) {
178
+ return "black";
179
+ }
155
180
  const key = base.charAt(0).toLowerCase() + base.slice(1);
156
181
  return key;
157
182
  };
158
183
  const parseColorName = (name) => {
184
+ if (!name || typeof name !== "string") {
185
+ return { rgb: { r: 0, g: 0, b: 0 }, wantBright: false };
186
+ }
159
187
  if (name.endsWith("Bright")) {
160
188
  const base = toBaseName(name);
161
189
  const rgb = fromNamed(base);
@@ -259,16 +287,20 @@ const STYLE_KEYS = /* @__PURE__ */ new Set([
259
287
  "strikethrough"
260
288
  ]);
261
289
  const isColorKey = (key) => {
290
+ if (!key || typeof key !== "string") {
291
+ return false;
292
+ }
262
293
  if (key in NAMED_COLORS) {
263
294
  return true;
264
295
  }
265
- if (key.endsWith("Bright") && isColorKey(key.slice(0, -BRIGHT_SUFFIX_LENGTH))) {
266
- return true;
296
+ if (key.endsWith("Bright") && key.length > BRIGHT_SUFFIX_LENGTH) {
297
+ const baseName = key.slice(0, -BRIGHT_SUFFIX_LENGTH);
298
+ return baseName in NAMED_COLORS;
267
299
  }
268
300
  return false;
269
301
  };
270
302
  const isBgKey = (key) => {
271
- if (!key.startsWith("bg") || key.length <= BG_PREFIX_LENGTH) {
303
+ if (!key || typeof key !== "string" || !key.startsWith("bg") || key.length <= BG_PREFIX_LENGTH) {
272
304
  return false;
273
305
  }
274
306
  const colorPart = key.charAt(BG_PREFIX_LENGTH).toLowerCase() + key.slice(BG_COLOR_START);
@@ -298,6 +330,9 @@ const callableProxy = (ops) => {
298
330
  }
299
331
  if (isBgKey(key)) {
300
332
  const raw = key.slice(BG_PREFIX_LENGTH);
333
+ if (!raw) {
334
+ return callableProxy(ops);
335
+ }
301
336
  const colorName = raw.charAt(0).toLowerCase() + raw.slice(1);
302
337
  const { rgb, wantBright } = parseColorName(colorName);
303
338
  return callableProxy([...ops, ...mkBgOpsFromRgb(rgb, wantBright)]);
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "license": "MIT",
6
6
  "name": "@reliverse/relico",
7
7
  "type": "module",
8
- "version": "1.3.6",
8
+ "version": "1.3.8",
9
9
  "author": "reliverse",
10
10
  "bugs": {
11
11
  "email": "blefnk@gmail.com",