瀏覽代碼

Added caption and subtitles colors

Dmitriy Slipak 4 年之前
父節點
當前提交
40ab6a9482
共有 6 個文件被更改,包括 175 次插入277 次删除
  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 查看文件

@@ -4,7 +4,8 @@ var d3 = require("d3"),
4 4
     minimap = require("./minimap.js"),
5 5
     sampleWave = require("./sample-wave.js"),
6 6
     getRenderer = require("../renderer/"),
7
-    getWaveform = require("./waveform.js");
7
+    getWaveform = require("./waveform.js"),
8
+    $ = require("jquery");
8 9
 
9 10
 var context = d3.select("canvas").node().getContext("2d");
10 11
 
@@ -15,6 +16,8 @@ var theme,
15 16
     newTheme,
16 17
     newCaption,
17 18
     subtitle;
19
+    // captionColorPicker,
20
+    // subtitleColorPicker;
18 21
 
19 22
 function _file(_) {
20 23
   return arguments.length ? (file = _) : file;
@@ -113,10 +116,145 @@ function redraw() {
113 116
       fontName = fontName.substring(1, fontName.length-1);
114 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 258
 function loadAudio(f, cb) {
121 259
 
122 260
   d3.queue()

+ 2 - 8
client/theme-editor.js 查看文件

@@ -2,8 +2,7 @@ var d3 = require("d3"),
2 2
     $ = require("jquery"),
3 3
     preview = require("./preview.js"),
4 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 7
 function _initialize() {
9 8
     d3.select("#btn-new-theme").on("click", uploadTheme);
@@ -22,10 +21,6 @@ function _initialize() {
22 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 26
 function setClass(cl, msg) {
@@ -182,7 +177,7 @@ function saveTheme() {
182 177
       preview.theme(theme);
183 178
     },
184 179
     error: function (error) {
185
-      console.log('error', error);
180
+      // console.log('error', error);
186 181
     }
187 182
   });
188 183
 
@@ -198,7 +193,6 @@ function setNoPattern() {
198 193
   } else {
199 194
     theme.noPattern = checked;
200 195
   }
201
-
202 196
   saveTheme();
203 197
 }
204 198
 

+ 10 - 9
editor/theme.html 查看文件

@@ -11,6 +11,9 @@
11 11
     <link href="/css/base.css" rel="stylesheet" type="text/css">
12 12
     <link href="/css/editor.css" rel="stylesheet" type="text/css">
13 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 17
   </head>
15 18
   <body class="loading">
16 19
 
@@ -74,23 +77,21 @@
74 77
         </div>
75 78
 
76 79
         <div class="row form-row">
80
+          <div style="padding-bottom: 7px">No pattern</div>
77 81
           <input type="checkbox" class="form-check-input" id="chkNoPattern">
78
-          <label class="form-check-label" for="chkNoPattern">No pattern</label>
79 82
         </div>
80 83
 
81 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 88
           </div>
87 89
         </div>
88 90
 
89 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 95
           </div>
95 96
         </div>
96 97
 

+ 22 - 9
package-lock.json 查看文件

@@ -4,6 +4,15 @@
4 4
   "lockfileVersion": 1,
5 5
   "requires": true,
6 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 16
     "JSONStream": {
8 17
       "version": "1.3.5",
9 18
       "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
@@ -13,14 +22,6 @@
13 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 25
     "abbrev": {
25 26
       "version": "1.1.1",
26 27
       "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@@ -1024,6 +1025,11 @@
1024 1025
       "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=",
1025 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 1033
     "core-util-is": {
1028 1034
       "version": "1.0.2",
1029 1035
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
@@ -3129,6 +3135,7 @@
3129 3135
       "version": "2.0.4",
3130 3136
       "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
3131 3137
       "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
3138
+      "dev": true,
3132 3139
       "requires": {
3133 3140
         "isobject": "^3.0.1"
3134 3141
       }
@@ -3189,7 +3196,8 @@
3189 3196
     "isobject": {
3190 3197
       "version": "3.0.1",
3191 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 3202
     "isstream": {
3195 3203
       "version": "0.1.2",
@@ -3542,6 +3550,11 @@
3542 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 3558
     "needle": {
3546 3559
       "version": "2.4.0",
3547 3560
       "resolved": "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz",

+ 1 - 1
package.json 查看文件

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

文件差異過大導致無法顯示
+ 1 - 249
settings/themes.json