(e)
| 36 | } |
| 37 | |
| 38 | function bulkItemConvertColorInput(e) { |
| 39 | let background = document.getElementById('bulkConvertBackground').value; |
| 40 | let bulkInputs = document.getElementById('bulkConvertColors'); |
| 41 | let bulkValues = bulkInputs.value.replace(/\r\n/g, '\n').replace(/[,\/]/g, '\n').replace(' ', '').replace(/['\/]/g, '').replace(/["\/]/g, '').replace(' ', '').split('\n'); |
| 42 | bulkValues = bulkValues.map((value) => { |
| 43 | return value.replace(' ', ''); |
| 44 | }); |
| 45 | for (let i = 0; i < bulkValues.length; i++) { |
| 46 | // console.log(bulkValues[i]) |
| 47 | if (!bulkValues[i].startsWith('#')) { |
| 48 | bulkValues[i] = '#' + bulkValues[i]; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | let opts = ['HEX']; // By default, always include hex |
| 53 | let checkboxes = document.getElementsByClassName('convertBulkColorspace'); |
| 54 | for (let i = 0; i < checkboxes.length; i++) { |
| 55 | if (checkboxes[i].checked) opts.push(checkboxes[i].id.replace('checkboxConvert-', '')); |
| 56 | } |
| 57 | |
| 58 | let colors = []; |
| 59 | // add key colors for each input |
| 60 | for (let i = 0; i < bulkValues.length; i++) { |
| 61 | console.log(bulkValues[i]); |
| 62 | let colorVal = chroma(bulkValues[i]).hex(); //d3.color(bulkValues[i]).formatHex() |
| 63 | colors.push(colorVal); |
| 64 | } |
| 65 | |
| 66 | let data = []; |
| 67 | colors.map((c) => { |
| 68 | data.push(createColorJson(c, opts, background)); |
| 69 | }); |
| 70 | |
| 71 | const replacer = (key, value) => (value === null ? '' : value); // specify how you want to handle null values here |
| 72 | const header = Object.keys(data[0]); |
| 73 | const csv = [ |
| 74 | header.join(','), // header row first |
| 75 | ...data.map((row) => header.map((fieldName) => JSON.stringify(row[fieldName], replacer)).join(',')) |
| 76 | ].join('\r\n'); |
| 77 | |
| 78 | // console.log(csv) |
| 79 | |
| 80 | const csvData = Promise.resolve(csv); |
| 81 | |
| 82 | csvData.then((file) => { |
| 83 | let filename = `converted_colors.csv`; |
| 84 | var blob = new Blob([`${file}`], {type: 'text/plain'}); |
| 85 | |
| 86 | saveAs(blob, filename); |
| 87 | }); |
| 88 | |
| 89 | cancelBulkConvert(); |
| 90 | |
| 91 | bulkInputs.value = ' '; |
| 92 | } |
| 93 | |
| 94 | function createColorJson(value, colorSpaces, background) { |
| 95 | if (!chroma.valid(value)) { |
nothing calls this directly
no test coverage detected