hive-swarm 2.0.0 → 2.1.1

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/hive-bees.js CHANGED
@@ -1,64 +1,110 @@
1
- (() => {
2
- 'use strict';
3
- const palette=[
4
- ['#efac37','#ffe18d','#bb641d'],
5
- ['#75baef','#cdefff','#3974bb'],
6
- ['#55cbb2','#b8f8df','#268c7d'],
7
- ['#e68db3','#ffcee2','#a24275'],
8
- ['#b3ce64','#e9f6a1','#6c9137'],
9
- ['#ad9ce8','#e3d4ff','#6d58af'],
10
- ['#f09a71','#ffd3b7','#af5833'],
11
- ['#95cbd1','#defbfa','#4a8d9d'],
12
- ['#d1a76a','#ffe2a9','#987044'],
13
- ];
14
-
15
- function colors(name,coordinator,tint) {
16
- if (coordinator) return palette[0];
17
- if (Number.isInteger(tint)) return palette[1+tint%(palette.length-1)];
18
- const hash=[...name].reduce((sum,letter)=>sum*31+letter.charCodeAt(0),0)>>>0;
19
- return palette[hash%palette.length];
20
- }
21
-
22
- function sprite(name,{status='working',coordinator=false,tint}={}) {
23
- const canvas=document.createElement('canvas');
24
- canvas.className='bee-pixel';
25
- canvas.width=20;
26
- canvas.height=18;
27
- canvas.setAttribute('aria-hidden','true');
28
- const [base,highlight,shade]=colors(name,coordinator,tint);
29
- const asleep=['waiting','quota','retired','done'].includes(status);
30
- canvas.dataset.pose=asleep?'sleeping':'awake';
31
- const ctx=canvas.getContext('2d');
32
- const paint=(color,rects)=>{
33
- ctx.fillStyle=color;
34
- for (const rect of rects) ctx.fillRect(...rect);
35
- };
36
- paint('#201915',[[3,2,1,3],[6,3,1,2],[5,1,2,1],[2,3,1,1],[5,5,10,8],[3,7,13,5],
37
- [4,12,11,2],[6,14,7,1],[16,9,2,2],[7,14,1,2],[12,14,1,2]]);
38
- paint('#24313d',[[7,3,6,4],[8,2,4,6],[12,3,4,4],[13,2,2,1]]);
39
- paint('#a9c6db',[[8,3,3,4],[12,4,3,2],[9,7,2,1]]);
40
- paint('#e7f2fa',[[9,3,2,2],[12,4,2,1],[8,4,1,2]]);
41
- paint(base,[[4,7,8,5],[5,6,6,7],[12,7,3,5],[13,12,1,1],[6,13,1,1]]);
42
- paint(highlight,[[5,7,3,1],[4,9,2,2],[10,7,2,1],[13,8,1,2],[5,12,2,1]]);
43
- paint(shade,[[6,12,7,1],[12,11,3,1],[13,12,1,1]]);
44
- paint('#2c221c',[[8,6,2,7],[12,7,1,6],[15,9,2,1]]);
45
- if (asleep) {
46
- paint('#201915',[[4,10,2,1]]);
47
- paint('#d7dcff',coordinator
48
- ? [[0,0,2,1],[1,1,1,1],[0,2,2,1],[15,0,4,1],[17,1,1,2],[15,3,4,1]]
49
- : [[1,1,3,1],[2,2,1,1],[1,3,3,1],[15,0,4,1],[17,1,1,2],[15,3,4,1]]);
50
- } else {
51
- paint('#201915',[[5,8,1,2]]);
52
- paint('#fff6d7',[[5,8,1,1]]);
53
- }
54
- if (coordinator) {
55
- paint('#6d4219',[[2,1,1,4],[8,1,1,4],[2,4,7,1]]);
56
- paint('#ffd86b',[[2,0,1,2],[5,0,1,3],[8,0,1,2],[3,2,5,2],[4,1,3,1]]);
57
- paint('#e7a52f',[[3,4,5,1],[3,3,5,1]]);
58
- paint('#fff3bf',[[3,2,1,1],[7,2,1,1],[5,3,1,1]]);
59
- }
60
- return canvas;
61
- }
62
-
63
- globalThis.HiveBee=Object.freeze({sprite,colors});
64
- })();
1
+ (() => {
2
+ 'use strict';
3
+ const palette = [
4
+ ['#efac37', '#ffe18d', '#bb641d'],
5
+ ['#75baef', '#cdefff', '#3974bb'],
6
+ ['#55cbb2', '#b8f8df', '#268c7d'],
7
+ ['#e68db3', '#ffcee2', '#a24275'],
8
+ ['#b3ce64', '#e9f6a1', '#6c9137'],
9
+ ['#ad9ce8', '#e3d4ff', '#6d58af'],
10
+ ['#f09a71', '#ffd3b7', '#af5833'],
11
+ ['#95cbd1', '#defbfa', '#4a8d9d'],
12
+ ['#d1a76a', '#ffe2a9', '#987044'],
13
+ ];
14
+
15
+ const mutedPalette = ['#aaafb6', '#d6dae0', '#848991'];
16
+
17
+ function colors(name, coordinator, tint) {
18
+ if (coordinator) return palette[0];
19
+ if (Number.isInteger(tint)) return palette[1 + (Math.abs(tint) % (palette.length - 1))];
20
+ const hash = [...String(name ?? '')].reduce((sum, letter) => sum * 31 + letter.charCodeAt(0), 0) >>> 0;
21
+ return palette[hash % palette.length];
22
+ }
23
+
24
+ function hexRgb(hex) {
25
+ const clean = String(hex).replace('#', '');
26
+ const value = Number.parseInt(clean, 16);
27
+ return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
28
+ }
29
+
30
+ function tintStyle(name, coordinator, tint) {
31
+ const [base, highlight, shade] = colors(name, coordinator, tint);
32
+ const [r, g, b] = hexRgb(base);
33
+ const [sr, sg, sb] = hexRgb(shade);
34
+ const tr = Math.round(sr * 0.78);
35
+ const tg = Math.round(sg * 0.78);
36
+ const tb = Math.round(sb * 0.78);
37
+ const text = '#' + [tr, tg, tb].map(c => c.toString(16).padStart(2, '0')).join('');
38
+ return {
39
+ base,
40
+ highlight,
41
+ shade,
42
+ bg: `rgba(${r}, ${g}, ${b}, 0.14)`,
43
+ border: `rgba(${r}, ${g}, ${b}, 0.42)`,
44
+ text,
45
+ };
46
+ }
47
+
48
+ function paintRects(ctx, color, rects, ox = 0, oy = 0, scale = 1) {
49
+ ctx.fillStyle = color;
50
+ for (const [rx, ry, rw, rh] of rects) {
51
+ if (ox === 0 && oy === 0 && scale === 1) ctx.fillRect(rx, ry, rw, rh);
52
+ else ctx.fillRect(ox + rx * scale, oy + ry * scale, rw * scale, rh * scale);
53
+ }
54
+ }
55
+
56
+ function drawSprite(ctx, x, y, name, { status = 'working', coordinator = false, tint, muted = false, scale = 1 } = {}) {
57
+ if (!ctx) return;
58
+ const [base, highlight, shade] = muted ? mutedPalette : colors(name, coordinator, tint);
59
+ const asleep = !muted && ['waiting', 'quota', 'retired', 'done'].includes(status);
60
+
61
+ const outline = muted ? '#727880' : '#201915';
62
+ const wingRim = muted ? '#828a94' : '#24313d';
63
+ const wingFill = muted ? '#ced3d9' : '#a9c6db';
64
+ const wingLight = muted ? '#eef1f4' : '#e7f2fa';
65
+ const stripe = muted ? '#767c84' : '#2c221c';
66
+
67
+ paintRects(ctx, outline, [[3, 2, 1, 3], [6, 3, 1, 2], [5, 1, 2, 1], [2, 3, 1, 1], [5, 5, 10, 8], [3, 7, 13, 5],
68
+ [4, 12, 11, 2], [6, 14, 7, 1], [16, 9, 2, 2], [7, 14, 1, 2], [12, 14, 1, 2]], x, y, scale);
69
+ paintRects(ctx, wingRim, [[7, 3, 6, 4], [8, 2, 4, 6], [12, 3, 4, 4], [13, 2, 2, 1]], x, y, scale);
70
+ paintRects(ctx, wingFill, [[8, 3, 3, 4], [12, 4, 3, 2], [9, 7, 2, 1]], x, y, scale);
71
+ paintRects(ctx, wingLight, [[9, 3, 2, 2], [12, 4, 2, 1], [8, 4, 1, 2]], x, y, scale);
72
+ paintRects(ctx, base, [[4, 7, 8, 5], [5, 6, 6, 7], [12, 7, 3, 5], [13, 12, 1, 1], [6, 13, 1, 1]], x, y, scale);
73
+ paintRects(ctx, highlight, [[5, 7, 3, 1], [4, 9, 2, 2], [10, 7, 2, 1], [13, 8, 1, 2], [5, 12, 2, 1]], x, y, scale);
74
+ paintRects(ctx, shade, [[6, 12, 7, 1], [12, 11, 3, 1], [13, 12, 1, 1]], x, y, scale);
75
+ paintRects(ctx, stripe, [[8, 6, 2, 7], [12, 7, 1, 6], [15, 9, 2, 1]], x, y, scale);
76
+
77
+ if (asleep) {
78
+ paintRects(ctx, outline, [[4, 10, 2, 1]], x, y, scale);
79
+ paintRects(ctx, '#d7dcff', coordinator
80
+ ? [[0, 0, 2, 1], [1, 1, 1, 1], [0, 2, 2, 1], [15, 0, 4, 1], [17, 1, 1, 2], [15, 3, 4, 1]]
81
+ : [[1, 1, 3, 1], [2, 2, 1, 1], [1, 3, 3, 1], [15, 0, 4, 1], [17, 1, 1, 2], [15, 3, 4, 1]], x, y, scale);
82
+ } else {
83
+ paintRects(ctx, muted ? '#555b63' : '#201915', [[5, 8, 1, 2]], x, y, scale);
84
+ paintRects(ctx, muted ? '#e5e8ec' : '#fff6d7', [[5, 8, 1, 1]], x, y, scale);
85
+ }
86
+
87
+ if (coordinator) {
88
+ paintRects(ctx, muted ? '#727880' : '#6d4219', [[2, 1, 1, 4], [8, 1, 1, 4], [2, 4, 7, 1]], x, y, scale);
89
+ paintRects(ctx, muted ? '#c7cbd1' : '#ffd86b', [[2, 0, 1, 2], [5, 0, 1, 3], [8, 0, 1, 2], [3, 2, 5, 2], [4, 1, 3, 1]], x, y, scale);
90
+ paintRects(ctx, muted ? '#9da3ab' : '#e7a52f', [[3, 4, 5, 1], [3, 3, 5, 1]], x, y, scale);
91
+ paintRects(ctx, muted ? '#eceef1' : '#fff3bf', [[3, 2, 1, 1], [7, 2, 1, 1], [5, 3, 1, 1]], x, y, scale);
92
+ }
93
+ }
94
+
95
+ function sprite(name, { status = 'working', coordinator = false, tint, muted = false } = {}) {
96
+ const canvas = document.createElement('canvas');
97
+ canvas.className = 'bee-pixel';
98
+ canvas.width = 20;
99
+ canvas.height = 18;
100
+ canvas.setAttribute('aria-hidden', 'true');
101
+ const asleep = !muted && ['waiting', 'quota', 'retired', 'done'].includes(status);
102
+ canvas.dataset.pose = muted ? 'muted' : (asleep ? 'sleeping' : 'awake');
103
+ if (muted) canvas.dataset.muted = 'true';
104
+ const ctx = canvas.getContext('2d');
105
+ drawSprite(ctx, 0, 0, name, { status, coordinator, tint, muted, scale: 1 });
106
+ return canvas;
107
+ }
108
+
109
+ globalThis.HiveBee = Object.freeze({ sprite, colors, tintStyle, drawSprite });
110
+ })();