tweak-ui 0.4.3 → 0.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/LICENSE +7 -7
- package/README.md +32 -32
- package/dist/lib/builder.d.ts +166 -162
- package/dist/lib/builder.d.ts.map +1 -1
- package/dist/lib/builder.js +250 -0
- package/dist/lib/builder.js.map +1 -0
- package/dist/lib/color-formats/array-format.d.ts +8 -8
- package/dist/lib/color-formats/array-format.js +18 -0
- package/dist/lib/color-formats/array-format.js.map +1 -0
- package/dist/lib/color-formats/converter.d.ts +18 -18
- package/dist/lib/color-formats/converter.js +85 -0
- package/dist/lib/color-formats/converter.js.map +1 -0
- package/dist/lib/color-formats/css-string-format.d.ts +7 -7
- package/dist/lib/color-formats/css-string-format.js +28 -0
- package/dist/lib/color-formats/css-string-format.js.map +1 -0
- package/dist/lib/color-formats/formatter.d.ts +8 -8
- package/dist/lib/color-formats/formatter.js +35 -0
- package/dist/lib/color-formats/formatter.js.map +1 -0
- package/dist/lib/color-formats/hex-string-format.d.ts +7 -7
- package/dist/lib/color-formats/hex-string-format.js +28 -0
- package/dist/lib/color-formats/hex-string-format.js.map +1 -0
- package/dist/lib/color-formats/index.d.ts +3 -3
- package/dist/lib/color-formats/index.js +4 -0
- package/dist/lib/color-formats/index.js.map +1 -0
- package/dist/lib/color-formats/number-format.d.ts +8 -8
- package/dist/lib/color-formats/number-format.js +23 -0
- package/dist/lib/color-formats/number-format.js.map +1 -0
- package/dist/lib/color-formats/object-format.d.ts +14 -14
- package/dist/lib/color-formats/object-format.js +23 -0
- package/dist/lib/color-formats/object-format.js.map +1 -0
- package/dist/lib/color-formats/types.d.ts +101 -101
- package/dist/lib/color-formats/types.js +2 -0
- package/dist/lib/color-formats/types.js.map +1 -0
- package/dist/lib/components/button.d.ts +28 -28
- package/dist/lib/components/button.d.ts.map +1 -1
- package/dist/lib/components/button.js +15 -0
- package/dist/lib/components/button.js.map +1 -0
- package/dist/lib/components/content.d.ts +21 -21
- package/dist/lib/components/content.d.ts.map +1 -1
- package/dist/lib/components/content.js +10 -0
- package/dist/lib/components/content.js.map +1 -0
- package/dist/lib/components/controls/angle.d.ts +51 -51
- package/dist/lib/components/controls/angle.d.ts.map +1 -1
- package/dist/lib/components/controls/angle.js +201 -0
- package/dist/lib/components/controls/angle.js.map +1 -0
- package/dist/lib/components/controls/checkbox.d.ts +28 -28
- package/dist/lib/components/controls/checkbox.d.ts.map +1 -1
- package/dist/lib/components/controls/checkbox.js +31 -0
- package/dist/lib/components/controls/checkbox.js.map +1 -0
- package/dist/lib/components/controls/color-picker.d.ts +56 -56
- package/dist/lib/components/controls/color-picker.d.ts.map +1 -1
- package/dist/lib/components/controls/color-picker.js +267 -0
- package/dist/lib/components/controls/color-picker.js.map +1 -0
- package/dist/lib/components/controls/color.d.ts +51 -51
- package/dist/lib/components/controls/color.d.ts.map +1 -1
- package/dist/lib/components/controls/color.js +77 -0
- package/dist/lib/components/controls/color.js.map +1 -0
- package/dist/lib/components/controls/index.d.ts +10 -10
- package/dist/lib/components/controls/index.js +11 -0
- package/dist/lib/components/controls/index.js.map +1 -0
- package/dist/lib/components/controls/number.d.ts +47 -47
- package/dist/lib/components/controls/number.d.ts.map +1 -1
- package/dist/lib/components/controls/number.js +142 -0
- package/dist/lib/components/controls/number.js.map +1 -0
- package/dist/lib/components/controls/point.d.ts +47 -47
- package/dist/lib/components/controls/point.d.ts.map +1 -1
- package/dist/lib/components/controls/point.js +137 -0
- package/dist/lib/components/controls/point.js.map +1 -0
- package/dist/lib/components/controls/position.d.ts +55 -55
- package/dist/lib/components/controls/position.d.ts.map +1 -1
- package/dist/lib/components/controls/position.js +36 -0
- package/dist/lib/components/controls/position.js.map +1 -0
- package/dist/lib/components/controls/select.d.ts +59 -59
- package/dist/lib/components/controls/select.d.ts.map +1 -1
- package/dist/lib/components/controls/select.js +132 -0
- package/dist/lib/components/controls/select.js.map +1 -0
- package/dist/lib/components/controls/spherical.d.ts +74 -74
- package/dist/lib/components/controls/spherical.d.ts.map +1 -1
- package/dist/lib/components/controls/spherical.js +302 -0
- package/dist/lib/components/controls/spherical.js.map +1 -0
- package/dist/lib/components/controls/text.d.ts +35 -35
- package/dist/lib/components/controls/text.d.ts.map +1 -1
- package/dist/lib/components/controls/text.js +24 -0
- package/dist/lib/components/controls/text.js.map +1 -0
- package/dist/lib/components/groups/accordion.d.ts +21 -21
- package/dist/lib/components/groups/accordion.d.ts.map +1 -1
- package/dist/lib/components/groups/accordion.js +34 -0
- package/dist/lib/components/groups/accordion.js.map +1 -0
- package/dist/lib/components/groups/container.d.ts +24 -24
- package/dist/lib/components/groups/container.d.ts.map +1 -1
- package/dist/lib/components/groups/container.js +19 -0
- package/dist/lib/components/groups/container.js.map +1 -0
- package/dist/lib/components/groups/group.d.ts +48 -48
- package/dist/lib/components/groups/group.d.ts.map +1 -1
- package/dist/lib/components/groups/group.js +50 -0
- package/dist/lib/components/groups/group.js.map +1 -0
- package/dist/lib/components/groups/index.d.ts +4 -4
- package/dist/lib/components/groups/index.js +5 -0
- package/dist/lib/components/groups/index.js.map +1 -0
- package/dist/lib/components/groups/tabs.d.ts +21 -21
- package/dist/lib/components/groups/tabs.d.ts.map +1 -1
- package/dist/lib/components/groups/tabs.js +31 -0
- package/dist/lib/components/groups/tabs.js.map +1 -0
- package/dist/lib/components/image.d.ts +36 -36
- package/dist/lib/components/image.d.ts.map +1 -1
- package/dist/lib/components/image.js +46 -0
- package/dist/lib/components/image.js.map +1 -0
- package/dist/lib/components/index.d.ts +5 -5
- package/dist/lib/components/index.js +6 -0
- package/dist/lib/components/index.js.map +1 -0
- package/dist/lib/core/index.d.ts +4 -4
- package/dist/lib/core/index.js +5 -0
- package/dist/lib/core/index.js.map +1 -0
- package/dist/lib/core/registry.d.ts +17 -17
- package/dist/lib/core/registry.js +30 -0
- package/dist/lib/core/registry.js.map +1 -0
- package/dist/lib/core/render.d.ts +9 -9
- package/dist/lib/core/render.d.ts.map +1 -1
- package/dist/lib/core/render.js +19 -0
- package/dist/lib/core/render.js.map +1 -0
- package/dist/lib/core/types.d.ts +87 -87
- package/dist/lib/core/types.d.ts.map +1 -1
- package/dist/lib/core/types.js +2 -0
- package/dist/lib/core/types.js.map +1 -0
- package/dist/lib/core/utils.d.ts +93 -93
- package/dist/lib/core/utils.d.ts.map +1 -1
- package/dist/lib/core/utils.js +193 -0
- package/dist/lib/core/utils.js.map +1 -0
- package/dist/lib/core/value-accessor.d.ts +17 -17
- package/dist/lib/core/value-accessor.js +52 -0
- package/dist/lib/core/value-accessor.js.map +1 -0
- package/dist/lib/index.d.ts +21 -27
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +29 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/mount.d.ts +45 -45
- package/dist/lib/mount.js +85 -0
- package/dist/lib/mount.js.map +1 -0
- package/dist/tweak-ui.css +133 -138
- package/dist/tweak-ui.css.map +1 -1
- package/dist/tweak-ui.min.css +1 -1
- package/dist/tweak-ui.min.css.map +1 -1
- package/dist/tweak-ui.module.js +2733 -2396
- package/dist/tweak-ui.module.js.map +1 -1
- package/dist/tweak-ui.umd.js +1 -4419
- package/dist/tweak-ui.umd.js.map +1 -1
- package/package.json +25 -42
- package/dist/index.html +0 -1063
- package/dist/lib/color-formats/array-format.spec.d.ts +0 -2
- package/dist/lib/color-formats/array-format.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/converter.spec.d.ts +0 -2
- package/dist/lib/color-formats/converter.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/css-string-format.spec.d.ts +0 -2
- package/dist/lib/color-formats/css-string-format.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/formatter.spec.d.ts +0 -2
- package/dist/lib/color-formats/formatter.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/hex-string-format.spec.d.ts +0 -2
- package/dist/lib/color-formats/hex-string-format.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/number-format.spec.d.ts +0 -2
- package/dist/lib/color-formats/number-format.spec.d.ts.map +0 -1
- package/dist/lib/color-formats/object-format.spec.d.ts +0 -2
- package/dist/lib/color-formats/object-format.spec.d.ts.map +0 -1
- package/dist/scss/_style.scss +0 -120
- package/dist/scss/_themes.scss +0 -23
- package/dist/scss/_utils.scss +0 -24
- package/dist/scss/_variables.scss +0 -30
- package/dist/scss/controls/_angle.scss +0 -64
- package/dist/scss/controls/_button.scss +0 -0
- package/dist/scss/controls/_checkbox.scss +0 -19
- package/dist/scss/controls/_color-picker.scss +0 -124
- package/dist/scss/controls/_color.scss +0 -14
- package/dist/scss/controls/_container.scss +0 -13
- package/dist/scss/controls/_group.scss +0 -69
- package/dist/scss/controls/_image.scss +0 -27
- package/dist/scss/controls/_number.scss +0 -38
- package/dist/scss/controls/_point.scss +0 -36
- package/dist/scss/controls/_position.scss +0 -9
- package/dist/scss/controls/_select.scss +0 -0
- package/dist/scss/controls/_spherical.scss +0 -87
- package/dist/scss/controls/_tabs.scss +0 -38
- package/dist/scss/controls/_text.scss +0 -0
- package/dist/scss/index.scss +0 -21
- package/dist/tweak-ui.umd.min.js +0 -17
- package/dist/tweak-ui.umd.min.js.map +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import m from 'mithril';
|
|
2
|
+
import { component, getValue, renderModel, setValue, } from '../../core';
|
|
3
|
+
import { call, clamp, cssClass, dragUtil, getTouchInTarget, twuiClass } from '../../core/utils';
|
|
4
|
+
const TYPE = 'angle';
|
|
5
|
+
const AngleComponent = (vnode) => {
|
|
6
|
+
let angle = 0;
|
|
7
|
+
let dragged = false;
|
|
8
|
+
let pos = [0, 0];
|
|
9
|
+
function toDeg(value) {
|
|
10
|
+
return value * (180 / Math.PI);
|
|
11
|
+
}
|
|
12
|
+
function toRad(value) {
|
|
13
|
+
return value * (Math.PI / 180);
|
|
14
|
+
}
|
|
15
|
+
function toScreen(value) {
|
|
16
|
+
return clamp((value / 2 + 0.5) * 100, 0, 100);
|
|
17
|
+
}
|
|
18
|
+
function fetchValue(node) {
|
|
19
|
+
var _a;
|
|
20
|
+
const data = node.attrs.data;
|
|
21
|
+
angle = (_a = getValue(data)) !== null && _a !== void 0 ? _a : angle;
|
|
22
|
+
if (data.degree) {
|
|
23
|
+
angle = toRad(angle);
|
|
24
|
+
}
|
|
25
|
+
updatePositions();
|
|
26
|
+
}
|
|
27
|
+
function onChange(type) {
|
|
28
|
+
updatePositions();
|
|
29
|
+
const data = vnode.attrs.data;
|
|
30
|
+
const value = data.degree ? toRad(angle) : angle;
|
|
31
|
+
const written = setValue(data, value);
|
|
32
|
+
call(type === 'input' ? data.onInput : data.onChange, data, written);
|
|
33
|
+
}
|
|
34
|
+
function updatePositions() {
|
|
35
|
+
pos[0] = Math.cos(angle);
|
|
36
|
+
pos[1] = Math.sin(angle);
|
|
37
|
+
}
|
|
38
|
+
function onStartPhi(e) {
|
|
39
|
+
dragged = true;
|
|
40
|
+
drag.activate(e);
|
|
41
|
+
}
|
|
42
|
+
let touchOffset;
|
|
43
|
+
const drag = dragUtil({
|
|
44
|
+
onStart: (e) => {
|
|
45
|
+
const touch = getTouchInTarget(e);
|
|
46
|
+
touchOffset = [
|
|
47
|
+
-(touch.x - touch.width / 2),
|
|
48
|
+
-(touch.y - touch.height / 2),
|
|
49
|
+
];
|
|
50
|
+
drag.onMove(e);
|
|
51
|
+
},
|
|
52
|
+
onMove: (e) => {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
const position = getTouchInTarget(e, drag.target.parentElement, touchOffset);
|
|
55
|
+
const px = position.normalizedX - 0.5;
|
|
56
|
+
const py = position.normalizedY - 0.5;
|
|
57
|
+
if (dragged) {
|
|
58
|
+
// [-PI;PI]
|
|
59
|
+
angle = Math.atan2(px, py);
|
|
60
|
+
// convert to range [0;2PI]
|
|
61
|
+
angle += angle < 0 ? 2 * Math.PI : 0;
|
|
62
|
+
}
|
|
63
|
+
onChange('input');
|
|
64
|
+
m.redraw();
|
|
65
|
+
},
|
|
66
|
+
onEnd: (e) => {
|
|
67
|
+
drag.deactivate();
|
|
68
|
+
dragged = false;
|
|
69
|
+
onChange('change');
|
|
70
|
+
m.redraw();
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
function onPhiInput(model, value) {
|
|
74
|
+
angle = toRad(value);
|
|
75
|
+
onChange('input');
|
|
76
|
+
}
|
|
77
|
+
function onPhiChange(model, value) {
|
|
78
|
+
angle = toRad(value);
|
|
79
|
+
onChange('change');
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
onremove: () => {
|
|
83
|
+
drag.deactivate();
|
|
84
|
+
},
|
|
85
|
+
oninit: (node) => {
|
|
86
|
+
fetchValue(node);
|
|
87
|
+
},
|
|
88
|
+
onupdate: (node) => {
|
|
89
|
+
fetchValue(node);
|
|
90
|
+
},
|
|
91
|
+
view: () => {
|
|
92
|
+
return m('div', {
|
|
93
|
+
class: twuiClass(TYPE),
|
|
94
|
+
style: {
|
|
95
|
+
'--angle-value': `${toDeg(-angle) + 90}deg`,
|
|
96
|
+
'--angle-percent': `${(toDeg(angle) / 360) * 100}%`,
|
|
97
|
+
},
|
|
98
|
+
}, m('div.left-container', m('div.pane', {
|
|
99
|
+
style: {
|
|
100
|
+
position: 'relative',
|
|
101
|
+
width: '100%',
|
|
102
|
+
'padding-top': '100%',
|
|
103
|
+
},
|
|
104
|
+
}, m('div.angle-pane', {
|
|
105
|
+
class: cssClass({
|
|
106
|
+
'is-dragging': dragged,
|
|
107
|
+
}),
|
|
108
|
+
style: {
|
|
109
|
+
position: 'absolute',
|
|
110
|
+
top: '0.5rem',
|
|
111
|
+
left: '0.5rem',
|
|
112
|
+
width: 'calc(100% - 1rem)',
|
|
113
|
+
height: 'calc(100% - 1rem)',
|
|
114
|
+
},
|
|
115
|
+
}, m('div.angle-knob', {
|
|
116
|
+
onmousedown: onStartPhi,
|
|
117
|
+
ontouchstart: onStartPhi,
|
|
118
|
+
style: {
|
|
119
|
+
position: 'absolute',
|
|
120
|
+
width: '15px',
|
|
121
|
+
height: '15px',
|
|
122
|
+
top: `calc(${toScreen(pos[0])}% - 7px)`,
|
|
123
|
+
left: `calc(${toScreen(pos[1])}% - 7px)`,
|
|
124
|
+
},
|
|
125
|
+
})))), m('div.right-container', m('label', m.trust('α')), renderModel({
|
|
126
|
+
type: 'number',
|
|
127
|
+
min: 0,
|
|
128
|
+
max: 360,
|
|
129
|
+
step: 0.1,
|
|
130
|
+
value: toDeg(angle),
|
|
131
|
+
onInput: onPhiInput,
|
|
132
|
+
onChange: onPhiChange,
|
|
133
|
+
})));
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
component(TYPE, AngleComponent);
|
|
138
|
+
export function angleCodec({ axes, length, result } = {}) {
|
|
139
|
+
axes = axes || { x: 'right', y: 'up' };
|
|
140
|
+
const keys = Object.keys(axes);
|
|
141
|
+
const radius = () => {
|
|
142
|
+
return (typeof length === 'function' ? length() : length) || 1;
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
decode: (value) => {
|
|
146
|
+
let x = 0;
|
|
147
|
+
let y = 0;
|
|
148
|
+
for (const key of keys) {
|
|
149
|
+
switch (axes[key]) {
|
|
150
|
+
case 'right':
|
|
151
|
+
y = value[key];
|
|
152
|
+
break;
|
|
153
|
+
case 'left':
|
|
154
|
+
y = -value[key];
|
|
155
|
+
break;
|
|
156
|
+
case 'up':
|
|
157
|
+
case 'front':
|
|
158
|
+
x = -value[key];
|
|
159
|
+
break;
|
|
160
|
+
case 'down':
|
|
161
|
+
case 'back':
|
|
162
|
+
x = value[key];
|
|
163
|
+
default:
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const r = radius();
|
|
168
|
+
x /= r;
|
|
169
|
+
y /= r;
|
|
170
|
+
return Math.atan2(y, x) || 0;
|
|
171
|
+
},
|
|
172
|
+
encode: (angle) => {
|
|
173
|
+
const r = radius();
|
|
174
|
+
const x = r * Math.cos(angle);
|
|
175
|
+
const y = r * Math.sin(angle);
|
|
176
|
+
const value = result() || {};
|
|
177
|
+
for (const key of keys) {
|
|
178
|
+
switch (axes[key]) {
|
|
179
|
+
case 'right':
|
|
180
|
+
value[key] = y;
|
|
181
|
+
break;
|
|
182
|
+
case 'left':
|
|
183
|
+
value[key] = -y;
|
|
184
|
+
break;
|
|
185
|
+
case 'up':
|
|
186
|
+
case 'front':
|
|
187
|
+
value[key] = -x;
|
|
188
|
+
break;
|
|
189
|
+
case 'down':
|
|
190
|
+
case 'back':
|
|
191
|
+
value[key] = x;
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return value;
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=angle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angle.js","sourceRoot":"","sources":["../../../../src/lib/components/controls/angle.ts"],"names":[],"mappings":"AAAA,OAAO,CAAuB,MAAM,SAAS,CAAA;AAE7C,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,QAAQ,GAKT,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAoC/F,MAAM,IAAI,GAAG,OAAO,CAAA;AACpB,MAAM,cAAc,GAAiC,CAAC,KAAK,EAAE,EAAE;IAC7D,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,IAAI,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEhB,SAAS,KAAK,CAAC,KAAa;QAC1B,OAAO,KAAK,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;IAChC,CAAC;IACD,SAAS,KAAK,CAAC,KAAa;QAC1B,OAAO,KAAK,GAAG,CAAC,I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AE,CAAC;gBACvB,QAAQ,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBAClB,KAAK,OAAO;wBACV,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;wBACd,MAAK;oBACP,KAAK,MAAM;wBACT,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;wBACf,MAAK;oBACP,KAAK,IAAI,CAAC;oBACV,KAAK,OAAO;wBACV,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;wBACf,MAAK;oBACP,KAAK,MAAM,CAAC;oBACZ,KAAK,MAAM;wBACT,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;wBACd,MAAK;oBACP;wBACE,MAAK;gBACT,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import m, { FactoryComponent } from 'mithril'\r\n\r\nimport {\r\n component,\r\n getValue,\r\n renderModel,\r\n setValue,\r\n ComponentModel,\r\n ValueSource,\r\n ComponentAttrs,\r\n ValueCodec,\r\n} from '../../core'\r\nimport { call, clamp, cssClass, dragUtil, getTouchInTarget, twuiClass } from '../../core/utils'\r\nimport type { NumberModel } from './number'\r\nimport { Direction } from './spherical'\r\n\r\n/**\r\n * Spherical component attributes\r\n * @public\r\n */\r\nexport type AngleAttrs = ComponentAttrs<AngleModel>\r\n\r\n/**\r\n * Spherical component model\r\n * @public\r\n */\r\nexport interface AngleModel<T = unknown> extends ComponentModel, ValueSource<T, number> {\r\n /**\r\n * The type name of the control\r\n */\r\n type: 'angle'\r\n /**\r\n * Whether to use degrees instead of radians\r\n */\r\n degree?: boolean\r\n /**\r\n * This is called when the control value has been changed.\r\n */\r\n onInput?: (model: AngleModel<T>, value: unknown) => void\r\n /**\r\n * This is called once the control value is committed by the user.\r\n *\r\n * @remarks\r\n * Unlike the `onInput` callback, this is not necessarily called for each value change.\r\n */\r\n onChange?: (model: AngleModel<T>, value: unknown) => void\r\n}\r\n\r\nconst TYPE = 'angle'\r\nconst AngleComponent: FactoryComponent<AngleAttrs> = (vnode) => {\r\n let angle = 0\r\n let dragged = false\r\n let pos = [0, 0]\r\n\r\n function toDeg(value: number) {\r\n return value * (180 / Math.PI)\r\n }\r\n function toRad(value: number) {\r\n return value * (Math.PI / 180)\r\n }\r\n function toScreen(value: number) {\r\n return clamp((value / 2 + 0.5) * 100, 0, 100)\r\n }\r\n\r\n function fetchValue(node: m.Vnode<AngleAttrs>) {\r\n const data = node.attrs.data\r\n angle = getValue(data) ?? angle\r\n if (data.degree) {\r\n angle = toRad(angle)\r\n }\r\n updatePositions()\r\n }\r\n\r\n function onChange(type: 'change' | 'input') {\r\n updatePositions()\r\n const data = vnode.attrs.data\r\n const value = data.degree ? toRad(angle) : angle\r\n const written = setValue(data, value)\r\n call(type === 'input' ? data.onInput : data.onChange, data, written)\r\n }\r\n\r\n function updatePositions() {\r\n pos[0] = Math.cos(angle)\r\n pos[1] = Math.sin(angle)\r\n }\r\n\r\n function onStartPhi(e: MouseEvent) {\r\n dragged = true\r\n drag.activate(e)\r\n }\r\n\r\n let touchOffset: [number, number]\r\n const drag = dragUtil({\r\n onStart: (e) => {\r\n const touch = getTouchInTarget(e)\r\n touchOffset = [\r\n -(touch.x - touch.width / 2),\r\n -(touch.y - touch.height / 2),\r\n ]\r\n drag.onMove(e)\r\n },\r\n onMove: (e) => {\r\n e.preventDefault()\r\n\r\n const position = getTouchInTarget(e, drag.target.parentElement, touchOffset)\r\n const px = position.normalizedX - 0.5\r\n const py = position.normalizedY - 0.5\r\n if (dragged) {\r\n // [-PI;PI]\r\n angle = Math.atan2(px, py)\r\n // convert to range [0;2PI]\r\n angle += angle < 0 ? 2 * Math.PI : 0\r\n }\r\n onChange('input')\r\n m.redraw()\r\n },\r\n onEnd: (e) => {\r\n drag.deactivate()\r\n dragged = false\r\n onChange('change')\r\n m.redraw()\r\n },\r\n })\r\n\r\n function onPhiInput(model: unknown, value: number) {\r\n angle = toRad(value)\r\n onChange('input')\r\n }\r\n function onPhiChange(model: unknown, value: number) {\r\n angle = toRad(value)\r\n onChange('change')\r\n }\r\n\r\n return {\r\n onremove: () => {\r\n drag.deactivate()\r\n },\r\n oninit: (node) => {\r\n fetchValue(node)\r\n },\r\n onupdate: (node) => {\r\n fetchValue(node)\r\n },\r\n view: () => {\r\n return m(\r\n 'div',\r\n {\r\n class: twuiClass(TYPE),\r\n style: {\r\n '--angle-value': `${toDeg(-angle) + 90}deg`,\r\n '--angle-percent': `${(toDeg(angle) / 360) * 100}%`,\r\n },\r\n },\r\n m(\r\n 'div.left-container',\r\n m(\r\n 'div.pane',\r\n {\r\n style: {\r\n position: 'relative',\r\n width: '100%',\r\n 'padding-top': '100%',\r\n },\r\n },\r\n m(\r\n 'div.angle-pane',\r\n {\r\n class: cssClass({\r\n 'is-dragging': dragged,\r\n }),\r\n style: {\r\n position: 'absolute',\r\n top: '0.5rem',\r\n left: '0.5rem',\r\n width: 'calc(100% - 1rem)',\r\n height: 'calc(100% - 1rem)',\r\n },\r\n },\r\n m('div.angle-knob', {\r\n onmousedown: onStartPhi,\r\n ontouchstart: onStartPhi,\r\n style: {\r\n position: 'absolute',\r\n width: '15px',\r\n height: '15px',\r\n top: `calc(${toScreen(pos[0])}% - 7px)`,\r\n left: `calc(${toScreen(pos[1])}% - 7px)`,\r\n },\r\n }),\r\n ),\r\n ),\r\n ),\r\n m(\r\n 'div.right-container',\r\n m('label', m.trust('α')),\r\n renderModel<NumberModel>({\r\n type: 'number',\r\n min: 0,\r\n max: 360,\r\n step: 0.1,\r\n value: toDeg(angle),\r\n onInput: onPhiInput,\r\n onChange: onPhiChange,\r\n }),\r\n ),\r\n )\r\n },\r\n }\r\n}\r\n\r\ncomponent<AngleAttrs>(TYPE, AngleComponent)\r\n\r\nexport interface AngleCodecOptions<T> {\r\n /**\r\n * Maps object keys to cartesian axes. Defaults to `{ x: 'right', y: 'up' }`\r\n */\r\n axes?: Record<string | number, Direction>\r\n /**\r\n * The vector length (circle radius). Defaults to `1`\r\n */\r\n length?: number | (() => number)\r\n /**\r\n * Gets the objec where the result should be stored. May return a new instance.\r\n */\r\n result?: () => T\r\n}\r\n\r\nexport function angleCodec(): ValueCodec<{ x: number; y: number }, number>\r\nexport function angleCodec<T>(options: AngleCodecOptions<T>): ValueCodec<T, number>\r\nexport function angleCodec({ axes, length, result }: AngleCodecOptions<any> = {}): ValueCodec<\r\n any,\r\n number\r\n> {\r\n axes = axes || { x: 'right', y: 'up'}\r\n const keys = Object.keys(axes)\r\n const radius = () => {\r\n return (typeof length === 'function' ? length() : length) || 1\r\n }\r\n return {\r\n decode: (value: any) => {\r\n let x: number = 0\r\n let y: number = 0\r\n for (const key of keys) {\r\n switch (axes[key]) {\r\n case 'right':\r\n y = value[key]\r\n break\r\n case 'left':\r\n y = -value[key]\r\n break\r\n case 'up':\r\n case 'front':\r\n x = -value[key]\r\n break\r\n case 'down':\r\n case 'back':\r\n x = value[key]\r\n default:\r\n break\r\n }\r\n }\r\n const r = radius()\r\n x /= r\r\n y /= r\r\n return Math.atan2(y, x) || 0\r\n },\r\n encode: (angle) => {\r\n const r = radius()\r\n const x = r * Math.cos(angle)\r\n const y = r * Math.sin(angle)\r\n const value = result() || {}\r\n for (const key of keys) {\r\n switch (axes[key]) {\r\n case 'right':\r\n value[key] = y\r\n break\r\n case 'left':\r\n value[key] = -y\r\n break\r\n case 'up':\r\n case 'front':\r\n value[key] = -x\r\n break\r\n case 'down':\r\n case 'back':\r\n value[key] = x\r\n break\r\n default:\r\n break\r\n }\r\n }\r\n return value\r\n },\r\n }\r\n}\r\n"]}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { ValueSource, ComponentAttrs, ComponentModel } from '../../core';
|
|
2
|
-
/**
|
|
3
|
-
* Checkbox component attrs
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export
|
|
7
|
-
/**
|
|
8
|
-
* Describes a checkbox control
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export interface CheckboxModel<T = unknown> extends ComponentModel, ValueSource<T, boolean> {
|
|
12
|
-
/**
|
|
13
|
-
* The type name of the control
|
|
14
|
-
*/
|
|
15
|
-
type: 'checkbox';
|
|
16
|
-
/**
|
|
17
|
-
* This is called when the control value changes
|
|
18
|
-
*/
|
|
19
|
-
onChange?: (model: CheckboxModel, value: unknown) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Text behind the checkbox or inside the buttn
|
|
22
|
-
*/
|
|
23
|
-
text?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Disables the control input
|
|
26
|
-
*/
|
|
27
|
-
disabled?: boolean;
|
|
28
|
-
}
|
|
1
|
+
import { ValueSource, ComponentAttrs, ComponentModel } from '../../core';
|
|
2
|
+
/**
|
|
3
|
+
* Checkbox component attrs
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type CheckboxAttrs = ComponentAttrs<CheckboxModel>;
|
|
7
|
+
/**
|
|
8
|
+
* Describes a checkbox control
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface CheckboxModel<T = unknown> extends ComponentModel, ValueSource<T, boolean> {
|
|
12
|
+
/**
|
|
13
|
+
* The type name of the control
|
|
14
|
+
*/
|
|
15
|
+
type: 'checkbox';
|
|
16
|
+
/**
|
|
17
|
+
* This is called when the control value changes
|
|
18
|
+
*/
|
|
19
|
+
onChange?: (model: CheckboxModel, value: unknown) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Text behind the checkbox or inside the buttn
|
|
22
|
+
*/
|
|
23
|
+
text?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Disables the control input
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
}
|
|
29
29
|
//# sourceMappingURL=checkbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/controls/checkbox.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,WAAW,EACX,cAAc,EACd,cAAc,EACf,MAAM,YAAY,CAAA;AAGnB;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/controls/checkbox.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,WAAW,EACX,cAAc,EACd,cAAc,EACf,MAAM,YAAY,CAAA;AAGnB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,aAAa,CAAC,CAAA;AAEzD;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO,CACxC,SAAQ,cAAc,EACpB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,IAAI,EAAE,UAAU,CAAA;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACzD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import m from 'mithril';
|
|
2
|
+
import { getValue, component, setValue, } from '../../core';
|
|
3
|
+
import { call, twuiClass, cssClass, viewFn } from '../../core/utils';
|
|
4
|
+
const TYPE = 'checkbox';
|
|
5
|
+
const CheckboxComponent = (node) => {
|
|
6
|
+
function onChange(e) {
|
|
7
|
+
const data = node.attrs.data;
|
|
8
|
+
const checked = e.target.checked;
|
|
9
|
+
const written = setValue(data, checked);
|
|
10
|
+
call(data.onChange, data, written);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
view: viewFn((data) => {
|
|
14
|
+
const checked = getValue(data) === true;
|
|
15
|
+
return m('label', {
|
|
16
|
+
class: cssClass({
|
|
17
|
+
[twuiClass(TYPE)]: true,
|
|
18
|
+
checked: checked,
|
|
19
|
+
disabled: data.disabled,
|
|
20
|
+
}),
|
|
21
|
+
}, m('input', {
|
|
22
|
+
type: 'checkbox',
|
|
23
|
+
checked: checked,
|
|
24
|
+
onchange: onChange,
|
|
25
|
+
disabled: data.disabled,
|
|
26
|
+
}), data.text);
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
component(TYPE, CheckboxComponent);
|
|
31
|
+
//# sourceMappingURL=checkbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../../src/lib/components/controls/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,CAAuB,MAAM,SAAS,CAAA;AAE7C,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,GAIT,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAiCpE,MAAM,IAAI,GAAG,UAAU,CAAA;AACvB,MAAM,iBAAiB,GAAoC,CAAC,IAAI,EAAE,EAAE;IAClE,SAAS,QAAQ,CAAC,CAAQ;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;QAC5B,MAAM,OAAO,GAAI,CAAC,CAAC,MAA2B,CAAC,OAAO,CAAA;QACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACpC,CAAC;IACD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;YACvC,OAAO,CAAC,CACN,OAAO,EACP;gBACE,KAAK,EAAE,QAAQ,CAAC;oBACd,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI;oBACvB,OAAO,EAAE,OAAO;oBAChB,QAAQ,EAAE,IAAI,CAAC,QAAQ;iBACxB,CAAC;aACH,EACD,CAAC,CAAC,OAAO,EAAE;gBACT,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC,EACF,IAAI,CAAC,IAAI,CACV,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACH,CAAC,CAAA;AAED,SAAS,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import m, { FactoryComponent } from 'mithril'\r\n\r\nimport {\r\n getValue,\r\n component,\r\n setValue,\r\n ValueSource,\r\n ComponentAttrs,\r\n ComponentModel,\r\n} from '../../core'\r\nimport { call, twuiClass, cssClass, viewFn } from '../../core/utils'\r\n\r\n/**\r\n * Checkbox component attrs\r\n * @public\r\n */\r\nexport type CheckboxAttrs = ComponentAttrs<CheckboxModel>\r\n\r\n/**\r\n * Describes a checkbox control\r\n * @public\r\n */\r\nexport interface CheckboxModel<T = unknown>\r\n extends ComponentModel,\r\n ValueSource<T, boolean> {\r\n /**\r\n * The type name of the control\r\n */\r\n type: 'checkbox'\r\n /**\r\n * This is called when the control value changes\r\n */\r\n onChange?: (model: CheckboxModel, value: unknown) => void\r\n /**\r\n * Text behind the checkbox or inside the buttn\r\n */\r\n text?: string\r\n /**\r\n * Disables the control input\r\n */\r\n disabled?: boolean\r\n}\r\n\r\nconst TYPE = 'checkbox'\r\nconst CheckboxComponent: FactoryComponent<CheckboxAttrs> = (node) => {\r\n function onChange(e: Event) {\r\n const data = node.attrs.data\r\n const checked = (e.target as HTMLInputElement).checked\r\n const written = setValue(data, checked)\r\n call(data.onChange, data, written)\r\n }\r\n return {\r\n view: viewFn((data) => {\r\n const checked = getValue(data) === true\r\n return m(\r\n 'label',\r\n {\r\n class: cssClass({\r\n [twuiClass(TYPE)]: true,\r\n checked: checked,\r\n disabled: data.disabled,\r\n }),\r\n },\r\n m('input', {\r\n type: 'checkbox',\r\n checked: checked,\r\n onchange: onChange,\r\n disabled: data.disabled,\r\n }),\r\n data.text,\r\n )\r\n }),\r\n }\r\n}\r\n\r\ncomponent(TYPE, CheckboxComponent)\r\n"]}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { ComponentModel, ValueSource, ComponentAttrs } from '../../core';
|
|
2
|
-
/**
|
|
3
|
-
* Color picker component attributes
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Color picker component model
|
|
10
|
-
*
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export interface ColorPickerModel<T = unknown, V = number | string | number[]> extends ComponentModel, ValueSource<T, V> {
|
|
14
|
-
/**
|
|
15
|
-
* The type name of the control
|
|
16
|
-
*/
|
|
17
|
-
type: 'color-picker';
|
|
18
|
-
/**
|
|
19
|
-
* If `target` and `property` are not set, then this is used as the control value
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* The format is determined by the `format` property.
|
|
23
|
-
*
|
|
24
|
-
* It is allowed to omit the '#' character but the '#' will be added on change
|
|
25
|
-
*
|
|
26
|
-
* It is allowed to use single character form per component (#f00 instead of #ff0000)
|
|
27
|
-
* but it will always be written back as #ff0000 on change
|
|
28
|
-
*/
|
|
29
|
-
value?: V;
|
|
30
|
-
/**
|
|
31
|
-
* The format of the string value. Defaults to 'rgb'
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* This must be a combination of the letters `r`, `g`, `b` and `a`.
|
|
35
|
-
*
|
|
36
|
-
* A prefix of `#` indicates the input/output is a hex string. e.g. #rgba
|
|
37
|
-
*
|
|
38
|
-
* A prefix of `0x` indicates the input is a number. e.g. 0xrgba
|
|
39
|
-
*
|
|
40
|
-
* A prefix of `[]` indicates the input is an array of numbers. e.g. `[]rgba`
|
|
41
|
-
*
|
|
42
|
-
* If a prefix is missing `#` is assumed
|
|
43
|
-
*/
|
|
44
|
-
format?: string;
|
|
45
|
-
/**
|
|
46
|
-
* This is called when the control value has been changed.
|
|
47
|
-
*/
|
|
48
|
-
onInput?: (model: ColorPickerModel<T, V>, value: unknown) => void;
|
|
49
|
-
/**
|
|
50
|
-
* This is called once the control value is committed by the user.
|
|
51
|
-
*
|
|
52
|
-
* @remarks
|
|
53
|
-
* Unlike the `onInput` callback, this is not necessarily called for each value change.
|
|
54
|
-
*/
|
|
55
|
-
onChange?: (model: ColorPickerModel<T, V>, value: unknown) => void;
|
|
56
|
-
}
|
|
1
|
+
import { ComponentModel, ValueSource, ComponentAttrs } from '../../core';
|
|
2
|
+
/**
|
|
3
|
+
* Color picker component attributes
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type ColorPickerAttrs = ComponentAttrs<ColorPickerModel>;
|
|
8
|
+
/**
|
|
9
|
+
* Color picker component model
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface ColorPickerModel<T = unknown, V = number | string | number[]> extends ComponentModel, ValueSource<T, V> {
|
|
14
|
+
/**
|
|
15
|
+
* The type name of the control
|
|
16
|
+
*/
|
|
17
|
+
type: 'color-picker';
|
|
18
|
+
/**
|
|
19
|
+
* If `target` and `property` are not set, then this is used as the control value
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* The format is determined by the `format` property.
|
|
23
|
+
*
|
|
24
|
+
* It is allowed to omit the '#' character but the '#' will be added on change
|
|
25
|
+
*
|
|
26
|
+
* It is allowed to use single character form per component (#f00 instead of #ff0000)
|
|
27
|
+
* but it will always be written back as #ff0000 on change
|
|
28
|
+
*/
|
|
29
|
+
value?: V;
|
|
30
|
+
/**
|
|
31
|
+
* The format of the string value. Defaults to 'rgb'
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* This must be a combination of the letters `r`, `g`, `b` and `a`.
|
|
35
|
+
*
|
|
36
|
+
* A prefix of `#` indicates the input/output is a hex string. e.g. #rgba
|
|
37
|
+
*
|
|
38
|
+
* A prefix of `0x` indicates the input is a number. e.g. 0xrgba
|
|
39
|
+
*
|
|
40
|
+
* A prefix of `[]` indicates the input is an array of numbers. e.g. `[]rgba`
|
|
41
|
+
*
|
|
42
|
+
* If a prefix is missing `#` is assumed
|
|
43
|
+
*/
|
|
44
|
+
format?: string;
|
|
45
|
+
/**
|
|
46
|
+
* This is called when the control value has been changed.
|
|
47
|
+
*/
|
|
48
|
+
onInput?: (model: ColorPickerModel<T, V>, value: unknown) => void;
|
|
49
|
+
/**
|
|
50
|
+
* This is called once the control value is committed by the user.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Unlike the `onInput` callback, this is not necessarily called for each value change.
|
|
54
|
+
*/
|
|
55
|
+
onChange?: (model: ColorPickerModel<T, V>, value: unknown) => void;
|
|
56
|
+
}
|
|
57
57
|
//# sourceMappingURL=color-picker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-picker.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/controls/color-picker.ts"],"names":[],"mappings":"AAWA,OAAO,EAIL,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAA;AASnB;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"color-picker.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/controls/color-picker.ts"],"names":[],"mappings":"AAWA,OAAO,EAIL,cAAc,EACd,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAA;AASnB;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAA;AAE/D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAC3E,SAAQ,cAAc,EACpB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IACnB;;OAEG;IACH,IAAI,EAAE,cAAc,CAAA;IACpB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,CAAC,CAAA;IACT;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACjE;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnE"}
|