plotboilerplate 1.24.0 → 1.25.0

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 (141) hide show
  1. package/README.md +13 -1
  2. package/dist/index.esm.js +294 -129
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +12084 -11919
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +9 -5
  11. package/src/cjs/PlotBoilerplate.d.ts +37 -6
  12. package/src/cjs/PlotBoilerplate.js +222 -116
  13. package/src/cjs/PlotBoilerplate.js.map +1 -1
  14. package/src/cjs/Polygon.d.ts +26 -7
  15. package/src/cjs/Polygon.js +56 -10
  16. package/src/cjs/Polygon.js.map +1 -1
  17. package/src/cjs/Triangle.js +2 -2
  18. package/src/cjs/Triangle.js.map +1 -1
  19. package/src/cjs/Vertex.d.ts +15 -3
  20. package/src/cjs/Vertex.js +18 -1
  21. package/src/cjs/Vertex.js.map +1 -1
  22. package/src/cjs/interfaces/core.d.ts +28 -0
  23. package/src/cjs/interfaces/core.js +2 -0
  24. package/src/cjs/interfaces/core.js.map +1 -1
  25. package/src/cjs/utils/datastructures/Color.d.ts +147 -1
  26. package/src/cjs/utils/datastructures/Color.js +385 -41
  27. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  28. package/src/cjs/utils/datastructures/ColorGradient.d.ts +79 -0
  29. package/src/cjs/utils/datastructures/ColorGradient.js +171 -0
  30. package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -0
  31. package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +245 -0
  32. package/src/cjs/utils/dom/components/ColorGradientPicker.js +667 -0
  33. package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -0
  34. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
  35. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js +520 -0
  36. package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
  37. package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +117 -0
  38. package/src/cjs/utils/dom/components/ColorGradientSelector.js +325 -0
  39. package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -0
  40. package/src/cjs/utils/dom/components/Test.d.ts +7 -0
  41. package/src/cjs/utils/dom/components/Test.js +30 -0
  42. package/src/cjs/utils/dom/components/Test.js.map +1 -0
  43. package/src/cjs/utils/dom/guiSizeToggler.js +1 -1
  44. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
  45. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
  46. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +20 -13
  47. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  48. package/src/cjs/utils/helpers/CircleHelper.d.ts +10 -1
  49. package/src/cjs/utils/helpers/CircleHelper.js +13 -2
  50. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  51. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +2 -2
  52. package/src/cjs/utils/helpers/CircleSectorHelper.js +1 -0
  53. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  54. package/src/cjs/utils/helpers/TriangleHelper.d.ts +57 -0
  55. package/src/cjs/utils/helpers/TriangleHelper.js +83 -0
  56. package/src/cjs/utils/helpers/TriangleHelper.js.map +1 -0
  57. package/src/cjs/utils/helpers/VEllipseHelper.d.ts +6 -4
  58. package/src/cjs/utils/helpers/VEllipseHelper.js +4 -2
  59. package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -1
  60. package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
  61. package/src/cjs/utils/helpers/VEllipseSectorHelper.js +1 -0
  62. package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
  63. package/src/cjs/utils/parsers/LinearColorGradientParser.d.ts +78 -0
  64. package/src/cjs/utils/parsers/LinearColorGradientParser.js +224 -0
  65. package/src/cjs/utils/parsers/LinearColorGradientParser.js.map +1 -0
  66. package/src/createDemoDrawables.js +1 -0
  67. package/src/esm/PlotBoilerplate.d.ts +37 -6
  68. package/src/esm/PlotBoilerplate.js +222 -116
  69. package/src/esm/PlotBoilerplate.js.map +1 -1
  70. package/src/esm/Polygon.d.ts +26 -7
  71. package/src/esm/Polygon.js +53 -10
  72. package/src/esm/Polygon.js.map +1 -1
  73. package/src/esm/Triangle.js +2 -2
  74. package/src/esm/Triangle.js.map +1 -1
  75. package/src/esm/Vertex.d.ts +15 -3
  76. package/src/esm/Vertex.js +18 -1
  77. package/src/esm/Vertex.js.map +1 -1
  78. package/src/esm/interfaces/core.d.ts +28 -0
  79. package/src/esm/interfaces/core.js +2 -0
  80. package/src/esm/interfaces/core.js.map +1 -1
  81. package/src/esm/utils/datastructures/Color.d.ts +147 -1
  82. package/src/esm/utils/datastructures/Color.js +386 -42
  83. package/src/esm/utils/datastructures/Color.js.map +1 -1
  84. package/src/esm/utils/datastructures/ColorGradient.d.ts +79 -0
  85. package/src/esm/utils/datastructures/ColorGradient.js +166 -0
  86. package/src/esm/utils/datastructures/ColorGradient.js.map +1 -0
  87. package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +245 -0
  88. package/src/esm/utils/dom/components/ColorGradientPicker.js +732 -0
  89. package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -0
  90. package/src/esm/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
  91. package/src/esm/utils/dom/components/ColorGradientPickerJSX.js +582 -0
  92. package/src/esm/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
  93. package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +117 -0
  94. package/src/esm/utils/dom/components/ColorGradientSelector.js +332 -0
  95. package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -0
  96. package/src/esm/utils/dom/components/Test.d.ts +7 -0
  97. package/src/esm/utils/dom/components/Test.js +26 -0
  98. package/src/esm/utils/dom/components/Test.js.map +1 -0
  99. package/src/esm/utils/dom/guiSizeToggler.js +1 -1
  100. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
  101. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
  102. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +20 -13
  103. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  104. package/src/esm/utils/helpers/CircleHelper.d.ts +10 -1
  105. package/src/esm/utils/helpers/CircleHelper.js +13 -2
  106. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  107. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +2 -2
  108. package/src/esm/utils/helpers/CircleSectorHelper.js +1 -0
  109. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  110. package/src/esm/utils/helpers/TriangleHelper.d.ts +57 -0
  111. package/src/esm/utils/helpers/TriangleHelper.js +78 -0
  112. package/src/esm/utils/helpers/TriangleHelper.js.map +1 -0
  113. package/src/esm/utils/helpers/VEllipseHelper.d.ts +6 -4
  114. package/src/esm/utils/helpers/VEllipseHelper.js +4 -2
  115. package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -1
  116. package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
  117. package/src/esm/utils/helpers/VEllipseSectorHelper.js +1 -0
  118. package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
  119. package/src/esm/utils/parsers/LinearColorGradientParser.d.ts +78 -0
  120. package/src/esm/utils/parsers/LinearColorGradientParser.js +217 -0
  121. package/src/esm/utils/parsers/LinearColorGradientParser.js.map +1 -0
  122. package/src/external.d.ts +9 -0
  123. package/src/ts/PlotBoilerplate.ts +233 -105
  124. package/src/ts/Polygon.ts +68 -14
  125. package/src/ts/Triangle.ts +2 -2
  126. package/src/ts/Vertex.ts +21 -3
  127. package/src/ts/interfaces/core.ts +31 -0
  128. package/src/ts/utils/datastructures/Color.ts +423 -44
  129. package/src/ts/utils/datastructures/ColorGradient.ts +196 -0
  130. package/src/ts/utils/dom/components/ColorGradientPicker.tsx +877 -0
  131. package/src/ts/utils/dom/components/ColorGradientSelector.tsx +445 -0
  132. package/src/ts/utils/dom/components/Test.tsx +44 -0
  133. package/src/ts/utils/dom/components/_ColorGradientPicker_raw.ts_ +392 -0
  134. package/src/ts/utils/dom/guiSizeToggler.ts +1 -1
  135. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +25 -15
  136. package/src/ts/utils/helpers/CircleHelper.ts +17 -3
  137. package/src/ts/utils/helpers/CircleSectorHelper.ts +4 -2
  138. package/src/ts/utils/helpers/TriangleHelper.ts +102 -0
  139. package/src/ts/utils/helpers/VEllipseHelper.ts +6 -4
  140. package/src/ts/utils/helpers/VEllipseSectorHelper.ts +3 -2
  141. package/src/ts/utils/parsers/LinearColorGradientParser.ts +297 -0
@@ -18,7 +18,12 @@
18
18
  * @modified 2022-05-11 Fixed the `interpolate` function.
19
19
  * @modified 2023-01-23 Added `Color.set(Color)` function to set all values (r,g,b,h,s,l,a) simultanoeusly.
20
20
  * @modified 2024-03-10 Fixed some NaN type check for Typescript 5 compatibility.
21
- * @version 0.0.13
21
+ * @modified 2025-08-08 Fixed an issue in the static `makeRGB` method: values in [0..1] are now correctly reconized (1.0 was excluded).
22
+ * @modified 2025-08-08 Added static color instances (singletons): Color.Red, Color.Gold, Color.Yellow, Color.Green, Color.LimeGreen, Color.Blue, Color.MediumBlue, Color.Purple.
23
+ * @modified 2025-09-01 Adding all standard web colors. Source: https://en.wikipedia.org/wiki/Web_colors
24
+ * @modified 2025-09-01 Modifying the `Sanitizer.RGB` helper method: recognoizing 0 to 255 as valid values (not only 1 to 255).
25
+ * @modified 2025-09-01 Modifying the `Color.parse` method: recognizing CSS color strings now.
26
+ * @version 0.0.14
22
27
  **/
23
28
 
24
29
  /**
@@ -333,7 +338,7 @@ export class Color {
333
338
  // }
334
339
  saturate(v: string | number): Color {
335
340
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
336
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
341
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
337
342
  this.s += (1 - this.s) * (v / 100);
338
343
  } else if ("number" == typeof v) {
339
344
  if (v >= -0.0 && v <= 1.0) {
@@ -353,7 +358,7 @@ export class Color {
353
358
  }
354
359
  desaturate(v: string | number): Color {
355
360
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
356
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
361
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
357
362
  this.s -= v / 100;
358
363
  } else if ("number" == typeof v) {
359
364
  if (v >= 0.0 && v <= 1.0) {
@@ -392,8 +397,7 @@ export class Color {
392
397
  // }
393
398
  lighten(v: string | number): Color {
394
399
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
395
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
396
-
400
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
397
401
  this.l += (1 - this.l) * (v / 100);
398
402
  } else if ("number" == typeof v) {
399
403
  if (v >= 0.0 && v <= 1.0) {
@@ -413,7 +417,7 @@ export class Color {
413
417
  }
414
418
  darken(v: string | number): Color {
415
419
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
416
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
420
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
417
421
  this.l -= this.l * (v / 100);
418
422
  } else if ("number" == typeof v) {
419
423
  if (v >= 0.0 && v <= 1.0) {
@@ -433,7 +437,7 @@ export class Color {
433
437
  }
434
438
  fadein(v: string | number): Color {
435
439
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
436
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
440
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
437
441
  this.a += (1 - this.a) * (v / 100);
438
442
  } else if ("number" == typeof v) {
439
443
  if (v >= 0.0 && v <= 1.0) {
@@ -454,7 +458,7 @@ export class Color {
454
458
  }
455
459
  fadeout(v: string | number): Color {
456
460
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
457
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
461
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
458
462
  this.a -= v / 100;
459
463
  } else if ("number" == typeof v) {
460
464
  if (v >= 0.0 && v <= 1.0) {
@@ -474,12 +478,14 @@ export class Color {
474
478
  }
475
479
  spin(v: string | number): Color {
476
480
  // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) this.h += v / 100;
477
- if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
481
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN((v = parseInt(v)))) {
478
482
  this.h += v / 100;
479
483
  } else if ("number" == typeof v) {
480
484
  // range 360
481
485
  this.h += v / 360;
482
- } else throw new Error("error: bad modifier format (percent or number)");
486
+ } else {
487
+ throw new Error("error: bad modifier format (percent or number)");
488
+ }
483
489
  if (this.h > 1) this.h = 1;
484
490
  else if (this.h < 0) this.h = 0;
485
491
  Color.Converter.HSLToRGB(this);
@@ -489,13 +495,15 @@ export class Color {
489
495
  static makeRGB(...args: any[]): Color {
490
496
  const c: Color = new Color();
491
497
  let sanitized: Array<number>;
492
- if (arguments.length < 3 || arguments.length > 4) throw new Error("error: 3 or 4 arguments");
493
- sanitized = Color.Sanitizer.RGB(arguments[0], arguments[1], arguments[2]);
498
+ if (args.length < 3 || args.length > 4) {
499
+ throw new Error("error: 3 or 4 arguments");
500
+ }
501
+ sanitized = Color.Sanitizer.RGB(args[0], args[1], args[2]);
494
502
  c.r = sanitized[0];
495
503
  c.g = sanitized[1];
496
504
  c.b = sanitized[2];
497
- if (arguments.length == 4) {
498
- c.a = arguments[3];
505
+ if (args.length == 4) {
506
+ c.a = args[3];
499
507
  } else {
500
508
  c.a = 1.0;
501
509
  }
@@ -506,13 +514,18 @@ export class Color {
506
514
  static makeHSL(...args: Array<number | string>): Color {
507
515
  const c: Color = new Color();
508
516
  let sanitized: Array<number>;
509
- if (arguments.length < 3 || arguments.length > 4) throw new Error("error: 3 or 4 arguments");
510
- sanitized = Color.Sanitizer.HSL(arguments[0], arguments[1], arguments[2]);
517
+ if (args.length < 3 || args.length > 4) {
518
+ throw new Error("error: 3 or 4 arguments");
519
+ }
520
+ sanitized = Color.Sanitizer.HSL(args[0], args[1], args[2]);
511
521
  c.h = sanitized[0];
512
522
  c.s = sanitized[1];
513
523
  c.l = sanitized[2];
514
- if (arguments.length == 4) c.a = arguments[3];
515
- else c.a = 1.0;
524
+ if (args.length == 4) {
525
+ c.a = typeof args[3] === "string" ? Number.parseFloat(args[3]) : args[3];
526
+ } else {
527
+ c.a = 1.0;
528
+ }
516
529
  Color.Converter.HSLToRGB(c);
517
530
  return c;
518
531
  }
@@ -522,7 +535,9 @@ export class Color {
522
535
  sanitized;
523
536
  // Edit Ika 2018-0308
524
537
  // Allow leading '#'
525
- if (value && value.startsWith("#")) value = value.substr(1);
538
+ if (value && value.startsWith("#")) {
539
+ value = value.substr(1);
540
+ }
526
541
  Color.Validator.checkHEX(value);
527
542
  if (value.length == 3) {
528
543
  sanitized = Color.Sanitizer.RGB(
@@ -536,7 +551,9 @@ export class Color {
536
551
  parseInt(value.substr(2, 2), 16),
537
552
  parseInt(value.substr(4, 2), 16)
538
553
  );
539
- } else throw new Error("error: 3 or 6 arguments");
554
+ } else {
555
+ throw new Error("error: 3 or 6 arguments");
556
+ }
540
557
  c.r = sanitized[0];
541
558
  c.g = sanitized[1];
542
559
  c.b = sanitized[2];
@@ -561,7 +578,9 @@ export class Color {
561
578
  if ((str = str.trim().toLowerCase()).length == 0) {
562
579
  return null;
563
580
  }
564
- if (str.startsWith("#")) return Color.makeHEX(str.substring(1, str.length));
581
+ if (str.startsWith("#")) {
582
+ return Color.makeHEX(str.substring(1, str.length));
583
+ }
565
584
  if (str.startsWith("rgb")) {
566
585
  var parts = str.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,?\s*(\d*(?:\.\d+\s*)?)\)$/);
567
586
  if (!parts) {
@@ -574,42 +593,57 @@ export class Color {
574
593
  } else {
575
594
  return Color.makeRGB(parts[1], parts[2], parts[3], Number(parts[4]));
576
595
  }
577
- } else {
578
- throw "Unrecognized color format (1): " + str;
579
596
  }
597
+
598
+ // Try to locate by CSS color name
599
+ const keys: string[] = Object.keys(Color.CSS_COLORS);
600
+ const cssColorKey: string = keys.reduce((prevKey: string, curKey: string) => {
601
+ if (curKey && curKey.toLowerCase() === str.toLowerCase()) {
602
+ return curKey;
603
+ }
604
+ return prevKey;
605
+ }, null);
606
+ if (cssColorKey) {
607
+ const cssColor: Color = Color.CSS_COLORS[cssColorKey];
608
+ // console.log("cssColor?", cssColor, str, cssColorKey);
609
+ if (cssColor) {
610
+ // console.log("CONSTRUCTOR?", cssColor.constructor);
611
+ return cssColor.clone();
612
+ }
613
+ }
614
+ throw "Unrecognized color format (1): " + str;
580
615
  }
581
616
 
582
617
  private static Sanitizer = {
583
- RGB: function (...args: any[]) {
618
+ RGB: (...args: any[]) => {
584
619
  var o: number[] = [];
585
- if (arguments.length == 0) {
620
+ if (args.length == 0) {
586
621
  return [];
587
622
  }
588
623
  // const allAreFrac = Color.testFrac( arguments );
589
- for (var i = 0; i < arguments.length; i++) {
590
- var c = arguments[i];
624
+ for (var i = 0; i < args.length; i++) {
625
+ var c = args[i];
591
626
  if ("string" == typeof c && c.indexOf("%") > -1) {
592
627
  // if ((c = parseInt(c)) == NaN) throw new Error("Bad format");
593
- if (Number.isNaN(c = parseInt(c))) {
628
+ if (Number.isNaN((c = parseInt(c)))) {
594
629
  throw new Error("Bad format");
595
630
  }
596
631
  if (c < 0 || c > 100) throw new Error("Bad format");
597
632
  o[i] = c / 100;
598
633
  } else {
599
634
  // if ("string" == typeof c && (c = parseInt(c)) == NaN) {
600
- if ("string" == typeof c && Number.isNaN(c = parseInt(c))) {
601
-
635
+ if ("string" == typeof c && Number.isNaN((c = parseInt(c)))) {
602
636
  throw new Error("Bad format");
603
637
  }
604
638
  if (c < 0) {
605
639
  throw new Error("Bad format");
606
640
  }
607
641
  //else if( allAreFrac ) o[i] = c; // c >= 0 && c <= 1 (all)
608
- else if (c >= 0 && c < 1) {
642
+ else if (c >= 0 && c <= 1) {
609
643
  o[i] = c;
610
644
  }
611
645
  // else if(c >= 0.0 && c <= 1.0) o[i] = c;
612
- else if (c >= 1 && c < 256) {
646
+ else if (c >= 0 && c < 256) {
613
647
  o[i] = c / 255;
614
648
  }
615
649
  // ???
@@ -621,32 +655,48 @@ export class Color {
621
655
  },
622
656
 
623
657
  HSL: function (...args: Array<string | number>): Array<number> {
624
- if (arguments.length < 3 || arguments.length > 4) throw new Error("3 or 4 arguments required");
625
- var h = arguments[0],
626
- s = arguments[1],
627
- l = arguments[2];
658
+ if (args.length < 3 || args.length > 4) {
659
+ throw new Error("3 or 4 arguments required");
660
+ }
661
+ var h = args[0],
662
+ s = args[1],
663
+ l = args[2];
628
664
  // if ("string" == typeof h && (h = parseFloat(h)) == NaN) throw new Error("Bad format for hue");
629
- if ("string" == typeof h && Number.isNaN(h = parseFloat(h))) {
630
- throw new Error("Bad format for hue");
665
+ if ("string" == typeof h && Number.isNaN((h = parseFloat(h)))) {
666
+ throw new Error("Bad format for hue");
631
667
  }
632
668
  if (h < 0 || h > 360) throw new Error("Hue out of range (0..360)");
633
669
  else if ((("" + h).indexOf(".") > -1 && h > 1) || ("" + h).indexOf(".") == -1) h /= 360;
634
670
  if ("string" == typeof s && s.indexOf("%") > -1) {
635
671
  // if ((s = parseInt(s)) == NaN) throw new Error("Bad format for saturation");
636
- if (Number.isNaN(s = parseInt(s))) {
672
+ if (Number.isNaN((s = parseInt(s)))) {
673
+ throw new Error("Bad format for saturation");
674
+ }
675
+ if (s < 0 || s > 100) {
637
676
  throw new Error("Bad format for saturation");
638
677
  }
639
- if (s < 0 || s > 100) throw new Error("Bad format for saturation");
640
678
  s /= 100;
641
- } else if (s < 0 || s > 1) throw new Error("Bad format for saturation");
679
+ } else {
680
+ s = typeof s === "string" ? Number.parseFloat(s) : s;
681
+ if (s < 0 || s > 1) {
682
+ throw new Error("Bad format for saturation");
683
+ }
684
+ }
642
685
  if ("string" == typeof l && l.indexOf("%") > -1) {
643
686
  // if ((l = parseInt(l)) == NaN) throw new Error("Bad format for lightness");
644
- if (Number.isNaN(l = parseInt(l))) {
687
+ if (Number.isNaN((l = parseInt(l)))) {
688
+ throw new Error("Bad format for lightness");
689
+ }
690
+ if (l < 0 || l > 100) {
645
691
  throw new Error("Bad format for lightness");
646
692
  }
647
- if (l < 0 || l > 100) throw new Error("Bad format for lightness");
648
693
  l /= 100;
649
- } else if (l < 0 || l > 1) throw new Error("Bad format for lightness");
694
+ } else {
695
+ l = typeof l === "string" ? Number.parseFloat(l) : l;
696
+ if (l < 0 || l > 1) {
697
+ throw new Error("Bad format for lightness");
698
+ }
699
+ }
650
700
  return [h, s, l];
651
701
  }
652
702
  }; // ENd sanitizer
@@ -769,4 +819,333 @@ export class Color {
769
819
  this.a += (c.a - this.a) * t;
770
820
  return this;
771
821
  }
822
+
823
+ // Source
824
+ // https://en.wikipedia.org/wiki/Web_colors
825
+
826
+ // Pink colors
827
+ static MediumVioletRed: Color = Color.makeRGB(199, 21, 133);
828
+ static DeepPink: Color = Color.makeRGB(255, 20, 147);
829
+ static PaleVioletRed: Color = Color.makeRGB(219, 112, 147);
830
+ static HotPink: Color = Color.makeRGB(255, 105, 180);
831
+ static LightPink: Color = Color.makeRGB(255, 182, 193);
832
+ static Pink: Color = Color.makeRGB(255, 192, 203);
833
+
834
+ // Red colors
835
+ static DarkRed: Color = Color.makeRGB(139, 0, 0);
836
+ static Red: Color = Color.makeRGB(255, 0, 0);
837
+ static Firebrick: Color = Color.makeRGB(178, 34, 34);
838
+ static Crimson: Color = Color.makeRGB(220, 20, 60);
839
+ static IndianRed: Color = Color.makeRGB(205, 92, 92);
840
+ static LightCoral: Color = Color.makeRGB(240, 128, 128);
841
+ static Salmon: Color = Color.makeRGB(250, 128, 114);
842
+ static DarkSalmon: Color = Color.makeRGB(233, 150, 122);
843
+ static LightSalmon: Color = Color.makeRGB(255, 160, 122);
844
+
845
+ // Orange colors
846
+ static OrangeRed: Color = Color.makeRGB(255, 69, 0);
847
+ static Tomato: Color = Color.makeRGB(255, 99, 71);
848
+ static DarkOrange: Color = Color.makeRGB(255, 140, 0);
849
+ static Coral: Color = Color.makeRGB(255, 127, 80);
850
+ static Orange: Color = Color.makeRGB(255, 165, 0);
851
+
852
+ // Yellow colors
853
+ static DarkKhaki: Color = Color.makeRGB(189, 183, 107);
854
+ static Gold: Color = Color.makeRGB(255, 215, 0);
855
+ static Khaki: Color = Color.makeRGB(240, 230, 140);
856
+ static PeachPuff: Color = Color.makeRGB(255, 218, 185);
857
+ static Yellow: Color = Color.makeRGB(255, 255, 0);
858
+ static PaleGoldenrod: Color = Color.makeRGB(238, 232, 170);
859
+ static Moccasin: Color = Color.makeRGB(255, 228, 181);
860
+ static PapayaWhip: Color = Color.makeRGB(255, 239, 213);
861
+ static LightGoldenrodYellow: Color = Color.makeRGB(250, 250, 210);
862
+ static LemonChiffon: Color = Color.makeRGB(255, 250, 205);
863
+ static LightYellow: Color = Color.makeRGB(255, 255, 224);
864
+
865
+ // Brown colors
866
+ static Maroon: Color = Color.makeRGB(128, 0, 0);
867
+ static Brown: Color = Color.makeRGB(165, 42, 42);
868
+ static SaddleBrown: Color = Color.makeRGB(139, 69, 19);
869
+ static Sienna: Color = Color.makeRGB(160, 82, 45);
870
+ static Chocolate: Color = Color.makeRGB(210, 105, 30);
871
+ static DarkGoldenrod: Color = Color.makeRGB(184, 134, 11);
872
+ static Peru: Color = Color.makeRGB(205, 133, 63);
873
+ static RosyBrown: Color = Color.makeRGB(188, 143, 143);
874
+ static Goldenrod: Color = Color.makeRGB(218, 165, 32);
875
+ static SandyBrown: Color = Color.makeRGB(244, 164, 96);
876
+ static Tan: Color = Color.makeRGB(210, 180, 140);
877
+ static Burlywood: Color = Color.makeRGB(222, 184, 135);
878
+ static Wheat: Color = Color.makeRGB(245, 222, 179);
879
+ static NavajoWhite: Color = Color.makeRGB(255, 222, 173);
880
+ static Bisque: Color = Color.makeRGB(255, 228, 196);
881
+ static BlanchedAlmond: Color = Color.makeRGB(255, 235, 205);
882
+ static Cornsilk: Color = Color.makeRGB(255, 248, 220);
883
+
884
+ // Purple, violet, and magenta colors
885
+ static Indigo: Color = Color.makeRGB(75, 0, 130);
886
+ static Purple: Color = Color.makeRGB(128, 0, 128);
887
+ static DarkMagenta: Color = Color.makeRGB(139, 0, 139);
888
+ static DarkViolet: Color = Color.makeRGB(148, 0, 211);
889
+ static DarkSlateBlue: Color = Color.makeRGB(72, 61, 139);
890
+ static BlueViolet: Color = Color.makeRGB(138, 43, 226);
891
+ static DarkOrchid: Color = Color.makeRGB(153, 50, 204);
892
+ static Fuchsia: Color = Color.makeRGB(255, 0, 255);
893
+ static Magenta: Color = Color.makeRGB(255, 0, 255);
894
+ static SlateBlue: Color = Color.makeRGB(106, 90, 205);
895
+ static MediumSlateBlue: Color = Color.makeRGB(123, 104, 238);
896
+ static MediumOrchid: Color = Color.makeRGB(186, 85, 211);
897
+ static MediumPurple: Color = Color.makeRGB(147, 112, 219);
898
+ static Orchid: Color = Color.makeRGB(218, 112, 214);
899
+ static Violet: Color = Color.makeRGB(238, 130, 238);
900
+ static Plum: Color = Color.makeRGB(221, 160, 221);
901
+ static Thistle: Color = Color.makeRGB(216, 191, 216);
902
+ static Lavender: Color = Color.makeRGB(230, 230, 250);
903
+
904
+ // Blue colors
905
+ static MidnightBlue: Color = Color.makeRGB(25, 25, 112);
906
+ static Navy: Color = Color.makeRGB(0, 0, 128);
907
+ static DarkBlue: Color = Color.makeRGB(0, 0, 139);
908
+ static MediumBlue: Color = Color.makeRGB(0, 0, 205);
909
+ static Blue: Color = Color.makeRGB(0, 0, 255);
910
+ static RoyalBlue: Color = Color.makeRGB(65, 105, 225);
911
+ static SteelBlue: Color = Color.makeRGB(70, 130, 180);
912
+ static DodgerBlue: Color = Color.makeRGB(30, 144, 255);
913
+ static DeepSkyBlue: Color = Color.makeRGB(0, 191, 255);
914
+ static CornflowerBlue: Color = Color.makeRGB(100, 149, 237);
915
+ static SkyBlue: Color = Color.makeRGB(135, 206, 235);
916
+ static LightSkyBlue: Color = Color.makeRGB(135, 206, 250);
917
+ static LightSteelBlue: Color = Color.makeRGB(176, 196, 222);
918
+ static LightBlue: Color = Color.makeRGB(173, 216, 230);
919
+ static PowderBlue: Color = Color.makeRGB(176, 224, 230);
920
+
921
+ // Cyan colors
922
+ static Teal: Color = Color.makeRGB(0, 128, 128);
923
+ static DarkCyan: Color = Color.makeRGB(0, 139, 139);
924
+ static LightSeaGreen: Color = Color.makeRGB(32, 178, 170);
925
+ static CadetBlue: Color = Color.makeRGB(95, 158, 160);
926
+ static DarkTurquoise: Color = Color.makeRGB(0, 206, 209);
927
+ static MediumTurquoise: Color = Color.makeRGB(72, 209, 204);
928
+ static Turquoise: Color = Color.makeRGB(64, 224, 208);
929
+ static Aqua: Color = Color.makeRGB(0, 255, 255);
930
+ static Cyan: Color = Color.makeRGB(0, 255, 255);
931
+ static Aquamarine: Color = Color.makeRGB(127, 255, 212);
932
+ static PaleTurquoise: Color = Color.makeRGB(175, 238, 238);
933
+ static LightCyan: Color = Color.makeRGB(224, 255, 255);
934
+
935
+ // Green colors
936
+ static DarkGreen: Color = Color.makeRGB(0, 100, 0);
937
+ static Green: Color = Color.makeRGB(0, 128, 0);
938
+ static DarkOliveGreen: Color = Color.makeRGB(85, 107, 47);
939
+ static ForestGreen: Color = Color.makeRGB(34, 139, 34);
940
+ static SeaGreen: Color = Color.makeRGB(46, 139, 87);
941
+ static Olive: Color = Color.makeRGB(128, 128, 0);
942
+ static OliveDrab: Color = Color.makeRGB(107, 142, 35);
943
+ static MediumSeaGreen: Color = Color.makeRGB(60, 179, 113);
944
+ static LimeGreen: Color = Color.makeRGB(50, 205, 50);
945
+ static Lime: Color = Color.makeRGB(0, 255, 0);
946
+ static SpringGreen: Color = Color.makeRGB(0, 255, 127);
947
+ static MediumSpringGreen: Color = Color.makeRGB(0, 250, 154);
948
+ static DarkSeaGreen: Color = Color.makeRGB(143, 188, 143);
949
+ static MediumAquamarine: Color = Color.makeRGB(102, 205, 170);
950
+ static YellowGreen: Color = Color.makeRGB(154, 205, 50);
951
+ static LawnGreen: Color = Color.makeRGB(124, 252, 0);
952
+ static Chartreuse: Color = Color.makeRGB(127, 255, 0);
953
+ static LightGreen: Color = Color.makeRGB(144, 238, 144);
954
+ static GreenYellow: Color = Color.makeRGB(173, 255, 47);
955
+ static PaleGreen: Color = Color.makeRGB(152, 251, 152);
956
+
957
+ // White colors
958
+ static MistyRose: Color = Color.makeRGB(255, 228, 225);
959
+ static AntiqueWhite: Color = Color.makeRGB(250, 235, 215);
960
+ static Linen: Color = Color.makeRGB(250, 240, 230);
961
+ static Beige: Color = Color.makeRGB(245, 245, 220);
962
+ static WhiteSmoke: Color = Color.makeRGB(245, 245, 245);
963
+ static LavenderBlush: Color = Color.makeRGB(255, 240, 245);
964
+ static OldLace: Color = Color.makeRGB(253, 245, 230);
965
+ static AliceBlue: Color = Color.makeRGB(240, 248, 255);
966
+ static Seashell: Color = Color.makeRGB(255, 245, 238);
967
+ static GhostWhite: Color = Color.makeRGB(248, 248, 255);
968
+ static Honeydew: Color = Color.makeRGB(240, 255, 240);
969
+ static FloralWhite: Color = Color.makeRGB(255, 250, 240);
970
+ static Azure: Color = Color.makeRGB(240, 255, 255);
971
+ static MintCream: Color = Color.makeRGB(245, 255, 250);
972
+ static Snow: Color = Color.makeRGB(255, 250, 250);
973
+ static Ivory: Color = Color.makeRGB(255, 255, 240);
974
+ static White: Color = Color.makeRGB(255, 255, 255);
975
+
976
+ // Gray and black colors
977
+ static Black: Color = Color.makeRGB(0, 0, 0);
978
+ static DarkSlateGray: Color = Color.makeRGB(47, 79, 79);
979
+ static DimGray: Color = Color.makeRGB(105, 105, 105);
980
+ static SlateGray: Color = Color.makeRGB(112, 128, 144);
981
+ static Gray: Color = Color.makeRGB(128, 128, 128);
982
+ static LightSlateGray: Color = Color.makeRGB(119, 136, 153);
983
+ static DarkGray: Color = Color.makeRGB(169, 169, 169);
984
+ static Silver: Color = Color.makeRGB(192, 192, 192);
985
+ static LightGray: Color = Color.makeRGB(211, 211, 211);
986
+ static Gainsboro: Color = Color.makeRGB(220, 220, 220);
987
+
988
+ static CSS_COLORS: Record<string, Color> = {
989
+ // Pink Color.XYZ,lors
990
+ MediumVioletRed: Color.MediumVioletRed,
991
+ DeepPink: Color.DeepPink,
992
+ PaleVioletRed: Color.PaleVioletRed,
993
+ HotPink: Color.HotPink,
994
+ LightPink: Color.LightPink,
995
+ Pink: Color.Pink,
996
+
997
+ // Red Color.XYZ,lors
998
+ DarkRed: Color.DarkRed,
999
+ Red: Color.Red,
1000
+ Firebrick: Color.Firebrick,
1001
+ Crimson: Color.Crimson,
1002
+ IndianRed: Color.IndianRed,
1003
+ LightCoral: Color.LightCoral,
1004
+ Salmon: Color.Salmon,
1005
+ DarkSalmon: Color.DarkSalmon,
1006
+ LightSalmon: Color.LightSalmon,
1007
+
1008
+ // Orange Color.XYZ,lors
1009
+ OrangeRed: Color.OrangeRed,
1010
+ Tomato: Color.Tomato,
1011
+ DarkOrange: Color.DarkOrange,
1012
+ Coral: Color.Coral,
1013
+ Orange: Color.Orange,
1014
+
1015
+ // Yellow Color.XYZ,lors
1016
+ DarkKhaki: Color.DarkKhaki,
1017
+ Gold: Color.Gold,
1018
+ Khaki: Color.Khaki,
1019
+ PeachPuff: Color.PeachPuff,
1020
+ Yellow: Color.Yellow,
1021
+ PaleGoldenrod: Color.PaleGoldenrod,
1022
+ Moccasin: Color.Moccasin,
1023
+ PapayaWhip: Color.PapayaWhip,
1024
+ LightGoldenrodYellow: Color.LightGoldenrodYellow,
1025
+ LemonChiffon: Color.LemonChiffon,
1026
+ LightYellow: Color.LightYellow,
1027
+
1028
+ // Brown Color.XYZ,lors
1029
+ Maroon: Color.Maroon,
1030
+ Brown: Color.Brown,
1031
+ SaddleBrown: Color.SaddleBrown,
1032
+ Sienna: Color.Sienna,
1033
+ Chocolate: Color.Chocolate,
1034
+ DarkGoldenrod: Color.DarkGoldenrod,
1035
+ Peru: Color.Peru,
1036
+ RosyBrown: Color.RosyBrown,
1037
+ Goldenrod: Color.Goldenrod,
1038
+ SandyBrown: Color.SandyBrown,
1039
+ Tan: Color.Tan,
1040
+ Burlywood: Color.Burlywood,
1041
+ Wheat: Color.Wheat,
1042
+ NavajoWhite: Color.NavajoWhite,
1043
+ Bisque: Color.Bisque,
1044
+ BlanchedAlmond: Color.BlanchedAlmond,
1045
+ Cornsilk: Color.Cornsilk,
1046
+
1047
+ // Purple, violet, and magenta Color.XYZ,lors
1048
+ Indigo: Color.Indigo,
1049
+ Purple: Color.Purple,
1050
+ DarkMagenta: Color.DarkMagenta,
1051
+ DarkViolet: Color.DarkViolet,
1052
+ DarkSlateBlue: Color.DarkSlateBlue,
1053
+ BlueViolet: Color.BlueViolet,
1054
+ DarkOrchid: Color.DarkOrchid,
1055
+ Fuchsia: Color.Fuchsia,
1056
+ Magenta: Color.Magenta,
1057
+ SlateBlue: Color.SlateBlue,
1058
+ MediumSlateBlue: Color.MediumSlateBlue,
1059
+ MediumOrchid: Color.MediumOrchid,
1060
+ MediumPurple: Color.MediumPurple,
1061
+ Orchid: Color.Orchid,
1062
+ Violet: Color.Violet,
1063
+ Plum: Color.Plum,
1064
+ Thistle: Color.Thistle,
1065
+ Lavender: Color.Lavender,
1066
+
1067
+ // Blue Colors
1068
+ MidnightBlue: Color.MidnightBlue,
1069
+ Navy: Color.Navy,
1070
+ DarkBlue: Color.DarkBlue,
1071
+ MediumBlue: Color.MediumBlue,
1072
+ Blue: Color.Blue,
1073
+ RoyalBlue: Color.RoyalBlue,
1074
+ SteelBlue: Color.SteelBlue,
1075
+ DodgerBlue: Color.DodgerBlue,
1076
+ DeepSkyBlue: Color.DeepSkyBlue,
1077
+ CornflowerBlue: Color.CornflowerBlue,
1078
+ SkyBlue: Color.SkyBlue,
1079
+ LightSkyBlue: Color.LightSkyBlue,
1080
+ LightSteelBlue: Color.LightSteelBlue,
1081
+ LightBlue: Color.LightBlue,
1082
+ PowderBlue: Color.PowderBlue,
1083
+
1084
+ // Coyan Colors
1085
+ Teal: Color.Teal,
1086
+ DarkCyan: Color.DarkCyan,
1087
+ LightSeaGreen: Color.LightSeaGreen,
1088
+ CadetBlue: Color.CadetBlue,
1089
+ DarkTurquoise: Color.DarkTurquoise,
1090
+ MediumTurquoise: Color.MediumTurquoise,
1091
+ Turquoise: Color.Turquoise,
1092
+ Aqua: Color.Aqua,
1093
+ Cyan: Color.Cyan,
1094
+ Aquamarine: Color.Aquamarine,
1095
+ PaleTurquoise: Color.PaleTurquoise,
1096
+ LightCyan: Color.LightCyan,
1097
+
1098
+ // Green Colors
1099
+ DarkGreen: Color.DarkGreen,
1100
+ Green: Color.Green,
1101
+ DarkOliveGreen: Color.DarkOliveGreen,
1102
+ ForestGreen: Color.ForestGreen,
1103
+ SeaGreen: Color.SeaGreen,
1104
+ Olive: Color.Olive,
1105
+ OliveDrab: Color.OliveDrab,
1106
+ MediumSeaGreen: Color.MediumSeaGreen,
1107
+ LimeGreen: Color.LimeGreen,
1108
+ Lime: Color.Lime,
1109
+ SpringGreen: Color.SpringGreen,
1110
+ MediumSpringGreen: Color.MediumSpringGreen,
1111
+ DarkSeaGreen: Color.DarkSeaGreen,
1112
+ MediumAquamarine: Color.MediumAquamarine,
1113
+ YellowGreen: Color.YellowGreen,
1114
+ LawnGreen: Color.LawnGreen,
1115
+ Chartreuse: Color.Chartreuse,
1116
+ LightGreen: Color.LightGreen,
1117
+ GreenYellow: Color.GreenYellow,
1118
+ PaleGreen: Color.PaleGreen,
1119
+
1120
+ // White Color.XYZ,lors
1121
+ MistyRose: Color.MistyRose,
1122
+ AntiqueWhite: Color.AntiqueWhite,
1123
+ Linen: Color.Linen,
1124
+ Beige: Color.Beige,
1125
+ WhiteSmoke: Color.WhiteSmoke,
1126
+ LavenderBlush: Color.LavenderBlush,
1127
+ OldLace: Color.OldLace,
1128
+ AliceBlue: Color.AliceBlue,
1129
+ Seashell: Color.Seashell,
1130
+ GhostWhite: Color.GhostWhite,
1131
+ Honeydew: Color.Honeydew,
1132
+ FloralWhite: Color.FloralWhite,
1133
+ Azure: Color.Azure,
1134
+ MintCream: Color.MintCream,
1135
+ Snow: Color.Snow,
1136
+ Ivory: Color.Ivory,
1137
+ White: Color.White,
1138
+
1139
+ // Gray and black Color.XYZ,lors
1140
+ Black: Color.Black,
1141
+ DarkSlateGray: Color.DarkSlateGray,
1142
+ DimGray: Color.DimGray,
1143
+ SlateGray: Color.SlateGray,
1144
+ Gray: Color.Gray,
1145
+ LightSlateGray: Color.LightSlateGray,
1146
+ DarkGray: Color.DarkGray,
1147
+ Silver: Color.Silver,
1148
+ LightGray: Color.LightGray,
1149
+ Gainsboro: Color.Gainsboro
1150
+ };
772
1151
  } // END class