wenay-common 1.0.102 → 1.0.103

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.
@@ -18,6 +18,10 @@ export type ColorAny = ColorNumber | ColorString | Readonly<ColorRGBA>;
18
18
  export type Color = ColorString;
19
19
  export declare function rgb(red: number, green: number, blue: number): ColorString;
20
20
  export declare function colorGenerator(min?: number, max?: number): Generator<[number, number, number]>;
21
+ export declare function colorGenerator2({ min, max }: {
22
+ min?: number;
23
+ max?: number;
24
+ }): Generator<[number, number, number]>;
21
25
  export declare function colorGeneratorByCount(value?: number, count?: number, index?: number): ColorString;
22
26
  export declare function colorStringToRGBA(str: ColorString): [number, number, number, number];
23
27
  export declare function colorStringToRGBA(str: string): [number, number, number, number] | undefined;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSimilarColors = exports.toColorString = exports.colorStringToRGBA = exports.colorGeneratorByCount = exports.colorGenerator = exports.rgb = void 0;
3
+ exports.isSimilarColors = exports.toColorString = exports.colorStringToRGBA = exports.colorGeneratorByCount = exports.colorGenerator2 = exports.colorGenerator = exports.rgb = void 0;
4
4
  function rgb(red, green, blue) { return `rgb(${red},${green},${blue})`; }
5
5
  exports.rgb = rgb;
6
6
  function* colorGenerator(min = 0, max = 254) {
7
- for (let step = (max - min) / 2; step >= 1; step /= 2) {
7
+ for (let step = Math.floor((max - min) / 2); step >= 1; step /= 2) {
8
8
  let v = (max - min) / step;
9
9
  for (let rStep = 0, r = 0; rStep <= v; rStep++, r += step)
10
10
  for (let gStep = 0, g = 0; gStep <= v; gStep++, g += step)
@@ -17,6 +17,48 @@ function* colorGenerator(min = 0, max = 254) {
17
17
  yield [-1, -1, -1];
18
18
  }
19
19
  exports.colorGenerator = colorGenerator;
20
+ function* colorGenerator2({ min = 0, max = 0 }) {
21
+ function* _range(start = 0, end = 255) {
22
+ const range = (end - start) * 5;
23
+ for (let p = range; p > 1; p >>= 2)
24
+ for (let i = 1, step = p >> 2; step * i < range; i++)
25
+ yield step * i;
26
+ }
27
+ const d = max - min;
28
+ let buf = [min, min, min];
29
+ const rangeGen = _range(min, max);
30
+ for (let num of rangeGen) {
31
+ const p = Math.round(num / d);
32
+ const r = num % d;
33
+ if (p == 0) {
34
+ buf[0] = max;
35
+ buf[1] = min + r;
36
+ }
37
+ if (p == 1) {
38
+ buf[0] = max - r;
39
+ buf[1] = max;
40
+ }
41
+ if (p == 2) {
42
+ buf[1] = max;
43
+ buf[2] = min + r;
44
+ }
45
+ if (p == 3) {
46
+ buf[1] = max - r;
47
+ buf[2] = max;
48
+ }
49
+ if (p == 4) {
50
+ buf[2] = max;
51
+ buf[0] = min + r;
52
+ }
53
+ if (p == 5) {
54
+ buf[2] = max - r;
55
+ buf[0] = max;
56
+ }
57
+ yield buf;
58
+ }
59
+ yield [-1, -1, -1];
60
+ }
61
+ exports.colorGenerator2 = colorGenerator2;
20
62
  function colorGeneratorByCount(value = 180, count = 100, index = 1) {
21
63
  const step = Math.floor(value * 6 * index / count);
22
64
  const p = Math.floor(step / value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wenay-common",
3
- "version": "1.0.102",
3
+ "version": "1.0.103",
4
4
  "description": "Common library",
5
5
  "strict": true,
6
6
  "main": "lib/index.js",