@jamesrock/rockjs 1.9.0 → 1.10.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 +31 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -74,13 +74,37 @@ export const createSelect = (options) => {
|
|
|
74
74
|
return node;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const createOption = (label = '{label}', value = 0) => {
|
|
77
|
+
export const createOption = (label = '{label}', value = 0) => {
|
|
78
78
|
const node = createNode('option');
|
|
79
79
|
node.innerText = label;
|
|
80
80
|
node.value = value;
|
|
81
81
|
return node;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
export const makeBitArray = (size) => {
|
|
85
|
+
let bob = 2**size;
|
|
86
|
+
return makeArray(size, () => {
|
|
87
|
+
bob = bob/2;
|
|
88
|
+
return bob;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const makeHexMap = (full = true) => {
|
|
93
|
+
const out = [];
|
|
94
|
+
const hexMap = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
|
95
|
+
if(full) {
|
|
96
|
+
makeArray(hexMap.length).forEach((x) => {
|
|
97
|
+
makeArray(hexMap.length).forEach((y) => {
|
|
98
|
+
out.push(`${hexMap[x]}${hexMap[y]}`);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return hexMap;
|
|
104
|
+
};
|
|
105
|
+
return out;
|
|
106
|
+
};
|
|
107
|
+
|
|
84
108
|
export class Storage {
|
|
85
109
|
constructor(namespace) {
|
|
86
110
|
|
|
@@ -247,7 +271,11 @@ export class BrickMaker extends DisplayObject {
|
|
|
247
271
|
const bob = 30;
|
|
248
272
|
const gap = 1;
|
|
249
273
|
const bits = [];
|
|
250
|
-
const hexMap =
|
|
274
|
+
const hexMap = size*size > 16 ? makeHexMap() : makeHexMap(false);
|
|
275
|
+
const typeValues = {
|
|
276
|
+
'digits': makeArray(size*size, () => 1),
|
|
277
|
+
'binary': makeBitArray(size)
|
|
278
|
+
};
|
|
251
279
|
|
|
252
280
|
const calculate = () => {
|
|
253
281
|
let total = null;
|
|
@@ -290,7 +318,7 @@ export class BrickMaker extends DisplayObject {
|
|
|
290
318
|
bit.style.width = bit.style.height = `${bob}px`;
|
|
291
319
|
bit.dataset.x = x;
|
|
292
320
|
bit.dataset.y = y;
|
|
293
|
-
bit.dataset.value =
|
|
321
|
+
bit.dataset.value = typeValues[this.type][x];
|
|
294
322
|
bit.dataset.active = 'N';
|
|
295
323
|
node.appendChild(bit);
|
|
296
324
|
|
|
@@ -306,9 +334,5 @@ export class BrickMaker extends DisplayObject {
|
|
|
306
334
|
});
|
|
307
335
|
|
|
308
336
|
};
|
|
309
|
-
typeValues = {
|
|
310
|
-
'digits': makeArray(16, () => 1),
|
|
311
|
-
'binary': [8, 4, 2, 1]
|
|
312
|
-
};
|
|
313
337
|
value = null;
|
|
314
338
|
};
|