@thednp/color-picker 1.0.1 → 2.0.0-alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) 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/LICENSE +0 -0
  6. package/README.md +55 -72
  7. package/compile.js +48 -0
  8. package/cypress/e2e/color-palette.cy.ts +128 -0
  9. package/cypress/e2e/color-picker.cy.ts +920 -0
  10. package/cypress/fixtures/colorNamesFrench.js +3 -0
  11. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  12. package/cypress/fixtures/format.js +3 -0
  13. package/cypress/fixtures/getCEMarkup.js +29 -0
  14. package/cypress/fixtures/getMarkup.js +28 -0
  15. package/cypress/fixtures/getRandomInt.js +6 -0
  16. package/cypress/fixtures/sampleWebcolors.js +18 -0
  17. package/cypress/fixtures/testSample.js +8 -0
  18. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  19. package/cypress/plugins/tsCompile.ts +34 -0
  20. package/cypress/support/commands.ts +0 -0
  21. package/cypress/support/e2e.ts +21 -0
  22. package/cypress/test.html +23 -0
  23. package/cypress.config.ts +29 -0
  24. package/dist/css/color-picker.css +16 -40
  25. package/dist/css/color-picker.min.css +2 -2
  26. package/dist/css/color-picker.rtl.css +16 -40
  27. package/dist/css/color-picker.rtl.min.css +2 -2
  28. package/dist/js/color-picker.cjs +8 -0
  29. package/dist/js/color-picker.cjs.map +1 -0
  30. package/dist/js/color-picker.d.ts +278 -0
  31. package/dist/js/color-picker.js +5 -3570
  32. package/dist/js/color-picker.js.map +1 -0
  33. package/dist/js/color-picker.mjs +2631 -0
  34. package/dist/js/color-picker.mjs.map +1 -0
  35. package/dts.config.ts +15 -0
  36. package/package.json +64 -74
  37. package/src/scss/_variables.scss +0 -1
  38. package/src/scss/color-picker.rtl.scss +4 -0
  39. package/src/scss/color-picker.scss +80 -40
  40. package/src/ts/colorPalette.ts +89 -0
  41. package/src/{js/color-picker.js → ts/index.ts} +489 -486
  42. package/src/ts/interface/colorPickerLabels.ts +20 -0
  43. package/src/ts/interface/colorPickerOptions.ts +11 -0
  44. package/src/ts/interface/paletteOptions.ts +6 -0
  45. package/src/ts/util/colorNames.ts +21 -0
  46. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  47. package/src/ts/util/getColorControls.ts +90 -0
  48. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  49. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  50. package/src/ts/util/isValidJSON.ts +19 -0
  51. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +57 -48
  52. package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
  53. package/tsconfig.json +29 -0
  54. package/vite.config.ts +34 -0
  55. package/dist/js/color-esm.js +0 -1164
  56. package/dist/js/color-esm.min.js +0 -2
  57. package/dist/js/color-palette-esm.js +0 -1235
  58. package/dist/js/color-palette-esm.min.js +0 -2
  59. package/dist/js/color-palette.js +0 -1243
  60. package/dist/js/color-palette.min.js +0 -2
  61. package/dist/js/color-picker-element-esm.js +0 -3718
  62. package/dist/js/color-picker-element-esm.min.js +0 -2
  63. package/dist/js/color-picker-element.js +0 -3726
  64. package/dist/js/color-picker-element.min.js +0 -2
  65. package/dist/js/color-picker-esm.js +0 -3565
  66. package/dist/js/color-picker-esm.min.js +0 -2
  67. package/dist/js/color-picker.min.js +0 -2
  68. package/dist/js/color.js +0 -1172
  69. package/dist/js/color.min.js +0 -2
  70. package/src/js/color-palette.js +0 -75
  71. package/src/js/color-picker-element.js +0 -107
  72. package/src/js/color.js +0 -1104
  73. package/src/js/index.js +0 -8
  74. package/src/js/util/colorNames.js +0 -6
  75. package/src/js/util/getColorControls.js +0 -103
  76. package/src/js/util/isValidJSON.js +0 -13
  77. package/src/js/util/nonColors.js +0 -5
  78. package/src/js/util/roundPart.js +0 -9
  79. package/src/js/util/setCSSProperties.js +0 -12
  80. package/src/js/util/tabindex.js +0 -3
  81. package/src/js/util/toggleCEAttr.js +0 -70
  82. package/src/js/util/version.js +0 -5
  83. package/src/js/version.js +0 -5
  84. package/types/cp.d.ts +0 -558
  85. package/types/index.d.ts +0 -44
  86. package/types/source/source.ts +0 -4
  87. package/types/source/types.d.ts +0 -92
package/compile.js ADDED
@@ -0,0 +1,48 @@
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 fs = require("fs");
6
+ const writeFileSync = fs.writeFileSync;
7
+ const sass = require("sass");
8
+ const pkg = require("./package.json");
9
+ const year = new Date().getFullYear();
10
+ const args = {};
11
+
12
+ const ARGS = process.argv.slice(-1)[0].split(",");
13
+ ARGS.map((x) => {
14
+ const [name, value] = x.split(":");
15
+ args[name] = value;
16
+ });
17
+
18
+ const RTL = args.DIR === "rtl" ? "RTL " : "";
19
+ const banner =
20
+ args.MIN === "true"
21
+ ? `/* ColorPicker ${RTL}v${pkg.version} | ${pkg.author} © ${year} | ${pkg.license}-License */`
22
+ : `/*!
23
+ * ColorPicker v${pkg.version} (${pkg.homepage})
24
+ * Copyright ${year} © ${pkg.author}
25
+ * Licensed under MIT (${pkg.license}/blob/main/LICENSE)
26
+ */`;
27
+
28
+ const DIR = args.DIR === "rtl" ? ".rtl" : "";
29
+ const MIN = args.MIN === "true" ? ".min" : "";
30
+ const INPUTFILE = args.INPUTFILE
31
+ ? args.INPUTFILE
32
+ : `./src/scss/color-picker${DIR}.scss`;
33
+ const OUTPUTFILE = args.OUTPUTFILE
34
+ ? args.OUTPUTFILE
35
+ : `./dist/css/color-picker${DIR}${MIN}.css`;
36
+ const COMPRESS = args.MIN === "true" ? "compressed" : "expanded";
37
+
38
+ // Helper Functions
39
+ function compile(inputPath, writePath, compressType) {
40
+ const result = sass.compile(inputPath, {
41
+ style: compressType,
42
+ loadPaths: ["src/scss"],
43
+ });
44
+ writeFileSync(writePath, `${banner}\n` + result.css.toString());
45
+ console.log(`✅ Compiled ${inputPath} to ${writePath}.`);
46
+ }
47
+
48
+ 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
+ });