Browse Source

Added caption and subtitles colors

Dmitriy Slipak 4 years ago
parent
commit
40ab6a9482
6 changed files with 175 additions and 277 deletions
  1. 139 1
      client/preview.js
  2. 2 8
      client/theme-editor.js
  3. 10 9
      editor/theme.html
  4. 22 9
      package-lock.json
  5. 1 1
      package.json
  6. 1 249
      settings/themes.json

+ 139 - 1
client/preview.js View File

4
     minimap = require("./minimap.js"),
4
     minimap = require("./minimap.js"),
5
     sampleWave = require("./sample-wave.js"),
5
     sampleWave = require("./sample-wave.js"),
6
     getRenderer = require("../renderer/"),
6
     getRenderer = require("../renderer/"),
7
-    getWaveform = require("./waveform.js");
7
+    getWaveform = require("./waveform.js"),
8
+    $ = require("jquery");
8
 
9
 
9
 var context = d3.select("canvas").node().getContext("2d");
10
 var context = d3.select("canvas").node().getContext("2d");
10
 
11
 
15
     newTheme,
16
     newTheme,
16
     newCaption,
17
     newCaption,
17
     subtitle;
18
     subtitle;
19
+    // captionColorPicker,
20
+    // subtitleColorPicker;
18
 
21
 
19
 function _file(_) {
22
 function _file(_) {
20
   return arguments.length ? (file = _) : file;
23
   return arguments.length ? (file = _) : file;
113
       fontName = fontName.substring(1, fontName.length-1);
116
       fontName = fontName.substring(1, fontName.length-1);
114
       d3.select("#input-font").property("value", fontName);
117
       d3.select("#input-font").property("value", fontName);
115
     }
118
     }
119
+    
120
+    const captionColor = (theme.captionColor === undefined) ? "#000" : theme.captionColor;
121
+    const subtitleColor = (theme.subtitleColor === undefined) ? "#000" : theme.subtitleColor;
122
+    
123
+    var container = document.querySelector(".captionColorPicker");
124
+
125
+    if (container.hasChildNodes()) {
126
+      while (container.firstChild) {
127
+        container.removeChild(container.firstChild);
128
+      }
129
+    }
130
+    var newElement = document.createElement('div');
131
+    container.appendChild(newElement);
132
+
133
+    var captionColorPicker = new Pickr({
134
+      el: newElement,
135
+      default: captionColor ? captionColor : '#fff',
136
+      theme: 'nano',
137
+      lockOpacity: true,
138
+
139
+      swatches: [
140
+        'rgba(244, 67, 54, 1)',
141
+        'rgba(233, 30, 99, 0.95)',
142
+        'rgba(156, 39, 176, 0.9)',
143
+        'rgba(103, 58, 183, 0.85)',
144
+        'rgba(63, 81, 181, 0.8)',
145
+        'rgba(33, 150, 243, 0.75)',
146
+        'rgba(3, 169, 244, 0.7)',
147
+        'rgba(0, 188, 212, 0.7)',
148
+        'rgba(0, 150, 136, 0.75)',
149
+        'rgba(76, 175, 80, 0.8)',
150
+        'rgba(139, 195, 74, 0.85)',
151
+        'rgba(205, 220, 57, 0.9)',
152
+        'rgba(255, 235, 59, 0.95)',
153
+        'rgba(255, 193, 7, 1)'
154
+      ],
155
+
156
+      components: {
157
+        preview: true,
158
+        opacity: true,
159
+        hue: true,
160
+
161
+        interaction: {
162
+          hex: true,
163
+          rgba: true,
164
+          hsva: true,
165
+          input: true,
166
+          clear: true,
167
+          save: true
168
+        }
169
+      }
170
+    });
171
+
172
+    captionColorPicker.on('save', (color, instance) => {
173
+      if (theme.captionColor) {
174
+        theme.captionColor = color.toHEXA().toString();
175
+      } else {
176
+        theme['captionColor'] = color.toHEXA().toString();
177
+      }
178
+      saveTheme();
179
+    });
180
+
181
+    container = document.querySelector(".subtitleColorPicker");
182
+
183
+    if (container.hasChildNodes()) {
184
+      while (container.firstChild) {
185
+        container.removeChild(container.firstChild);
186
+      }
187
+    }
188
+    newElement = document.createElement('div');
189
+    container.appendChild(newElement);
190
+
191
+    var subtitleColorPicker = new Pickr({
192
+      el: newElement,
193
+      default: subtitleColor ? subtitleColor : '#fff',
194
+      theme: 'nano',
195
+      lockOpacity: true,
196
+
197
+      swatches: [
198
+        'rgba(244, 67, 54, 1)',
199
+        'rgba(233, 30, 99, 0.95)',
200
+        'rgba(156, 39, 176, 0.9)',
201
+        'rgba(103, 58, 183, 0.85)',
202
+        'rgba(63, 81, 181, 0.8)',
203
+        'rgba(33, 150, 243, 0.75)',
204
+        'rgba(3, 169, 244, 0.7)',
205
+        'rgba(0, 188, 212, 0.7)',
206
+        'rgba(0, 150, 136, 0.75)',
207
+        'rgba(76, 175, 80, 0.8)',
208
+        'rgba(139, 195, 74, 0.85)',
209
+        'rgba(205, 220, 57, 0.9)',
210
+        'rgba(255, 235, 59, 0.95)',
211
+        'rgba(255, 193, 7, 1)'
212
+      ],
213
+
214
+      components: {
215
+        preview: true,
216
+        opacity: true,
217
+        hue: true,
218
+
219
+        interaction: {
220
+          hex: true,
221
+          rgba: true,
222
+          hsva: true,
223
+          input: true,
224
+          clear: true,
225
+          save: true
226
+        }
227
+      }
228
+    });
229
+
230
+    subtitleColorPicker.on('save', (color, instance) => {
231
+      if (theme.captionColor) {
232
+        theme.subtitleColor = color.toHEXA().toString();
233
+      } else {
234
+        theme['subtitleColor'] = color.toHEXA().toString();
235
+      }
236
+      saveTheme();
237
+    });
238
+
116
   }
239
   }
117
 
240
 
118
 }
241
 }
119
 
242
 
243
+function saveTheme() {
244
+  $.ajax({
245
+    url: "/theme/save",
246
+    type: "POST",
247
+    data: JSON.stringify({theme: theme}),
248
+    dataType: "json",
249
+    contentType: "application/json",
250
+    cache: false,
251
+    error: function (error) {
252
+      console.log('error', error);
253
+    }
254
+  });
255
+
256
+}
257
+
120
 function loadAudio(f, cb) {
258
 function loadAudio(f, cb) {
121
 
259
 
122
   d3.queue()
260
   d3.queue()

+ 2 - 8
client/theme-editor.js View File

2
     $ = require("jquery"),
2
     $ = require("jquery"),
3
     preview = require("./preview.js"),
3
     preview = require("./preview.js"),
4
     fonts = [{name: "Neue Haas Grotesk Text Pro"},
4
     fonts = [{name: "Neue Haas Grotesk Text Pro"},
5
-      {name: "Source Sans Pro"}],
6
-    AColorPicker = require("a-color-picker");
5
+      {name: "Source Sans Pro"}];
7
 
6
 
8
 function _initialize() {
7
 function _initialize() {
9
     d3.select("#btn-new-theme").on("click", uploadTheme);
8
     d3.select("#btn-new-theme").on("click", uploadTheme);
22
         return d.name;
21
         return d.name;
23
       });
22
       });
24
 
23
 
25
-    AColorPicker.from('.picker')
26
-    .on('change', (picker, color) => {
27
-      console.log(color);
28
-    });
29
 }
24
 }
30
 
25
 
31
 function setClass(cl, msg) {
26
 function setClass(cl, msg) {
182
       preview.theme(theme);
177
       preview.theme(theme);
183
     },
178
     },
184
     error: function (error) {
179
     error: function (error) {
185
-      console.log('error', error);
180
+      // console.log('error', error);
186
     }
181
     }
187
   });
182
   });
188
 
183
 
198
   } else {
193
   } else {
199
     theme.noPattern = checked;
194
     theme.noPattern = checked;
200
   }
195
   }
201
-
202
   saveTheme();
196
   saveTheme();
203
 }
197
 }
204
 
198
 

+ 10 - 9
editor/theme.html View File

11
     <link href="/css/base.css" rel="stylesheet" type="text/css">
11
     <link href="/css/base.css" rel="stylesheet" type="text/css">
12
     <link href="/css/editor.css" rel="stylesheet" type="text/css">
12
     <link href="/css/editor.css" rel="stylesheet" type="text/css">
13
     <link href="/fonts/fonts.css" rel="stylesheet" type="text/css">
13
     <link href="/fonts/fonts.css" rel="stylesheet" type="text/css">
14
+    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/nano.min.css"/>
15
+    <script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.min.js"></script>
16
+    <script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.es5.min.js"></script>
14
   </head>
17
   </head>
15
   <body class="loading">
18
   <body class="loading">
16
 
19
 
74
         </div>
77
         </div>
75
 
78
 
76
         <div class="row form-row">
79
         <div class="row form-row">
80
+          <div style="padding-bottom: 7px">No pattern</div>
77
           <input type="checkbox" class="form-check-input" id="chkNoPattern">
81
           <input type="checkbox" class="form-check-input" id="chkNoPattern">
78
-          <label class="form-check-label" for="chkNoPattern">No pattern</label>
79
         </div>
82
         </div>
80
 
83
 
81
         <div class="row form-row">
84
         <div class="row form-row">
82
-          <label for="captionColor">
83
-            Caption color
84
-          </label>
85
-          <div class="picker" acp-color="#EFE9E7" id="captionColor" name="captionColor">
85
+          <div style="padding-bottom: 10px">Caption color</div>
86
+          <div style="border: thin solid; max-width: 40px">
87
+            <div class="captionColorPicker"></div>
86
           </div>
88
           </div>
87
         </div>
89
         </div>
88
 
90
 
89
         <div class="row form-row">
91
         <div class="row form-row">
90
-          <label for="captionColor">
91
-            Subtitle color
92
-          </label>
93
-          <div class="picker" acp-color="#EFE9E7" id="subtitleColor" name="subtitleColor">
92
+          <div style="padding-bottom: 10px">Subtitle color</div>
93
+          <div style="border: thin solid; max-width: 40px">
94
+            <div class="subtitleColorPicker"></div>
94
           </div>
95
           </div>
95
         </div>
96
         </div>
96
 
97
 

+ 22 - 9
package-lock.json View File

4
   "lockfileVersion": 1,
4
   "lockfileVersion": 1,
5
   "requires": true,
5
   "requires": true,
6
   "dependencies": {
6
   "dependencies": {
7
+    "@simonwep/pickr": {
8
+      "version": "1.7.4",
9
+      "resolved": "https://registry.npmjs.org/@simonwep/pickr/-/pickr-1.7.4.tgz",
10
+      "integrity": "sha512-fq7jgKJT21uWGC1mARBHvvd1JYlEf93o7SuVOB4Lr0x/2UPuNC9Oe9n/GzVeg4oVtqMDfh1wIEJpsdOJEZb+3g==",
11
+      "requires": {
12
+        "core-js": "^3.6.5",
13
+        "nanopop": "^2.1.0"
14
+      }
15
+    },
7
     "JSONStream": {
16
     "JSONStream": {
8
       "version": "1.3.5",
17
       "version": "1.3.5",
9
       "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
18
       "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
13
         "through": ">=2.2.7 <3"
22
         "through": ">=2.2.7 <3"
14
       }
23
       }
15
     },
24
     },
16
-    "a-color-picker": {
17
-      "version": "1.2.1",
18
-      "resolved": "https://registry.npmjs.org/a-color-picker/-/a-color-picker-1.2.1.tgz",
19
-      "integrity": "sha512-aMCUKd2zTDWK2YWnjz0k3YhFc9XL0jZlPIywF6XkP6i3wdq2iHTEnl1BFPZkOVDV89M12t+zeZ8m23cfzn57/Q==",
20
-      "requires": {
21
-        "is-plain-object": "^2.0.4"
22
-      }
23
-    },
24
     "abbrev": {
25
     "abbrev": {
25
       "version": "1.1.1",
26
       "version": "1.1.1",
26
       "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
27
       "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
1024
       "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=",
1025
       "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=",
1025
       "dev": true
1026
       "dev": true
1026
     },
1027
     },
1028
+    "core-js": {
1029
+      "version": "3.6.5",
1030
+      "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz",
1031
+      "integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA=="
1032
+    },
1027
     "core-util-is": {
1033
     "core-util-is": {
1028
       "version": "1.0.2",
1034
       "version": "1.0.2",
1029
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
1035
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
3129
       "version": "2.0.4",
3135
       "version": "2.0.4",
3130
       "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
3136
       "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
3131
       "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
3137
       "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
3138
+      "dev": true,
3132
       "requires": {
3139
       "requires": {
3133
         "isobject": "^3.0.1"
3140
         "isobject": "^3.0.1"
3134
       }
3141
       }
3189
     "isobject": {
3196
     "isobject": {
3190
       "version": "3.0.1",
3197
       "version": "3.0.1",
3191
       "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
3198
       "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
3192
-      "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8="
3199
+      "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=",
3200
+      "dev": true
3193
     },
3201
     },
3194
     "isstream": {
3202
     "isstream": {
3195
       "version": "0.1.2",
3203
       "version": "0.1.2",
3542
         "to-regex": "^3.0.1"
3550
         "to-regex": "^3.0.1"
3543
       }
3551
       }
3544
     },
3552
     },
3553
+    "nanopop": {
3554
+      "version": "2.1.0",
3555
+      "resolved": "https://registry.npmjs.org/nanopop/-/nanopop-2.1.0.tgz",
3556
+      "integrity": "sha512-jGTwpFRexSH+fxappnGQtN9dspgE2ipa1aOjtR24igG0pv6JCxImIAmrLRHX+zUF5+1wtsFVbKyfP51kIGAVNw=="
3557
+    },
3545
     "needle": {
3558
     "needle": {
3546
       "version": "2.4.0",
3559
       "version": "2.4.0",
3547
       "resolved": "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz",
3560
       "resolved": "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz",

+ 1 - 1
package.json View File

24
   },
24
   },
25
   "license": "MIT",
25
   "license": "MIT",
26
   "dependencies": {
26
   "dependencies": {
27
-    "a-color-picker": "^1.2.1",
27
+    "@simonwep/pickr": "^1.7.4",
28
     "aws-sdk": "^2.2.39",
28
     "aws-sdk": "^2.2.39",
29
     "browserify": "^13.0.0",
29
     "browserify": "^13.0.0",
30
     "canvas": "^2.6.1",
30
     "canvas": "^2.6.1",

File diff suppressed because it is too large
+ 1 - 249
settings/themes.json