@thednp/color-picker 1.0.1 → 2.0.0-alpha10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/.eslintrc.cjs +199 -0
  2. package/.lgtm.yml +9 -0
  3. package/.prettierrc.json +15 -0
  4. package/.stylelintrc.json +236 -0
  5. package/README.md +55 -72
  6. package/compile.js +51 -0
  7. package/cypress/e2e/color-palette.cy.ts +128 -0
  8. package/cypress/e2e/color-picker.cy.ts +909 -0
  9. package/cypress/fixtures/colorNamesFrench.js +3 -0
  10. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  11. package/cypress/fixtures/format.js +3 -0
  12. package/cypress/fixtures/getMarkup.js +35 -0
  13. package/cypress/fixtures/getRandomInt.js +6 -0
  14. package/cypress/fixtures/sampleWebcolors.js +18 -0
  15. package/cypress/fixtures/testSample.js +8 -0
  16. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  17. package/cypress/plugins/tsCompile.ts +34 -0
  18. package/cypress/support/commands.ts +0 -0
  19. package/cypress/support/e2e.ts +21 -0
  20. package/cypress/test.html +23 -0
  21. package/cypress.config.ts +29 -0
  22. package/dist/css/color-picker.css +25 -54
  23. package/dist/css/color-picker.min.css +2 -2
  24. package/dist/css/color-picker.rtl.css +25 -54
  25. package/dist/css/color-picker.rtl.min.css +2 -2
  26. package/dist/js/color-picker.cjs +8 -0
  27. package/dist/js/color-picker.cjs.map +1 -0
  28. package/dist/js/color-picker.d.ts +296 -0
  29. package/dist/js/color-picker.js +5 -3570
  30. package/dist/js/color-picker.js.map +1 -0
  31. package/dist/js/color-picker.mjs +2618 -0
  32. package/dist/js/color-picker.mjs.map +1 -0
  33. package/dts.config.ts +15 -0
  34. package/package.json +116 -108
  35. package/src/scss/_variables.scss +0 -1
  36. package/src/scss/color-picker.rtl.scss +4 -0
  37. package/src/scss/color-picker.scss +93 -51
  38. package/src/ts/colorPalette.ts +89 -0
  39. package/src/{js/color-picker.js → ts/index.ts} +498 -509
  40. package/src/ts/interface/ColorNames.ts +20 -0
  41. package/src/ts/interface/colorPickerLabels.ts +20 -0
  42. package/src/ts/interface/colorPickerOptions.ts +11 -0
  43. package/src/ts/interface/paletteOptions.ts +6 -0
  44. package/src/ts/util/colorNames.ts +21 -0
  45. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  46. package/src/ts/util/getColorControls.ts +90 -0
  47. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  48. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  49. package/src/ts/util/isValidJSON.ts +19 -0
  50. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +61 -50
  51. package/tsconfig.json +29 -0
  52. package/vite.config.ts +34 -0
  53. package/dist/js/color-esm.js +0 -1164
  54. package/dist/js/color-esm.min.js +0 -2
  55. package/dist/js/color-palette-esm.js +0 -1235
  56. package/dist/js/color-palette-esm.min.js +0 -2
  57. package/dist/js/color-palette.js +0 -1243
  58. package/dist/js/color-palette.min.js +0 -2
  59. package/dist/js/color-picker-element-esm.js +0 -3718
  60. package/dist/js/color-picker-element-esm.min.js +0 -2
  61. package/dist/js/color-picker-element.js +0 -3726
  62. package/dist/js/color-picker-element.min.js +0 -2
  63. package/dist/js/color-picker-esm.js +0 -3565
  64. package/dist/js/color-picker-esm.min.js +0 -2
  65. package/dist/js/color-picker.min.js +0 -2
  66. package/dist/js/color.js +0 -1172
  67. package/dist/js/color.min.js +0 -2
  68. package/src/js/color-palette.js +0 -75
  69. package/src/js/color-picker-element.js +0 -107
  70. package/src/js/color.js +0 -1104
  71. package/src/js/index.js +0 -8
  72. package/src/js/util/colorNames.js +0 -6
  73. package/src/js/util/getColorControls.js +0 -103
  74. package/src/js/util/isValidJSON.js +0 -13
  75. package/src/js/util/nonColors.js +0 -5
  76. package/src/js/util/roundPart.js +0 -9
  77. package/src/js/util/setCSSProperties.js +0 -12
  78. package/src/js/util/tabindex.js +0 -3
  79. package/src/js/util/toggleCEAttr.js +0 -70
  80. package/src/js/util/version.js +0 -5
  81. package/src/js/version.js +0 -5
  82. package/types/cp.d.ts +0 -558
  83. package/types/index.d.ts +0 -44
  84. package/types/source/source.ts +0 -4
  85. package/types/source/types.d.ts +0 -92
  86. /package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
package/compile.js ADDED
@@ -0,0 +1,51 @@
1
+ // ColorPicker | Compile SCSS Script
2
+ // Build script to compile and minify the CSS file from SCSS folder
3
+ // Usage: npm run compile-scss
4
+
5
+ const {writeFileSync} = require("fs");
6
+ // const writeFileSync = fs.writeFileSync;
7
+ // import { writeFileSync } from "fs";
8
+ const sass = require("sass");
9
+ const pkg = require("./package.json");
10
+ const year = new Date().getFullYear();
11
+ const args = {};
12
+ const pkName = pkg.name.includes(pkg.author) ? pkg.name.replace('@','') : `${pkg.author}/${pkg.name}`;
13
+ const home = `https://github.com/${pkName}`;
14
+
15
+ const ARGS = process.argv.slice(-1)[0].split(",");
16
+ ARGS.map((x) => {
17
+ const [name, value] = x.split(":");
18
+ args[name] = value;
19
+ });
20
+
21
+ const RTL = args.DIR === "rtl" ? "RTL " : "";
22
+ const banner =
23
+ args.MIN === "true"
24
+ ? `/* ColorPicker ${RTL}v${pkg.version} | ${pkg.author} © ${year} | ${pkg.license}-License */`
25
+ : `/*!
26
+ * ColorPicker v${pkg.version} (${pkg.homepage})
27
+ * Copyright ${year} © ${pkg.author}
28
+ * Licensed under MIT (${home}/blob/main/LICENSE)
29
+ */`;
30
+
31
+ const DIR = args.DIR === "rtl" ? ".rtl" : "";
32
+ const MIN = args.MIN === "true" ? ".min" : "";
33
+ const INPUTFILE = args.INPUTFILE
34
+ ? args.INPUTFILE
35
+ : `./src/scss/color-picker${DIR}.scss`;
36
+ const OUTPUTFILE = args.OUTPUTFILE
37
+ ? args.OUTPUTFILE
38
+ : `./dist/css/color-picker${DIR}${MIN}.css`;
39
+ const COMPRESS = args.MIN === "true" ? "compressed" : "expanded";
40
+
41
+ // Helper Functions
42
+ function compile(inputPath, writePath, compressType) {
43
+ const result = sass.compile(inputPath, {
44
+ style: compressType,
45
+ loadPaths: ["src/scss"],
46
+ });
47
+ writeFileSync(writePath, `${banner}\n` + result.css.toString());
48
+ console.log(`✅ Compiled ${inputPath} to ${writePath}.`);
49
+ }
50
+
51
+ compile(INPUTFILE, OUTPUTFILE, COMPRESS);
@@ -0,0 +1,128 @@
1
+ /// <reference types="cypress" />
2
+
3
+ import Color from "@thednp/color";
4
+ import ColorPalette from "../../src/ts/colorPalette";
5
+
6
+ describe("ColorPalette Class Test", () => {
7
+ it("Test init with no parameter, use all default values", () => {
8
+ cy.wrap(new ColorPalette()).as("cpl")
9
+ .get("@cpl").should("be.instanceOf", ColorPalette)
10
+ .get("@cpl").its("hue").should("equal", 0)
11
+ .get("@cpl").its("hueSteps").should("equal", 12)
12
+ .get("@cpl").its("lightSteps").should("equal", 10)
13
+ .get("@cpl").its("colors").its("length").should("equal", 120);
14
+ });
15
+
16
+ it("Test init with 1 parameter, throws error", () => {
17
+ try {
18
+ new ColorPalette(0, undefined);
19
+ } catch (error) {
20
+ expect(error).to.be.instanceOf(TypeError);
21
+ expect(error).to.have.property(
22
+ "message",
23
+ 'ColorPalette: the two minimum arguments must be numbers higher than 0.'
24
+ );
25
+ }
26
+ });
27
+
28
+ // it("Test init with 1 parameter, throws error", () => {
29
+ // try {
30
+ // // @ts-ignore
31
+ // new ColorPalette(0, 'a');
32
+ // } catch (error) {
33
+ // expect(error).to.be.instanceOf(TypeError);
34
+ // expect(error).to.have.property(
35
+ // "message",
36
+ // 'ColorPalette only accepts numbers.'
37
+ // );
38
+ // }
39
+ // });
40
+
41
+ it("Test init with 2 invalid parameters, throws error", () => {
42
+ try {
43
+ new ColorPalette(0, 5);
44
+ } catch (error) {
45
+ expect(error).to.be.instanceOf(TypeError);
46
+ expect(error).to.have.property(
47
+ "message",
48
+ 'ColorPalette: the two minimum arguments must be numbers higher than 0.'
49
+ );
50
+ }
51
+ });
52
+
53
+ it("Test init with 2 valid parameters", () => {
54
+ // generated with new `ColorPalette(1, 5)`
55
+ const testSample = ["#330000", "#990000", "#ff0000", "#ff6666", "#ffcccc"];
56
+
57
+ cy.wrap(new ColorPalette(1, 5)).as("cpl")
58
+ .get("@cpl").its("hue").should("equal", 0)
59
+ .get("@cpl").its("hueSteps").should("equal", 1)
60
+ .get("@cpl").its("lightSteps").should("equal", 5)
61
+ .get("@cpl").its("saturation").should("equal", 100)
62
+ .get("@cpl").its("colors").its("length").should("equal", 5)
63
+ .get("@cpl").its("colors").then((colors) => {
64
+ // really test every color in the palette
65
+ colors.forEach((color: Color, i: number) => {
66
+ cy.log(`${color.ok}`)
67
+ expect(color).to.be.instanceOf(Color);
68
+ // expect(color.ok).to.be.true;
69
+ expect(color.toHexString()).to.equal(testSample[i]);
70
+ });
71
+ });
72
+ });
73
+
74
+ it("Test init with 14 lightSteps", () => {
75
+ // generated with `new ColorPalette(1, 14)`
76
+ const testSample = [
77
+ "#330000", "#550000", "#770000", "#990000", "#bb0000",
78
+ "#dd0000", "#ff0000", "#ff2222", "#ff4444", "#ff6666",
79
+ "#ff8888", "#ffaaaa", "#ffcccc", "#ffeeee",
80
+ ];
81
+
82
+ cy.wrap(new ColorPalette(1, 14)).as("cpl")
83
+ .get("@cpl").its("hue").should("equal", 0)
84
+ .get("@cpl").its("hueSteps").should("equal", 1)
85
+ .get("@cpl").its("lightSteps").should("equal", 14)
86
+ .get("@cpl").its("colors").its("length").should("equal", 14)
87
+ .get("@cpl").its("colors").then((colors) => {
88
+ expect(colors.map((c: Color) => c.toHexString())).to.deep.equal(testSample);
89
+ });
90
+ });
91
+
92
+ it("Test init with 15 lightSteps", () => {
93
+ // generated with `new ColorPalette(1, 15)`
94
+ const testSample = [
95
+ "#110000", "#330000", "#550000", "#770000",
96
+ "#990000", "#bb0000", "#dd0000", "#ff0000",
97
+ "#ff2222", "#ff4444", "#ff6666", "#ff8888",
98
+ "#ffaaaa", "#ffcccc", "#ffeeee",
99
+ ];
100
+
101
+ cy.wrap(new ColorPalette(1, 15)).as("cpl")
102
+ .get("@cpl").its("hue").should("equal", 0)
103
+ .get("@cpl").its("hueSteps").should("equal", 1)
104
+ .get("@cpl").its("lightSteps").should("equal", 15)
105
+ .get("@cpl").its("colors").its("length").should("equal", 15)
106
+ .get("@cpl").its("colors").then((colors) => {
107
+ expect(colors.map((c: Color) => c.toHexString())).to.deep.equal(testSample);
108
+ });
109
+ });
110
+
111
+ it("Test init with 3 valid parameters", () => {
112
+ // generated with `new ColorPalette(270, 1, 10)`
113
+ const testSample = [
114
+ "#240047", "#3b0075", "#5200a3", "#6900d1",
115
+ "#8000ff", "#962eff", "#ad5cff", "#c48aff",
116
+ "#dbb8ff", "#f2e6ff",
117
+ ];
118
+
119
+ cy.wrap(new ColorPalette(270, 1, 10)).as("cpl")
120
+ .get("@cpl").its("hue").should("equal", 270)
121
+ .get("@cpl").its("hueSteps").should("equal", 1)
122
+ .get("@cpl").its("lightSteps").should("equal", 10)
123
+ .get("@cpl").its("colors").its("length").should("equal", 10)
124
+ .get("@cpl").its("colors").then((colors) => {
125
+ expect(colors.map((c: Color) => c.toHexString())).to.deep.equal(testSample);
126
+ });
127
+ });
128
+ });