@zag-js/color-utils 0.80.0 → 0.81.1

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var numericRange = require('@zag-js/numeric-range');
3
+ var utils = require('@zag-js/utils');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -201,18 +201,18 @@ var Color = class {
201
201
  getChannelValuePercent(channel, valueToCheck) {
202
202
  const value = valueToCheck ?? this.getChannelValue(channel);
203
203
  const { minValue, maxValue } = this.getChannelRange(channel);
204
- return numericRange.getValuePercent(value, minValue, maxValue);
204
+ return utils.getValuePercent(value, minValue, maxValue);
205
205
  }
206
206
  getChannelPercentValue(channel, percentToCheck) {
207
207
  const { minValue, maxValue, step } = this.getChannelRange(channel);
208
- const percentValue = numericRange.getPercentValue(percentToCheck, minValue, maxValue, step);
209
- return numericRange.snapValueToStep(percentValue, minValue, maxValue, step);
208
+ const percentValue = utils.getPercentValue(percentToCheck, minValue, maxValue, step);
209
+ return utils.snapValueToStep(percentValue, minValue, maxValue, step);
210
210
  }
211
211
  withChannelValue(channel, value) {
212
212
  const { minValue, maxValue } = this.getChannelRange(channel);
213
213
  if (channel in this) {
214
214
  let clone = this.clone();
215
- clone[channel] = numericRange.clampValue(value, minValue, maxValue);
215
+ clone[channel] = utils.clampValue(value, minValue, maxValue);
216
216
  return clone;
217
217
  }
218
218
  throw new Error("Unsupported color channel: " + channel);
@@ -226,8 +226,8 @@ var Color = class {
226
226
  }
227
227
  incrementChannel(channel, stepSize) {
228
228
  const { minValue, maxValue, step } = this.getChannelRange(channel);
229
- const value = numericRange.snapValueToStep(
230
- numericRange.clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue),
229
+ const value = utils.snapValueToStep(
230
+ utils.clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue),
231
231
  minValue,
232
232
  maxValue,
233
233
  step
@@ -261,7 +261,7 @@ var _RGBColor = class _RGBColor extends Color {
261
261
  }
262
262
  const match = value.match(/^rgba?\((.*)\)$/);
263
263
  if (match?.[1]) {
264
- colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => numericRange.clampValue(num, 0, i < 3 ? 255 : 1));
264
+ colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => utils.clampValue(num, 0, i < 3 ? 255 : 1));
265
265
  }
266
266
  return colors.length < 3 ? void 0 : new _RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);
267
267
  }
@@ -328,10 +328,10 @@ var _RGBColor = class _RGBColor extends Color {
328
328
  hue /= 6;
329
329
  }
330
330
  return new HSBColor(
331
- numericRange.toFixedNumber(hue * 360, 2),
332
- numericRange.toFixedNumber(saturation * 100, 2),
333
- numericRange.toFixedNumber(brightness * 100, 2),
334
- numericRange.toFixedNumber(this.alpha, 2)
331
+ utils.toFixedNumber(hue * 360, 2),
332
+ utils.toFixedNumber(saturation * 100, 2),
333
+ utils.toFixedNumber(brightness * 100, 2),
334
+ utils.toFixedNumber(this.alpha, 2)
335
335
  );
336
336
  }
337
337
  /**
@@ -367,10 +367,10 @@ var _RGBColor = class _RGBColor extends Color {
367
367
  hue /= 6;
368
368
  }
369
369
  return new HSLColor(
370
- numericRange.toFixedNumber(hue * 360, 2),
371
- numericRange.toFixedNumber(saturation * 100, 2),
372
- numericRange.toFixedNumber(lightness * 100, 2),
373
- numericRange.toFixedNumber(this.alpha, 2)
370
+ utils.toFixedNumber(hue * 360, 2),
371
+ utils.toFixedNumber(saturation * 100, 2),
372
+ utils.toFixedNumber(lightness * 100, 2),
373
+ utils.toFixedNumber(this.alpha, 2)
374
374
  );
375
375
  }
376
376
  clone() {
@@ -432,7 +432,7 @@ var _HSLColor = class _HSLColor extends Color {
432
432
  let m;
433
433
  if (m = value.match(HSL_REGEX)) {
434
434
  const [h, s, l, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
435
- return new _HSLColor(numericRange.mod(h, 360), numericRange.clampValue(s, 0, 100), numericRange.clampValue(l, 0, 100), numericRange.clampValue(a ?? 1, 0, 1));
435
+ return new _HSLColor(utils.mod(h, 360), utils.clampValue(s, 0, 100), utils.clampValue(l, 0, 100), utils.clampValue(a ?? 1, 0, 1));
436
436
  }
437
437
  }
438
438
  toString(format) {
@@ -442,10 +442,10 @@ var _HSLColor = class _HSLColor extends Color {
442
442
  case "hexa":
443
443
  return this.toRGB().toString("hexa");
444
444
  case "hsl":
445
- return `hsl(${this.hue}, ${numericRange.toFixedNumber(this.saturation, 2)}%, ${numericRange.toFixedNumber(this.lightness, 2)}%)`;
445
+ return `hsl(${this.hue}, ${utils.toFixedNumber(this.saturation, 2)}%, ${utils.toFixedNumber(this.lightness, 2)}%)`;
446
446
  case "css":
447
447
  case "hsla":
448
- return `hsla(${this.hue}, ${numericRange.toFixedNumber(this.saturation, 2)}%, ${numericRange.toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;
448
+ return `hsla(${this.hue}, ${utils.toFixedNumber(this.saturation, 2)}%, ${utils.toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;
449
449
  case "hsb":
450
450
  return this.toHSB().toString("hsb");
451
451
  case "rgb":
@@ -477,10 +477,10 @@ var _HSLColor = class _HSLColor extends Color {
477
477
  let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
478
478
  saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
479
479
  return new HSBColor(
480
- numericRange.toFixedNumber(this.hue, 2),
481
- numericRange.toFixedNumber(saturation * 100, 2),
482
- numericRange.toFixedNumber(brightness * 100, 2),
483
- numericRange.toFixedNumber(this.alpha, 2)
480
+ utils.toFixedNumber(this.hue, 2),
481
+ utils.toFixedNumber(saturation * 100, 2),
482
+ utils.toFixedNumber(brightness * 100, 2),
483
+ utils.toFixedNumber(this.alpha, 2)
484
484
  );
485
485
  }
486
486
  /**
@@ -498,7 +498,7 @@ var _HSLColor = class _HSLColor extends Color {
498
498
  Math.round(fn(0) * 255),
499
499
  Math.round(fn(8) * 255),
500
500
  Math.round(fn(4) * 255),
501
- numericRange.toFixedNumber(this.alpha, 2)
501
+ utils.toFixedNumber(this.alpha, 2)
502
502
  );
503
503
  }
504
504
  clone() {
@@ -564,7 +564,7 @@ var _HSBColor = class _HSBColor extends Color {
564
564
  let m;
565
565
  if (m = value.match(HSB_REGEX)) {
566
566
  const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
567
- return new _HSBColor(numericRange.mod(h, 360), numericRange.clampValue(s, 0, 100), numericRange.clampValue(b, 0, 100), numericRange.clampValue(a ?? 1, 0, 1));
567
+ return new _HSBColor(utils.mod(h, 360), utils.clampValue(s, 0, 100), utils.clampValue(b, 0, 100), utils.clampValue(a ?? 1, 0, 1));
568
568
  }
569
569
  }
570
570
  toString(format) {
@@ -576,9 +576,9 @@ var _HSBColor = class _HSBColor extends Color {
576
576
  case "hexa":
577
577
  return this.toRGB().toString("hexa");
578
578
  case "hsb":
579
- return `hsb(${this.hue}, ${numericRange.toFixedNumber(this.saturation, 2)}%, ${numericRange.toFixedNumber(this.brightness, 2)}%)`;
579
+ return `hsb(${this.hue}, ${utils.toFixedNumber(this.saturation, 2)}%, ${utils.toFixedNumber(this.brightness, 2)}%)`;
580
580
  case "hsba":
581
- return `hsba(${this.hue}, ${numericRange.toFixedNumber(this.saturation, 2)}%, ${numericRange.toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
581
+ return `hsba(${this.hue}, ${utils.toFixedNumber(this.saturation, 2)}%, ${utils.toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
582
582
  case "hsl":
583
583
  return this.toHSL().toString("hsl");
584
584
  case "rgb":
@@ -610,10 +610,10 @@ var _HSBColor = class _HSBColor extends Color {
610
610
  let lightness = brightness * (1 - saturation / 2);
611
611
  saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
612
612
  return new HSLColor(
613
- numericRange.toFixedNumber(this.hue, 2),
614
- numericRange.toFixedNumber(saturation * 100, 2),
615
- numericRange.toFixedNumber(lightness * 100, 2),
616
- numericRange.toFixedNumber(this.alpha, 2)
613
+ utils.toFixedNumber(this.hue, 2),
614
+ utils.toFixedNumber(saturation * 100, 2),
615
+ utils.toFixedNumber(lightness * 100, 2),
616
+ utils.toFixedNumber(this.alpha, 2)
617
617
  );
618
618
  }
619
619
  /**
@@ -630,7 +630,7 @@ var _HSBColor = class _HSBColor extends Color {
630
630
  Math.round(fn(5) * 255),
631
631
  Math.round(fn(3) * 255),
632
632
  Math.round(fn(1) * 255),
633
- numericRange.toFixedNumber(this.alpha, 2)
633
+ utils.toFixedNumber(this.alpha, 2)
634
634
  );
635
635
  }
636
636
  clone() {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { getValuePercent, getPercentValue, snapValueToStep, clampValue, toFixedNumber, mod } from '@zag-js/numeric-range';
1
+ import { getValuePercent, getPercentValue, snapValueToStep, clampValue, toFixedNumber, mod } from '@zag-js/utils';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/color-utils",
3
- "version": "0.80.0",
3
+ "version": "0.81.1",
4
4
  "description": "Color utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "clean-package": "../../../clean-package.config.json",
26
26
  "dependencies": {
27
- "@zag-js/numeric-range": "0.80.0"
27
+ "@zag-js/utils": "0.81.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0"