@jamesrock/rockjs 1.34.0 → 1.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +72 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -33,10 +33,6 @@ export const roundTo = (number, to = 1) => (Math.round(number*to)/to);
|
|
|
33
33
|
export const ceilTo = (number, to = 1) => (Math.ceil(number*to)/to);
|
|
34
34
|
export const getXPercentOfY = (x, y) => (y*(x/100));
|
|
35
35
|
export const getXAsPercentOfY = (x, y) => ((x/y)*100);
|
|
36
|
-
// to be removed
|
|
37
|
-
export const formatMinutes = (ms) => pad(Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60)));
|
|
38
|
-
export const formatSeconds = (ms) => pad(Math.floor((ms % (1000 * 60)) / 1000));
|
|
39
|
-
export const formatTime = (ms) => `${formatMinutes(ms)}:${formatSeconds(ms)}`;
|
|
40
36
|
|
|
41
37
|
const sortingMethods = {
|
|
42
38
|
'0-9': (prop) => (a, b) => prop(a)-prop(b),
|
|
@@ -113,6 +109,23 @@ export const makeInput = (value = 0, type = 'number') => {
|
|
|
113
109
|
return input;
|
|
114
110
|
};
|
|
115
111
|
|
|
112
|
+
export const makeRadio = (value = 0, name = '{name}', id = '{id}', checked = false) => {
|
|
113
|
+
const node = makeInput(value, 'radio');
|
|
114
|
+
node.name = name;
|
|
115
|
+
node.id = id;
|
|
116
|
+
node.checked = checked;
|
|
117
|
+
return node;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const makeSlider = (value, min, max, step = 1) => {
|
|
121
|
+
const node = makeInput(0, 'range');
|
|
122
|
+
node.min = min;
|
|
123
|
+
node.max = max;
|
|
124
|
+
node.step = step;
|
|
125
|
+
node.value = value;
|
|
126
|
+
return node;
|
|
127
|
+
};
|
|
128
|
+
|
|
116
129
|
export const makeOutput = (rows = 7) => {
|
|
117
130
|
const node = makeNode('textarea');
|
|
118
131
|
node.rows = rows;
|
|
@@ -151,14 +164,6 @@ export const makeLink = (href = '{href}', label = '{label}', className) => {
|
|
|
151
164
|
return node;
|
|
152
165
|
};
|
|
153
166
|
|
|
154
|
-
export const makeRadio = (value = 0, name = '{name}', id = '{id}', checked = false) => {
|
|
155
|
-
const node = makeInput(value, 'radio');
|
|
156
|
-
node.name = name;
|
|
157
|
-
node.id = id;
|
|
158
|
-
node.checked = checked;
|
|
159
|
-
return node;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
167
|
export const makeLabel = (label = '{label}', id = '{id}', className) => {
|
|
163
168
|
const node = makeNode('label', className);
|
|
164
169
|
node.innerHTML = label;
|
|
@@ -262,6 +267,22 @@ export const addDragListeners = (target, tolerance) => {
|
|
|
262
267
|
|
|
263
268
|
};
|
|
264
269
|
|
|
270
|
+
export const append = (target) => {
|
|
271
|
+
const fn = (node) => {
|
|
272
|
+
target.appendChild(node);
|
|
273
|
+
return fn;
|
|
274
|
+
};
|
|
275
|
+
return fn;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export const appendTo = (target) => {
|
|
279
|
+
const fn = (node) => {
|
|
280
|
+
node.appendTo(target);
|
|
281
|
+
return fn;
|
|
282
|
+
};
|
|
283
|
+
return fn;
|
|
284
|
+
};
|
|
285
|
+
|
|
265
286
|
export class Storage {
|
|
266
287
|
constructor(namespace) {
|
|
267
288
|
|
|
@@ -667,10 +688,7 @@ export class Time {
|
|
|
667
688
|
getDaysInYear = (ms) => this.getDays(this.getMillisecondsInYear(ms));
|
|
668
689
|
getMinutesInHour = (ms) => this.getMinutes(this.getMillisecondsInHour(ms));
|
|
669
690
|
getSecondsInMinute = (ms) => this.getSeconds(this.getMillisecondsInMinute(ms));
|
|
670
|
-
|
|
671
|
-
formatMinutes = (ms) => pad(this.getMinutesInHour(ms));
|
|
672
|
-
formatHours = (ms) => pad(this.getHoursInDay(ms));
|
|
673
|
-
format = (ms) => `${this.formatMinutes(ms)}:${this.formatSeconds(ms)}`;
|
|
691
|
+
format = (ms) => `${pad(this.getMinutesInHour(ms))}:${pad(this.getSecondsInMinute(ms))}`;
|
|
674
692
|
};
|
|
675
693
|
|
|
676
694
|
export class PlayingCard extends DisplayObject {
|
|
@@ -846,13 +864,18 @@ export class SoundManager {
|
|
|
846
864
|
this.context = new AudioContext();
|
|
847
865
|
this.sounds = sounds;
|
|
848
866
|
this.buffers = {};
|
|
867
|
+
this.mixer = {};
|
|
868
|
+
this.keys = Object.keys(this.sounds);
|
|
869
|
+
|
|
870
|
+
this.listenForStateChange();
|
|
849
871
|
|
|
850
872
|
};
|
|
851
873
|
async load() {
|
|
852
874
|
|
|
853
|
-
return Promise.all(
|
|
875
|
+
return Promise.all(this.keys.map((key) => this.loadBuffer(key, this.sounds[key]))).then((items) => {
|
|
854
876
|
items.forEach(([name, buffer]) => {
|
|
855
877
|
this.buffers[name] = buffer;
|
|
878
|
+
this.mixer[name] = [0.5, 0];
|
|
856
879
|
});
|
|
857
880
|
});
|
|
858
881
|
|
|
@@ -873,11 +896,41 @@ export class SoundManager {
|
|
|
873
896
|
};
|
|
874
897
|
|
|
875
898
|
const source = this.context.createBufferSource();
|
|
899
|
+
const gainer = this.context.createGain();
|
|
900
|
+
const panner = this.context.createStereoPanner();
|
|
901
|
+
|
|
876
902
|
source.buffer = this.buffers[sound];
|
|
877
|
-
|
|
903
|
+
gainer.gain.value = this.mixer[sound][0];
|
|
904
|
+
panner.pan.value = this.mixer[sound][1];
|
|
905
|
+
|
|
906
|
+
source.connect(gainer).connect(panner).connect(this.context.destination);
|
|
907
|
+
|
|
878
908
|
source.start();
|
|
879
909
|
|
|
880
910
|
};
|
|
911
|
+
volume(sound, value) {
|
|
912
|
+
|
|
913
|
+
this.mixer[sound][0] = value;
|
|
914
|
+
return this;
|
|
915
|
+
|
|
916
|
+
};
|
|
917
|
+
pan(sound, value) {
|
|
918
|
+
|
|
919
|
+
this.mixer[sound][1] = value;
|
|
920
|
+
return this;
|
|
921
|
+
|
|
922
|
+
};
|
|
923
|
+
listenForStateChange() {
|
|
924
|
+
|
|
925
|
+
this.context.addEventListener('statechange', async () => {
|
|
926
|
+
if(this.context.state === 'suspended') {
|
|
927
|
+
await this.context.resume();
|
|
928
|
+
};
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
return this;
|
|
932
|
+
|
|
933
|
+
};
|
|
881
934
|
};
|
|
882
935
|
|
|
883
936
|
// temporary alias
|
|
@@ -892,3 +945,4 @@ export const createOption = makeOption;
|
|
|
892
945
|
export const createHeading = makeHeading;
|
|
893
946
|
export const createRadio = makeRadio;
|
|
894
947
|
export const createLabel = makeLabel;
|
|
948
|
+
export const formatTime = (ms) => new Time().format(ms);
|