@nebularstreams/libmui 2.0.17 → 2.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nebularstreams/libmui",
3
3
  "description": "Micro UI based on Mithril",
4
- "version": "2.0.17",
4
+ "version": "2.5.0",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "scripts": {
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";
@@ -50,6 +51,7 @@ export {
50
51
  ButtonNew,
51
52
  CardieWidget,
52
53
  ColorJoeWidget,
54
+ ColorJoePack,
53
55
  ComboPrompt,
54
56
  ComboWidget,
55
57
  Empty,
@@ -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
+ );
@@ -1,39 +1,36 @@
1
- const
1
+ import m from "mithril"
2
+ import {defineWidget, ButtonNew, Empty} from "./Basic.js"
2
3
 
3
- m = require("mithril"),
4
- defineWidget = require("util.definewidget"),
5
-
6
- { ButtonNew, Empty } = require("app.widgets");
7
4
 
8
5
  const EmptyButton = defineWidget(
9
- ({ attrs }) => m(
10
- Empty,
11
- {
12
- size: 2,
13
- icon: attrs.icon,
14
- class: "pad-2"
15
- },
16
- [
17
- ...attrs.texts
18
- .map((text) => m(".text", text)),
19
- ...attrs.buttonText ? [
20
- m(ButtonNew, {
21
- class: "font-125 accentbutton unitheightsmall",
22
- icon: attrs.icon || "plus",
23
- text: attrs.buttonText,
24
- onClick: attrs.onClick
25
- })
26
- ] : [],
27
- ...attrs.buttonAlt ? [
28
- m(ButtonNew, {
29
- class: "font-125 accentbutton unitheightsmall",
30
- icon: attrs.iconAlt || "plus",
31
- text: attrs.buttonTextAlt,
32
- onClick: attrs.onClick
33
- })
34
- ] : []
35
- ]
36
- )
6
+ ({attrs}) => m(
7
+ Empty,
8
+ {
9
+ size: 2,
10
+ icon: attrs.icon,
11
+ class: "pad-2"
12
+ },
13
+ [
14
+ ...attrs.texts
15
+ .map((text) => m(".text", text)),
16
+ ...attrs.buttonText ? [
17
+ m(ButtonNew, {
18
+ class: "font-125 accentbutton unitheightsmall",
19
+ icon: attrs.icon || "plus",
20
+ text: attrs.buttonText,
21
+ onClick: attrs.onClick
22
+ })
23
+ ] : [],
24
+ ...attrs.buttonAlt ? [
25
+ m(ButtonNew, {
26
+ class: "font-125 accentbutton unitheightsmall",
27
+ icon: attrs.iconAlt || "plus",
28
+ text: attrs.buttonTextAlt,
29
+ onClick: attrs.onClick
30
+ })
31
+ ] : []
32
+ ]
33
+ )
37
34
  );
38
35
 
39
36
  module.exports = EmptyButton;