@nebularstreams/libmui 2.0.16 → 2.0.18
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/dist/libui.esm.js +1 -1
- package/dist/libui.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +5 -1
- package/src/util/tainter.js +8 -0
- package/src/widgets/ColorJoePack.js +108 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import ComboWidget from "./widgets/ComboWidget";
|
|
|
9
9
|
import ComboPrompt from "./widgets/ComboPrompt";
|
|
10
10
|
import SwitchWidget from "./widgets/SwitchWidget";
|
|
11
11
|
import ColorJoeWidget from "./widgets/ColorJoeWidget";
|
|
12
|
+
import ColorJoePack from "./widgets/ColorJoePack";
|
|
12
13
|
import * as OverflowUtils from "./widgets/OverflowUtils";
|
|
13
14
|
import {clearModal, popupMessage} from "./util/widgets";
|
|
14
15
|
import Separator from "./widgets/Separator";
|
|
@@ -26,6 +27,7 @@ import clone from "./util/util.clone"
|
|
|
26
27
|
import Tokenizer from "./util/util.tokenizer"
|
|
27
28
|
import {CoolContentTicker, CoolGenericTicker, GenericButtonTicker, optionsPrompt} from "./widgets/CoolContentTicker";
|
|
28
29
|
import EmptyButton from "./widgets/EmptyButton";
|
|
30
|
+
import tainter from "./util/tainter"
|
|
29
31
|
|
|
30
32
|
import {
|
|
31
33
|
VideoUploadButton,
|
|
@@ -49,6 +51,7 @@ export {
|
|
|
49
51
|
ButtonNew,
|
|
50
52
|
CardieWidget,
|
|
51
53
|
ColorJoeWidget,
|
|
54
|
+
ColorJoePack,
|
|
52
55
|
ComboPrompt,
|
|
53
56
|
ComboWidget,
|
|
54
57
|
Empty,
|
|
@@ -98,5 +101,6 @@ export {
|
|
|
98
101
|
defineWidget,
|
|
99
102
|
processImage,
|
|
100
103
|
popupMessage,
|
|
101
|
-
startApp
|
|
104
|
+
startApp,
|
|
105
|
+
tainter
|
|
102
106
|
}
|
package/src/util/tainter.js
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import m from "mithril";
|
|
2
|
+
import {ButtonNew, defineWidget} from "./Basic";
|
|
3
|
+
import ColorJoeWidget from "./ColorJoeWidget";
|
|
4
|
+
|
|
5
|
+
const
|
|
6
|
+
DEFAULT_COLOR = [255, 255, 255, 1],
|
|
7
|
+
hslToRgb = (h, s, l) => {
|
|
8
|
+
|
|
9
|
+
let r,
|
|
10
|
+
g,
|
|
11
|
+
b;
|
|
12
|
+
|
|
13
|
+
if (s === 0) {
|
|
14
|
+
r = g = b = l; // achromatic
|
|
15
|
+
} else {
|
|
16
|
+
const hue2rgb = (p, q, t) => {
|
|
17
|
+
if (t < 0) t += 1;
|
|
18
|
+
if (t > 1) t -= 1;
|
|
19
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
20
|
+
if (t < 1 / 2) return q;
|
|
21
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
22
|
+
return p;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const
|
|
26
|
+
q = l < 0.5 ? l * (1 + s) : l + s - l * s,
|
|
27
|
+
p = 2 * l - q;
|
|
28
|
+
|
|
29
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
30
|
+
g = hue2rgb(p, q, h);
|
|
31
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default defineWidget(
|
|
38
|
+
({attrs}) => {
|
|
39
|
+
|
|
40
|
+
const
|
|
41
|
+
{colors = [], max = 8} = attrs,
|
|
42
|
+
length = colors.length,
|
|
43
|
+
getRgb = (colorBase = [0, 0, 0, 0]) => ("rgba("
|
|
44
|
+
+ (colorBase.map((c, i) => (i < 3 ? Math.floor(c * 255) : c)).join(",")) + ")"),
|
|
45
|
+
|
|
46
|
+
getHsl = (colorBase = [0, 0, 0, 0]) => ("rgba("
|
|
47
|
+
+ (hslToRgb(colorBase[0], colorBase[1], colorBase[2]).join(","))
|
|
48
|
+
+ "," + colorBase[3] + ")");
|
|
49
|
+
|
|
50
|
+
return m(".flexrow.wrap.gradient.grows",
|
|
51
|
+
{
|
|
52
|
+
class: attrs.class
|
|
53
|
+
},
|
|
54
|
+
[
|
|
55
|
+
|
|
56
|
+
...colors.map((entry, index) => m(
|
|
57
|
+
ColorJoeWidget,
|
|
58
|
+
{
|
|
59
|
+
class: "grows",
|
|
60
|
+
color: attrs.hsl ? getHsl(colors[index]) : getRgb(colors[index]),
|
|
61
|
+
title: "Click to edit, or Shift-click to remove this color from the collection",
|
|
62
|
+
hsl: attrs.hsl,
|
|
63
|
+
onchange: (parsedColor, colorObject) => {
|
|
64
|
+
let finalColor;
|
|
65
|
+
if (attrs.hsl) {
|
|
66
|
+
const hsl = colorObject.hsl();
|
|
67
|
+
finalColor = [hsl.hue(), hsl.saturation(), hsl.lightness(), colorObject.a()];
|
|
68
|
+
} else {
|
|
69
|
+
finalColor = [colorObject.r(), colorObject.g(), colorObject.b(), colorObject.a()];
|
|
70
|
+
}
|
|
71
|
+
colors[index] = finalColor;
|
|
72
|
+
if (attrs.onchange) {
|
|
73
|
+
attrs.onchange(colors);
|
|
74
|
+
}
|
|
75
|
+
m.redraw();
|
|
76
|
+
},
|
|
77
|
+
onshiftclick: () => {
|
|
78
|
+
colors.splice(index, 1);
|
|
79
|
+
if (attrs.onchange) {
|
|
80
|
+
attrs.onchange(colors);
|
|
81
|
+
}
|
|
82
|
+
m.redraw();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
)),
|
|
86
|
+
|
|
87
|
+
...(length < max)
|
|
88
|
+
? [
|
|
89
|
+
m(ButtonNew, {
|
|
90
|
+
icon: "plus",
|
|
91
|
+
class: "unitheightsmall accent bg-window-lo " + (length ? "mini" : "grows"),
|
|
92
|
+
title: "Add a new color to the collection, or SHIFT-CLICK to delete all colors",
|
|
93
|
+
onClick: (e) => {
|
|
94
|
+
if (e.shiftKey) {
|
|
95
|
+
colors.splice(0, colors.length);
|
|
96
|
+
} else {
|
|
97
|
+
colors.push(DEFAULT_COLOR);
|
|
98
|
+
}
|
|
99
|
+
if (attrs.onchange) {
|
|
100
|
+
attrs.onchange(colors);
|
|
101
|
+
}
|
|
102
|
+
m.redraw();
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
] : []
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
);
|