tweak-ui 0.4.2 → 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 -2380
- package/dist/tweak-ui.module.js.map +1 -1
- package/dist/tweak-ui.umd.js +1 -4403
- package/dist/tweak-ui.umd.js.map +1 -1
- package/package.json +25 -42
- package/dist/index.html +0 -1061
- 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
package/dist/tweak-ui.umd.js
CHANGED
|
@@ -1,4404 +1,2 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TweakUi = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function Vnode(tag, key, attrs, children, text, dom) {
|
|
8
|
-
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined}
|
|
9
|
-
}
|
|
10
|
-
Vnode.normalize = function(node) {
|
|
11
|
-
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
|
12
|
-
if (node == null || typeof node === "boolean") return null
|
|
13
|
-
if (typeof node === "object") return node
|
|
14
|
-
return Vnode("#", undefined, undefined, String(node), undefined, undefined)
|
|
15
|
-
};
|
|
16
|
-
Vnode.normalizeChildren = function(input) {
|
|
17
|
-
var children = [];
|
|
18
|
-
if (input.length) {
|
|
19
|
-
var isKeyed = input[0] != null && input[0].key != null;
|
|
20
|
-
// Note: this is a *very* perf-sensitive check.
|
|
21
|
-
// Fun fact: merging the loop like this is somehow faster than splitting
|
|
22
|
-
// it, noticeably so.
|
|
23
|
-
for (var i = 1; i < input.length; i++) {
|
|
24
|
-
if ((input[i] != null && input[i].key != null) !== isKeyed) {
|
|
25
|
-
throw new TypeError("Vnodes must either always have keys or never have keys!")
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
for (var i = 0; i < input.length; i++) {
|
|
29
|
-
children[i] = Vnode.normalize(input[i]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return children
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var vnode = Vnode;
|
|
36
|
-
|
|
37
|
-
// Call via `hyperscriptVnode.apply(startOffset, arguments)`
|
|
38
|
-
//
|
|
39
|
-
// The reason I do it this way, forwarding the arguments and passing the start
|
|
40
|
-
// offset in `this`, is so I don't have to create a temporary array in a
|
|
41
|
-
// performance-critical path.
|
|
42
|
-
//
|
|
43
|
-
// In native ES6, I'd instead add a final `...args` parameter to the
|
|
44
|
-
// `hyperscript` and `fragment` factories and define this as
|
|
45
|
-
// `hyperscriptVnode(...args)`, since modern engines do optimize that away. But
|
|
46
|
-
// ES5 (what Mithril requires thanks to IE support) doesn't give me that luxury,
|
|
47
|
-
// and engines aren't nearly intelligent enough to do either of these:
|
|
48
|
-
//
|
|
49
|
-
// 1. Elide the allocation for `[].slice.call(arguments, 1)` when it's passed to
|
|
50
|
-
// another function only to be indexed.
|
|
51
|
-
// 2. Elide an `arguments` allocation when it's passed to any function other
|
|
52
|
-
// than `Function.prototype.apply` or `Reflect.apply`.
|
|
53
|
-
//
|
|
54
|
-
// In ES6, it'd probably look closer to this (I'd need to profile it, though):
|
|
55
|
-
// module.exports = function(attrs, ...children) {
|
|
56
|
-
// if (attrs == null || typeof attrs === "object" && attrs.tag == null && !Array.isArray(attrs)) {
|
|
57
|
-
// if (children.length === 1 && Array.isArray(children[0])) children = children[0]
|
|
58
|
-
// } else {
|
|
59
|
-
// children = children.length === 0 && Array.isArray(attrs) ? attrs : [attrs, ...children]
|
|
60
|
-
// attrs = undefined
|
|
61
|
-
// }
|
|
62
|
-
//
|
|
63
|
-
// if (attrs == null) attrs = {}
|
|
64
|
-
// return Vnode("", attrs.key, attrs, children)
|
|
65
|
-
// }
|
|
66
|
-
var hyperscriptVnode = function() {
|
|
67
|
-
var attrs = arguments[this], start = this + 1, children;
|
|
68
|
-
|
|
69
|
-
if (attrs == null) {
|
|
70
|
-
attrs = {};
|
|
71
|
-
} else if (typeof attrs !== "object" || attrs.tag != null || Array.isArray(attrs)) {
|
|
72
|
-
attrs = {};
|
|
73
|
-
start = this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (arguments.length === start + 1) {
|
|
77
|
-
children = arguments[start];
|
|
78
|
-
if (!Array.isArray(children)) children = [children];
|
|
79
|
-
} else {
|
|
80
|
-
children = [];
|
|
81
|
-
while (start < arguments.length) children.push(arguments[start++]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return vnode("", attrs.key, attrs, children)
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g;
|
|
88
|
-
var selectorCache = {};
|
|
89
|
-
var hasOwn = {}.hasOwnProperty;
|
|
90
|
-
|
|
91
|
-
function isEmpty(object) {
|
|
92
|
-
for (var key in object) if (hasOwn.call(object, key)) return false
|
|
93
|
-
return true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function compileSelector(selector) {
|
|
97
|
-
var match, tag = "div", classes = [], attrs = {};
|
|
98
|
-
while (match = selectorParser.exec(selector)) {
|
|
99
|
-
var type = match[1], value = match[2];
|
|
100
|
-
if (type === "" && value !== "") tag = value;
|
|
101
|
-
else if (type === "#") attrs.id = value;
|
|
102
|
-
else if (type === ".") classes.push(value);
|
|
103
|
-
else if (match[3][0] === "[") {
|
|
104
|
-
var attrValue = match[6];
|
|
105
|
-
if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\");
|
|
106
|
-
if (match[4] === "class") classes.push(attrValue);
|
|
107
|
-
else attrs[match[4]] = attrValue === "" ? attrValue : attrValue || true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (classes.length > 0) attrs.className = classes.join(" ");
|
|
111
|
-
return selectorCache[selector] = {tag: tag, attrs: attrs}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function execSelector(state, vnode$1) {
|
|
115
|
-
var attrs = vnode$1.attrs;
|
|
116
|
-
var children = vnode.normalizeChildren(vnode$1.children);
|
|
117
|
-
var hasClass = hasOwn.call(attrs, "class");
|
|
118
|
-
var className = hasClass ? attrs.class : attrs.className;
|
|
119
|
-
|
|
120
|
-
vnode$1.tag = state.tag;
|
|
121
|
-
vnode$1.attrs = null;
|
|
122
|
-
vnode$1.children = undefined;
|
|
123
|
-
|
|
124
|
-
if (!isEmpty(state.attrs) && !isEmpty(attrs)) {
|
|
125
|
-
var newAttrs = {};
|
|
126
|
-
|
|
127
|
-
for (var key in attrs) {
|
|
128
|
-
if (hasOwn.call(attrs, key)) newAttrs[key] = attrs[key];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
attrs = newAttrs;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
for (var key in state.attrs) {
|
|
135
|
-
if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(attrs, key)){
|
|
136
|
-
attrs[key] = state.attrs[key];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (className != null || state.attrs.className != null) attrs.className =
|
|
140
|
-
className != null
|
|
141
|
-
? state.attrs.className != null
|
|
142
|
-
? String(state.attrs.className) + " " + String(className)
|
|
143
|
-
: className
|
|
144
|
-
: state.attrs.className != null
|
|
145
|
-
? state.attrs.className
|
|
146
|
-
: null;
|
|
147
|
-
|
|
148
|
-
if (hasClass) attrs.class = null;
|
|
149
|
-
|
|
150
|
-
for (var key in attrs) {
|
|
151
|
-
if (hasOwn.call(attrs, key) && key !== "key") {
|
|
152
|
-
vnode$1.attrs = attrs;
|
|
153
|
-
break
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (Array.isArray(children) && children.length === 1 && children[0] != null && children[0].tag === "#") {
|
|
158
|
-
vnode$1.text = children[0].children;
|
|
159
|
-
} else {
|
|
160
|
-
vnode$1.children = children;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return vnode$1
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function hyperscript(selector) {
|
|
167
|
-
if (selector == null || typeof selector !== "string" && typeof selector !== "function" && typeof selector.view !== "function") {
|
|
168
|
-
throw Error("The selector must be either a string or a component.");
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
var vnode$1 = hyperscriptVnode.apply(1, arguments);
|
|
172
|
-
|
|
173
|
-
if (typeof selector === "string") {
|
|
174
|
-
vnode$1.children = vnode.normalizeChildren(vnode$1.children);
|
|
175
|
-
if (selector !== "[") return execSelector(selectorCache[selector] || compileSelector(selector), vnode$1)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
vnode$1.tag = selector;
|
|
179
|
-
return vnode$1
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
var hyperscript_1$1 = hyperscript;
|
|
183
|
-
|
|
184
|
-
var trust = function(html) {
|
|
185
|
-
if (html == null) html = "";
|
|
186
|
-
return vnode("<", undefined, undefined, html, undefined, undefined)
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
var fragment = function() {
|
|
190
|
-
var vnode$1 = hyperscriptVnode.apply(0, arguments);
|
|
191
|
-
|
|
192
|
-
vnode$1.tag = "[";
|
|
193
|
-
vnode$1.children = vnode.normalizeChildren(vnode$1.children);
|
|
194
|
-
return vnode$1
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
hyperscript_1$1.trust = trust;
|
|
198
|
-
hyperscript_1$1.fragment = fragment;
|
|
199
|
-
|
|
200
|
-
var hyperscript_1 = hyperscript_1$1;
|
|
201
|
-
|
|
202
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
203
|
-
|
|
204
|
-
function createCommonjsModule(fn, module) {
|
|
205
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** @constructor */
|
|
209
|
-
var PromisePolyfill = function(executor) {
|
|
210
|
-
if (!(this instanceof PromisePolyfill)) throw new Error("Promise must be called with `new`")
|
|
211
|
-
if (typeof executor !== "function") throw new TypeError("executor must be a function")
|
|
212
|
-
|
|
213
|
-
var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false);
|
|
214
|
-
var instance = self._instance = {resolvers: resolvers, rejectors: rejectors};
|
|
215
|
-
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout;
|
|
216
|
-
function handler(list, shouldAbsorb) {
|
|
217
|
-
return function execute(value) {
|
|
218
|
-
var then;
|
|
219
|
-
try {
|
|
220
|
-
if (shouldAbsorb && value != null && (typeof value === "object" || typeof value === "function") && typeof (then = value.then) === "function") {
|
|
221
|
-
if (value === self) throw new TypeError("Promise can't be resolved w/ itself")
|
|
222
|
-
executeOnce(then.bind(value));
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
callAsync(function() {
|
|
226
|
-
if (!shouldAbsorb && list.length === 0) console.error("Possible unhandled promise rejection:", value);
|
|
227
|
-
for (var i = 0; i < list.length; i++) list[i](value);
|
|
228
|
-
resolvers.length = 0, rejectors.length = 0;
|
|
229
|
-
instance.state = shouldAbsorb;
|
|
230
|
-
instance.retry = function() {execute(value);};
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
catch (e) {
|
|
235
|
-
rejectCurrent(e);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function executeOnce(then) {
|
|
240
|
-
var runs = 0;
|
|
241
|
-
function run(fn) {
|
|
242
|
-
return function(value) {
|
|
243
|
-
if (runs++ > 0) return
|
|
244
|
-
fn(value);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
var onerror = run(rejectCurrent);
|
|
248
|
-
try {then(run(resolveCurrent), onerror);} catch (e) {onerror(e);}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
executeOnce(executor);
|
|
252
|
-
};
|
|
253
|
-
PromisePolyfill.prototype.then = function(onFulfilled, onRejection) {
|
|
254
|
-
var self = this, instance = self._instance;
|
|
255
|
-
function handle(callback, list, next, state) {
|
|
256
|
-
list.push(function(value) {
|
|
257
|
-
if (typeof callback !== "function") next(value);
|
|
258
|
-
else try {resolveNext(callback(value));} catch (e) {if (rejectNext) rejectNext(e);}
|
|
259
|
-
});
|
|
260
|
-
if (typeof instance.retry === "function" && state === instance.state) instance.retry();
|
|
261
|
-
}
|
|
262
|
-
var resolveNext, rejectNext;
|
|
263
|
-
var promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject;});
|
|
264
|
-
handle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false);
|
|
265
|
-
return promise
|
|
266
|
-
};
|
|
267
|
-
PromisePolyfill.prototype.catch = function(onRejection) {
|
|
268
|
-
return this.then(null, onRejection)
|
|
269
|
-
};
|
|
270
|
-
PromisePolyfill.prototype.finally = function(callback) {
|
|
271
|
-
return this.then(
|
|
272
|
-
function(value) {
|
|
273
|
-
return PromisePolyfill.resolve(callback()).then(function() {
|
|
274
|
-
return value
|
|
275
|
-
})
|
|
276
|
-
},
|
|
277
|
-
function(reason) {
|
|
278
|
-
return PromisePolyfill.resolve(callback()).then(function() {
|
|
279
|
-
return PromisePolyfill.reject(reason);
|
|
280
|
-
})
|
|
281
|
-
}
|
|
282
|
-
)
|
|
283
|
-
};
|
|
284
|
-
PromisePolyfill.resolve = function(value) {
|
|
285
|
-
if (value instanceof PromisePolyfill) return value
|
|
286
|
-
return new PromisePolyfill(function(resolve) {resolve(value);})
|
|
287
|
-
};
|
|
288
|
-
PromisePolyfill.reject = function(value) {
|
|
289
|
-
return new PromisePolyfill(function(resolve, reject) {reject(value);})
|
|
290
|
-
};
|
|
291
|
-
PromisePolyfill.all = function(list) {
|
|
292
|
-
return new PromisePolyfill(function(resolve, reject) {
|
|
293
|
-
var total = list.length, count = 0, values = [];
|
|
294
|
-
if (list.length === 0) resolve([]);
|
|
295
|
-
else for (var i = 0; i < list.length; i++) {
|
|
296
|
-
(function(i) {
|
|
297
|
-
function consume(value) {
|
|
298
|
-
count++;
|
|
299
|
-
values[i] = value;
|
|
300
|
-
if (count === total) resolve(values);
|
|
301
|
-
}
|
|
302
|
-
if (list[i] != null && (typeof list[i] === "object" || typeof list[i] === "function") && typeof list[i].then === "function") {
|
|
303
|
-
list[i].then(consume, reject);
|
|
304
|
-
}
|
|
305
|
-
else consume(list[i]);
|
|
306
|
-
})(i);
|
|
307
|
-
}
|
|
308
|
-
})
|
|
309
|
-
};
|
|
310
|
-
PromisePolyfill.race = function(list) {
|
|
311
|
-
return new PromisePolyfill(function(resolve, reject) {
|
|
312
|
-
for (var i = 0; i < list.length; i++) {
|
|
313
|
-
list[i].then(resolve, reject);
|
|
314
|
-
}
|
|
315
|
-
})
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
var polyfill = PromisePolyfill;
|
|
319
|
-
|
|
320
|
-
var promise = createCommonjsModule(function (module) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (typeof window !== "undefined") {
|
|
325
|
-
if (typeof window.Promise === "undefined") {
|
|
326
|
-
window.Promise = polyfill;
|
|
327
|
-
} else if (!window.Promise.prototype.finally) {
|
|
328
|
-
window.Promise.prototype.finally = polyfill.prototype.finally;
|
|
329
|
-
}
|
|
330
|
-
module.exports = window.Promise;
|
|
331
|
-
} else if (typeof commonjsGlobal !== "undefined") {
|
|
332
|
-
if (typeof commonjsGlobal.Promise === "undefined") {
|
|
333
|
-
commonjsGlobal.Promise = polyfill;
|
|
334
|
-
} else if (!commonjsGlobal.Promise.prototype.finally) {
|
|
335
|
-
commonjsGlobal.Promise.prototype.finally = polyfill.prototype.finally;
|
|
336
|
-
}
|
|
337
|
-
module.exports = commonjsGlobal.Promise;
|
|
338
|
-
} else {
|
|
339
|
-
module.exports = polyfill;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
var render$1 = function($window) {
|
|
344
|
-
var $doc = $window && $window.document;
|
|
345
|
-
var currentRedraw;
|
|
346
|
-
|
|
347
|
-
var nameSpace = {
|
|
348
|
-
svg: "http://www.w3.org/2000/svg",
|
|
349
|
-
math: "http://www.w3.org/1998/Math/MathML"
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
function getNameSpace(vnode) {
|
|
353
|
-
return vnode.attrs && vnode.attrs.xmlns || nameSpace[vnode.tag]
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
//sanity check to discourage people from doing `vnode.state = ...`
|
|
357
|
-
function checkState(vnode, original) {
|
|
358
|
-
if (vnode.state !== original) throw new Error("`vnode.state` must not be modified")
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
//Note: the hook is passed as the `this` argument to allow proxying the
|
|
362
|
-
//arguments without requiring a full array allocation to do so. It also
|
|
363
|
-
//takes advantage of the fact the current `vnode` is the first argument in
|
|
364
|
-
//all lifecycle methods.
|
|
365
|
-
function callHook(vnode) {
|
|
366
|
-
var original = vnode.state;
|
|
367
|
-
try {
|
|
368
|
-
return this.apply(original, arguments)
|
|
369
|
-
} finally {
|
|
370
|
-
checkState(vnode, original);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// IE11 (at least) throws an UnspecifiedError when accessing document.activeElement when
|
|
375
|
-
// inside an iframe. Catch and swallow this error, and heavy-handidly return null.
|
|
376
|
-
function activeElement() {
|
|
377
|
-
try {
|
|
378
|
-
return $doc.activeElement
|
|
379
|
-
} catch (e) {
|
|
380
|
-
return null
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
//create
|
|
384
|
-
function createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {
|
|
385
|
-
for (var i = start; i < end; i++) {
|
|
386
|
-
var vnode = vnodes[i];
|
|
387
|
-
if (vnode != null) {
|
|
388
|
-
createNode(parent, vnode, hooks, ns, nextSibling);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function createNode(parent, vnode, hooks, ns, nextSibling) {
|
|
393
|
-
var tag = vnode.tag;
|
|
394
|
-
if (typeof tag === "string") {
|
|
395
|
-
vnode.state = {};
|
|
396
|
-
if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks);
|
|
397
|
-
switch (tag) {
|
|
398
|
-
case "#": createText(parent, vnode, nextSibling); break
|
|
399
|
-
case "<": createHTML(parent, vnode, ns, nextSibling); break
|
|
400
|
-
case "[": createFragment(parent, vnode, hooks, ns, nextSibling); break
|
|
401
|
-
default: createElement(parent, vnode, hooks, ns, nextSibling);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
else createComponent(parent, vnode, hooks, ns, nextSibling);
|
|
405
|
-
}
|
|
406
|
-
function createText(parent, vnode, nextSibling) {
|
|
407
|
-
vnode.dom = $doc.createTextNode(vnode.children);
|
|
408
|
-
insertNode(parent, vnode.dom, nextSibling);
|
|
409
|
-
}
|
|
410
|
-
var possibleParents = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"};
|
|
411
|
-
function createHTML(parent, vnode, ns, nextSibling) {
|
|
412
|
-
var match = vnode.children.match(/^\s*?<(\w+)/im) || [];
|
|
413
|
-
// not using the proper parent makes the child element(s) vanish.
|
|
414
|
-
// var div = document.createElement("div")
|
|
415
|
-
// div.innerHTML = "<td>i</td><td>j</td>"
|
|
416
|
-
// console.log(div.innerHTML)
|
|
417
|
-
// --> "ij", no <td> in sight.
|
|
418
|
-
var temp = $doc.createElement(possibleParents[match[1]] || "div");
|
|
419
|
-
if (ns === "http://www.w3.org/2000/svg") {
|
|
420
|
-
temp.innerHTML = "<svg xmlns=\"http://www.w3.org/2000/svg\">" + vnode.children + "</svg>";
|
|
421
|
-
temp = temp.firstChild;
|
|
422
|
-
} else {
|
|
423
|
-
temp.innerHTML = vnode.children;
|
|
424
|
-
}
|
|
425
|
-
vnode.dom = temp.firstChild;
|
|
426
|
-
vnode.domSize = temp.childNodes.length;
|
|
427
|
-
// Capture nodes to remove, so we don't confuse them.
|
|
428
|
-
vnode.instance = [];
|
|
429
|
-
var fragment = $doc.createDocumentFragment();
|
|
430
|
-
var child;
|
|
431
|
-
while (child = temp.firstChild) {
|
|
432
|
-
vnode.instance.push(child);
|
|
433
|
-
fragment.appendChild(child);
|
|
434
|
-
}
|
|
435
|
-
insertNode(parent, fragment, nextSibling);
|
|
436
|
-
}
|
|
437
|
-
function createFragment(parent, vnode, hooks, ns, nextSibling) {
|
|
438
|
-
var fragment = $doc.createDocumentFragment();
|
|
439
|
-
if (vnode.children != null) {
|
|
440
|
-
var children = vnode.children;
|
|
441
|
-
createNodes(fragment, children, 0, children.length, hooks, null, ns);
|
|
442
|
-
}
|
|
443
|
-
vnode.dom = fragment.firstChild;
|
|
444
|
-
vnode.domSize = fragment.childNodes.length;
|
|
445
|
-
insertNode(parent, fragment, nextSibling);
|
|
446
|
-
}
|
|
447
|
-
function createElement(parent, vnode$1, hooks, ns, nextSibling) {
|
|
448
|
-
var tag = vnode$1.tag;
|
|
449
|
-
var attrs = vnode$1.attrs;
|
|
450
|
-
var is = attrs && attrs.is;
|
|
451
|
-
|
|
452
|
-
ns = getNameSpace(vnode$1) || ns;
|
|
453
|
-
|
|
454
|
-
var element = ns ?
|
|
455
|
-
is ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) :
|
|
456
|
-
is ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag);
|
|
457
|
-
vnode$1.dom = element;
|
|
458
|
-
|
|
459
|
-
if (attrs != null) {
|
|
460
|
-
setAttrs(vnode$1, attrs, ns);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
insertNode(parent, element, nextSibling);
|
|
464
|
-
|
|
465
|
-
if (!maybeSetContentEditable(vnode$1)) {
|
|
466
|
-
if (vnode$1.text != null) {
|
|
467
|
-
if (vnode$1.text !== "") element.textContent = vnode$1.text;
|
|
468
|
-
else vnode$1.children = [vnode("#", undefined, undefined, vnode$1.text, undefined, undefined)];
|
|
469
|
-
}
|
|
470
|
-
if (vnode$1.children != null) {
|
|
471
|
-
var children = vnode$1.children;
|
|
472
|
-
createNodes(element, children, 0, children.length, hooks, null, ns);
|
|
473
|
-
if (vnode$1.tag === "select" && attrs != null) setLateSelectAttrs(vnode$1, attrs);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function initComponent(vnode$1, hooks) {
|
|
478
|
-
var sentinel;
|
|
479
|
-
if (typeof vnode$1.tag.view === "function") {
|
|
480
|
-
vnode$1.state = Object.create(vnode$1.tag);
|
|
481
|
-
sentinel = vnode$1.state.view;
|
|
482
|
-
if (sentinel.$$reentrantLock$$ != null) return
|
|
483
|
-
sentinel.$$reentrantLock$$ = true;
|
|
484
|
-
} else {
|
|
485
|
-
vnode$1.state = void 0;
|
|
486
|
-
sentinel = vnode$1.tag;
|
|
487
|
-
if (sentinel.$$reentrantLock$$ != null) return
|
|
488
|
-
sentinel.$$reentrantLock$$ = true;
|
|
489
|
-
vnode$1.state = (vnode$1.tag.prototype != null && typeof vnode$1.tag.prototype.view === "function") ? new vnode$1.tag(vnode$1) : vnode$1.tag(vnode$1);
|
|
490
|
-
}
|
|
491
|
-
initLifecycle(vnode$1.state, vnode$1, hooks);
|
|
492
|
-
if (vnode$1.attrs != null) initLifecycle(vnode$1.attrs, vnode$1, hooks);
|
|
493
|
-
vnode$1.instance = vnode.normalize(callHook.call(vnode$1.state.view, vnode$1));
|
|
494
|
-
if (vnode$1.instance === vnode$1) throw Error("A view cannot return the vnode it received as argument")
|
|
495
|
-
sentinel.$$reentrantLock$$ = null;
|
|
496
|
-
}
|
|
497
|
-
function createComponent(parent, vnode, hooks, ns, nextSibling) {
|
|
498
|
-
initComponent(vnode, hooks);
|
|
499
|
-
if (vnode.instance != null) {
|
|
500
|
-
createNode(parent, vnode.instance, hooks, ns, nextSibling);
|
|
501
|
-
vnode.dom = vnode.instance.dom;
|
|
502
|
-
vnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0;
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
vnode.domSize = 0;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
//update
|
|
510
|
-
/**
|
|
511
|
-
* @param {Element|Fragment} parent - the parent element
|
|
512
|
-
* @param {Vnode[] | null} old - the list of vnodes of the last `render()` call for
|
|
513
|
-
* this part of the tree
|
|
514
|
-
* @param {Vnode[] | null} vnodes - as above, but for the current `render()` call.
|
|
515
|
-
* @param {Function[]} hooks - an accumulator of post-render hooks (oncreate/onupdate)
|
|
516
|
-
* @param {Element | null} nextSibling - the next DOM node if we're dealing with a
|
|
517
|
-
* fragment that is not the last item in its
|
|
518
|
-
* parent
|
|
519
|
-
* @param {'svg' | 'math' | String | null} ns) - the current XML namespace, if any
|
|
520
|
-
* @returns void
|
|
521
|
-
*/
|
|
522
|
-
// This function diffs and patches lists of vnodes, both keyed and unkeyed.
|
|
523
|
-
//
|
|
524
|
-
// We will:
|
|
525
|
-
//
|
|
526
|
-
// 1. describe its general structure
|
|
527
|
-
// 2. focus on the diff algorithm optimizations
|
|
528
|
-
// 3. discuss DOM node operations.
|
|
529
|
-
|
|
530
|
-
// ## Overview:
|
|
531
|
-
//
|
|
532
|
-
// The updateNodes() function:
|
|
533
|
-
// - deals with trivial cases
|
|
534
|
-
// - determines whether the lists are keyed or unkeyed based on the first non-null node
|
|
535
|
-
// of each list.
|
|
536
|
-
// - diffs them and patches the DOM if needed (that's the brunt of the code)
|
|
537
|
-
// - manages the leftovers: after diffing, are there:
|
|
538
|
-
// - old nodes left to remove?
|
|
539
|
-
// - new nodes to insert?
|
|
540
|
-
// deal with them!
|
|
541
|
-
//
|
|
542
|
-
// The lists are only iterated over once, with an exception for the nodes in `old` that
|
|
543
|
-
// are visited in the fourth part of the diff and in the `removeNodes` loop.
|
|
544
|
-
|
|
545
|
-
// ## Diffing
|
|
546
|
-
//
|
|
547
|
-
// Reading https://github.com/localvoid/ivi/blob/ddc09d06abaef45248e6133f7040d00d3c6be853/packages/ivi/src/vdom/implementation.ts#L617-L837
|
|
548
|
-
// may be good for context on longest increasing subsequence-based logic for moving nodes.
|
|
549
|
-
//
|
|
550
|
-
// In order to diff keyed lists, one has to
|
|
551
|
-
//
|
|
552
|
-
// 1) match nodes in both lists, per key, and update them accordingly
|
|
553
|
-
// 2) create the nodes present in the new list, but absent in the old one
|
|
554
|
-
// 3) remove the nodes present in the old list, but absent in the new one
|
|
555
|
-
// 4) figure out what nodes in 1) to move in order to minimize the DOM operations.
|
|
556
|
-
//
|
|
557
|
-
// To achieve 1) one can create a dictionary of keys => index (for the old list), then iterate
|
|
558
|
-
// over the new list and for each new vnode, find the corresponding vnode in the old list using
|
|
559
|
-
// the map.
|
|
560
|
-
// 2) is achieved in the same step: if a new node has no corresponding entry in the map, it is new
|
|
561
|
-
// and must be created.
|
|
562
|
-
// For the removals, we actually remove the nodes that have been updated from the old list.
|
|
563
|
-
// The nodes that remain in that list after 1) and 2) have been performed can be safely removed.
|
|
564
|
-
// The fourth step is a bit more complex and relies on the longest increasing subsequence (LIS)
|
|
565
|
-
// algorithm.
|
|
566
|
-
//
|
|
567
|
-
// the longest increasing subsequence is the list of nodes that can remain in place. Imagine going
|
|
568
|
-
// from `1,2,3,4,5` to `4,5,1,2,3` where the numbers are not necessarily the keys, but the indices
|
|
569
|
-
// corresponding to the keyed nodes in the old list (keyed nodes `e,d,c,b,a` => `b,a,e,d,c` would
|
|
570
|
-
// match the above lists, for example).
|
|
571
|
-
//
|
|
572
|
-
// In there are two increasing subsequences: `4,5` and `1,2,3`, the latter being the longest. We
|
|
573
|
-
// can update those nodes without moving them, and only call `insertNode` on `4` and `5`.
|
|
574
|
-
//
|
|
575
|
-
// @localvoid adapted the algo to also support node deletions and insertions (the `lis` is actually
|
|
576
|
-
// the longest increasing subsequence *of old nodes still present in the new list*).
|
|
577
|
-
//
|
|
578
|
-
// It is a general algorithm that is fireproof in all circumstances, but it requires the allocation
|
|
579
|
-
// and the construction of a `key => oldIndex` map, and three arrays (one with `newIndex => oldIndex`,
|
|
580
|
-
// the `LIS` and a temporary one to create the LIS).
|
|
581
|
-
//
|
|
582
|
-
// So we cheat where we can: if the tails of the lists are identical, they are guaranteed to be part of
|
|
583
|
-
// the LIS and can be updated without moving them.
|
|
584
|
-
//
|
|
585
|
-
// If two nodes are swapped, they are guaranteed not to be part of the LIS, and must be moved (with
|
|
586
|
-
// the exception of the last node if the list is fully reversed).
|
|
587
|
-
//
|
|
588
|
-
// ## Finding the next sibling.
|
|
589
|
-
//
|
|
590
|
-
// `updateNode()` and `createNode()` expect a nextSibling parameter to perform DOM operations.
|
|
591
|
-
// When the list is being traversed top-down, at any index, the DOM nodes up to the previous
|
|
592
|
-
// vnode reflect the content of the new list, whereas the rest of the DOM nodes reflect the old
|
|
593
|
-
// list. The next sibling must be looked for in the old list using `getNextSibling(... oldStart + 1 ...)`.
|
|
594
|
-
//
|
|
595
|
-
// In the other scenarios (swaps, upwards traversal, map-based diff),
|
|
596
|
-
// the new vnodes list is traversed upwards. The DOM nodes at the bottom of the list reflect the
|
|
597
|
-
// bottom part of the new vnodes list, and we can use the `v.dom` value of the previous node
|
|
598
|
-
// as the next sibling (cached in the `nextSibling` variable).
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
// ## DOM node moves
|
|
602
|
-
//
|
|
603
|
-
// In most scenarios `updateNode()` and `createNode()` perform the DOM operations. However,
|
|
604
|
-
// this is not the case if the node moved (second and fourth part of the diff algo). We move
|
|
605
|
-
// the old DOM nodes before updateNode runs because it enables us to use the cached `nextSibling`
|
|
606
|
-
// variable rather than fetching it using `getNextSibling()`.
|
|
607
|
-
//
|
|
608
|
-
// The fourth part of the diff currently inserts nodes unconditionally, leading to issues
|
|
609
|
-
// like #1791 and #1999. We need to be smarter about those situations where adjascent old
|
|
610
|
-
// nodes remain together in the new list in a way that isn't covered by parts one and
|
|
611
|
-
// three of the diff algo.
|
|
612
|
-
|
|
613
|
-
function updateNodes(parent, old, vnodes, hooks, nextSibling, ns) {
|
|
614
|
-
if (old === vnodes || old == null && vnodes == null) return
|
|
615
|
-
else if (old == null || old.length === 0) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, ns);
|
|
616
|
-
else if (vnodes == null || vnodes.length === 0) removeNodes(parent, old, 0, old.length);
|
|
617
|
-
else {
|
|
618
|
-
var isOldKeyed = old[0] != null && old[0].key != null;
|
|
619
|
-
var isKeyed = vnodes[0] != null && vnodes[0].key != null;
|
|
620
|
-
var start = 0, oldStart = 0;
|
|
621
|
-
if (!isOldKeyed) while (oldStart < old.length && old[oldStart] == null) oldStart++;
|
|
622
|
-
if (!isKeyed) while (start < vnodes.length && vnodes[start] == null) start++;
|
|
623
|
-
if (isKeyed === null && isOldKeyed == null) return // both lists are full of nulls
|
|
624
|
-
if (isOldKeyed !== isKeyed) {
|
|
625
|
-
removeNodes(parent, old, oldStart, old.length);
|
|
626
|
-
createNodes(parent, vnodes, start, vnodes.length, hooks, nextSibling, ns);
|
|
627
|
-
} else if (!isKeyed) {
|
|
628
|
-
// Don't index past the end of either list (causes deopts).
|
|
629
|
-
var commonLength = old.length < vnodes.length ? old.length : vnodes.length;
|
|
630
|
-
// Rewind if necessary to the first non-null index on either side.
|
|
631
|
-
// We could alternatively either explicitly create or remove nodes when `start !== oldStart`
|
|
632
|
-
// but that would be optimizing for sparse lists which are more rare than dense ones.
|
|
633
|
-
start = start < oldStart ? start : oldStart;
|
|
634
|
-
for (; start < commonLength; start++) {
|
|
635
|
-
o = old[start];
|
|
636
|
-
v = vnodes[start];
|
|
637
|
-
if (o === v || o == null && v == null) continue
|
|
638
|
-
else if (o == null) createNode(parent, v, hooks, ns, getNextSibling(old, start + 1, nextSibling));
|
|
639
|
-
else if (v == null) removeNode(parent, o);
|
|
640
|
-
else updateNode(parent, o, v, hooks, getNextSibling(old, start + 1, nextSibling), ns);
|
|
641
|
-
}
|
|
642
|
-
if (old.length > commonLength) removeNodes(parent, old, start, old.length);
|
|
643
|
-
if (vnodes.length > commonLength) createNodes(parent, vnodes, start, vnodes.length, hooks, nextSibling, ns);
|
|
644
|
-
} else {
|
|
645
|
-
// keyed diff
|
|
646
|
-
var oldEnd = old.length - 1, end = vnodes.length - 1, map, o, v, oe, ve, topSibling;
|
|
647
|
-
|
|
648
|
-
// bottom-up
|
|
649
|
-
while (oldEnd >= oldStart && end >= start) {
|
|
650
|
-
oe = old[oldEnd];
|
|
651
|
-
ve = vnodes[end];
|
|
652
|
-
if (oe.key !== ve.key) break
|
|
653
|
-
if (oe !== ve) updateNode(parent, oe, ve, hooks, nextSibling, ns);
|
|
654
|
-
if (ve.dom != null) nextSibling = ve.dom;
|
|
655
|
-
oldEnd--, end--;
|
|
656
|
-
}
|
|
657
|
-
// top-down
|
|
658
|
-
while (oldEnd >= oldStart && end >= start) {
|
|
659
|
-
o = old[oldStart];
|
|
660
|
-
v = vnodes[start];
|
|
661
|
-
if (o.key !== v.key) break
|
|
662
|
-
oldStart++, start++;
|
|
663
|
-
if (o !== v) updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), ns);
|
|
664
|
-
}
|
|
665
|
-
// swaps and list reversals
|
|
666
|
-
while (oldEnd >= oldStart && end >= start) {
|
|
667
|
-
if (start === end) break
|
|
668
|
-
if (o.key !== ve.key || oe.key !== v.key) break
|
|
669
|
-
topSibling = getNextSibling(old, oldStart, nextSibling);
|
|
670
|
-
moveNodes(parent, oe, topSibling);
|
|
671
|
-
if (oe !== v) updateNode(parent, oe, v, hooks, topSibling, ns);
|
|
672
|
-
if (++start <= --end) moveNodes(parent, o, nextSibling);
|
|
673
|
-
if (o !== ve) updateNode(parent, o, ve, hooks, nextSibling, ns);
|
|
674
|
-
if (ve.dom != null) nextSibling = ve.dom;
|
|
675
|
-
oldStart++; oldEnd--;
|
|
676
|
-
oe = old[oldEnd];
|
|
677
|
-
ve = vnodes[end];
|
|
678
|
-
o = old[oldStart];
|
|
679
|
-
v = vnodes[start];
|
|
680
|
-
}
|
|
681
|
-
// bottom up once again
|
|
682
|
-
while (oldEnd >= oldStart && end >= start) {
|
|
683
|
-
if (oe.key !== ve.key) break
|
|
684
|
-
if (oe !== ve) updateNode(parent, oe, ve, hooks, nextSibling, ns);
|
|
685
|
-
if (ve.dom != null) nextSibling = ve.dom;
|
|
686
|
-
oldEnd--, end--;
|
|
687
|
-
oe = old[oldEnd];
|
|
688
|
-
ve = vnodes[end];
|
|
689
|
-
}
|
|
690
|
-
if (start > end) removeNodes(parent, old, oldStart, oldEnd + 1);
|
|
691
|
-
else if (oldStart > oldEnd) createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns);
|
|
692
|
-
else {
|
|
693
|
-
// inspired by ivi https://github.com/ivijs/ivi/ by Boris Kaul
|
|
694
|
-
var originalNextSibling = nextSibling, vnodesLength = end - start + 1, oldIndices = new Array(vnodesLength), li=0, i=0, pos = 2147483647, matched = 0, map, lisIndices;
|
|
695
|
-
for (i = 0; i < vnodesLength; i++) oldIndices[i] = -1;
|
|
696
|
-
for (i = end; i >= start; i--) {
|
|
697
|
-
if (map == null) map = getKeyMap(old, oldStart, oldEnd + 1);
|
|
698
|
-
ve = vnodes[i];
|
|
699
|
-
var oldIndex = map[ve.key];
|
|
700
|
-
if (oldIndex != null) {
|
|
701
|
-
pos = (oldIndex < pos) ? oldIndex : -1; // becomes -1 if nodes were re-ordered
|
|
702
|
-
oldIndices[i-start] = oldIndex;
|
|
703
|
-
oe = old[oldIndex];
|
|
704
|
-
old[oldIndex] = null;
|
|
705
|
-
if (oe !== ve) updateNode(parent, oe, ve, hooks, nextSibling, ns);
|
|
706
|
-
if (ve.dom != null) nextSibling = ve.dom;
|
|
707
|
-
matched++;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
nextSibling = originalNextSibling;
|
|
711
|
-
if (matched !== oldEnd - oldStart + 1) removeNodes(parent, old, oldStart, oldEnd + 1);
|
|
712
|
-
if (matched === 0) createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns);
|
|
713
|
-
else {
|
|
714
|
-
if (pos === -1) {
|
|
715
|
-
// the indices of the indices of the items that are part of the
|
|
716
|
-
// longest increasing subsequence in the oldIndices list
|
|
717
|
-
lisIndices = makeLisIndices(oldIndices);
|
|
718
|
-
li = lisIndices.length - 1;
|
|
719
|
-
for (i = end; i >= start; i--) {
|
|
720
|
-
v = vnodes[i];
|
|
721
|
-
if (oldIndices[i-start] === -1) createNode(parent, v, hooks, ns, nextSibling);
|
|
722
|
-
else {
|
|
723
|
-
if (lisIndices[li] === i - start) li--;
|
|
724
|
-
else moveNodes(parent, v, nextSibling);
|
|
725
|
-
}
|
|
726
|
-
if (v.dom != null) nextSibling = vnodes[i].dom;
|
|
727
|
-
}
|
|
728
|
-
} else {
|
|
729
|
-
for (i = end; i >= start; i--) {
|
|
730
|
-
v = vnodes[i];
|
|
731
|
-
if (oldIndices[i-start] === -1) createNode(parent, v, hooks, ns, nextSibling);
|
|
732
|
-
if (v.dom != null) nextSibling = vnodes[i].dom;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
function updateNode(parent, old, vnode, hooks, nextSibling, ns) {
|
|
741
|
-
var oldTag = old.tag, tag = vnode.tag;
|
|
742
|
-
if (oldTag === tag) {
|
|
743
|
-
vnode.state = old.state;
|
|
744
|
-
vnode.events = old.events;
|
|
745
|
-
if (shouldNotUpdate(vnode, old)) return
|
|
746
|
-
if (typeof oldTag === "string") {
|
|
747
|
-
if (vnode.attrs != null) {
|
|
748
|
-
updateLifecycle(vnode.attrs, vnode, hooks);
|
|
749
|
-
}
|
|
750
|
-
switch (oldTag) {
|
|
751
|
-
case "#": updateText(old, vnode); break
|
|
752
|
-
case "<": updateHTML(parent, old, vnode, ns, nextSibling); break
|
|
753
|
-
case "[": updateFragment(parent, old, vnode, hooks, nextSibling, ns); break
|
|
754
|
-
default: updateElement(old, vnode, hooks, ns);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
else updateComponent(parent, old, vnode, hooks, nextSibling, ns);
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
760
|
-
removeNode(parent, old);
|
|
761
|
-
createNode(parent, vnode, hooks, ns, nextSibling);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
function updateText(old, vnode) {
|
|
765
|
-
if (old.children.toString() !== vnode.children.toString()) {
|
|
766
|
-
old.dom.nodeValue = vnode.children;
|
|
767
|
-
}
|
|
768
|
-
vnode.dom = old.dom;
|
|
769
|
-
}
|
|
770
|
-
function updateHTML(parent, old, vnode, ns, nextSibling) {
|
|
771
|
-
if (old.children !== vnode.children) {
|
|
772
|
-
removeHTML(parent, old);
|
|
773
|
-
createHTML(parent, vnode, ns, nextSibling);
|
|
774
|
-
}
|
|
775
|
-
else {
|
|
776
|
-
vnode.dom = old.dom;
|
|
777
|
-
vnode.domSize = old.domSize;
|
|
778
|
-
vnode.instance = old.instance;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
|
|
782
|
-
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns);
|
|
783
|
-
var domSize = 0, children = vnode.children;
|
|
784
|
-
vnode.dom = null;
|
|
785
|
-
if (children != null) {
|
|
786
|
-
for (var i = 0; i < children.length; i++) {
|
|
787
|
-
var child = children[i];
|
|
788
|
-
if (child != null && child.dom != null) {
|
|
789
|
-
if (vnode.dom == null) vnode.dom = child.dom;
|
|
790
|
-
domSize += child.domSize || 1;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
if (domSize !== 1) vnode.domSize = domSize;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
function updateElement(old, vnode$1, hooks, ns) {
|
|
797
|
-
var element = vnode$1.dom = old.dom;
|
|
798
|
-
ns = getNameSpace(vnode$1) || ns;
|
|
799
|
-
|
|
800
|
-
if (vnode$1.tag === "textarea") {
|
|
801
|
-
if (vnode$1.attrs == null) vnode$1.attrs = {};
|
|
802
|
-
if (vnode$1.text != null) {
|
|
803
|
-
vnode$1.attrs.value = vnode$1.text; //FIXME handle multiple children
|
|
804
|
-
vnode$1.text = undefined;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
updateAttrs(vnode$1, old.attrs, vnode$1.attrs, ns);
|
|
808
|
-
if (!maybeSetContentEditable(vnode$1)) {
|
|
809
|
-
if (old.text != null && vnode$1.text != null && vnode$1.text !== "") {
|
|
810
|
-
if (old.text.toString() !== vnode$1.text.toString()) old.dom.firstChild.nodeValue = vnode$1.text;
|
|
811
|
-
}
|
|
812
|
-
else {
|
|
813
|
-
if (old.text != null) old.children = [vnode("#", undefined, undefined, old.text, undefined, old.dom.firstChild)];
|
|
814
|
-
if (vnode$1.text != null) vnode$1.children = [vnode("#", undefined, undefined, vnode$1.text, undefined, undefined)];
|
|
815
|
-
updateNodes(element, old.children, vnode$1.children, hooks, null, ns);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
function updateComponent(parent, old, vnode$1, hooks, nextSibling, ns) {
|
|
820
|
-
vnode$1.instance = vnode.normalize(callHook.call(vnode$1.state.view, vnode$1));
|
|
821
|
-
if (vnode$1.instance === vnode$1) throw Error("A view cannot return the vnode it received as argument")
|
|
822
|
-
updateLifecycle(vnode$1.state, vnode$1, hooks);
|
|
823
|
-
if (vnode$1.attrs != null) updateLifecycle(vnode$1.attrs, vnode$1, hooks);
|
|
824
|
-
if (vnode$1.instance != null) {
|
|
825
|
-
if (old.instance == null) createNode(parent, vnode$1.instance, hooks, ns, nextSibling);
|
|
826
|
-
else updateNode(parent, old.instance, vnode$1.instance, hooks, nextSibling, ns);
|
|
827
|
-
vnode$1.dom = vnode$1.instance.dom;
|
|
828
|
-
vnode$1.domSize = vnode$1.instance.domSize;
|
|
829
|
-
}
|
|
830
|
-
else if (old.instance != null) {
|
|
831
|
-
removeNode(parent, old.instance);
|
|
832
|
-
vnode$1.dom = undefined;
|
|
833
|
-
vnode$1.domSize = 0;
|
|
834
|
-
}
|
|
835
|
-
else {
|
|
836
|
-
vnode$1.dom = old.dom;
|
|
837
|
-
vnode$1.domSize = old.domSize;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
function getKeyMap(vnodes, start, end) {
|
|
841
|
-
var map = Object.create(null);
|
|
842
|
-
for (; start < end; start++) {
|
|
843
|
-
var vnode = vnodes[start];
|
|
844
|
-
if (vnode != null) {
|
|
845
|
-
var key = vnode.key;
|
|
846
|
-
if (key != null) map[key] = start;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
return map
|
|
850
|
-
}
|
|
851
|
-
// Lifted from ivi https://github.com/ivijs/ivi/
|
|
852
|
-
// takes a list of unique numbers (-1 is special and can
|
|
853
|
-
// occur multiple times) and returns an array with the indices
|
|
854
|
-
// of the items that are part of the longest increasing
|
|
855
|
-
// subsequece
|
|
856
|
-
var lisTemp = [];
|
|
857
|
-
function makeLisIndices(a) {
|
|
858
|
-
var result = [0];
|
|
859
|
-
var u = 0, v = 0, i = 0;
|
|
860
|
-
var il = lisTemp.length = a.length;
|
|
861
|
-
for (var i = 0; i < il; i++) lisTemp[i] = a[i];
|
|
862
|
-
for (var i = 0; i < il; ++i) {
|
|
863
|
-
if (a[i] === -1) continue
|
|
864
|
-
var j = result[result.length - 1];
|
|
865
|
-
if (a[j] < a[i]) {
|
|
866
|
-
lisTemp[i] = j;
|
|
867
|
-
result.push(i);
|
|
868
|
-
continue
|
|
869
|
-
}
|
|
870
|
-
u = 0;
|
|
871
|
-
v = result.length - 1;
|
|
872
|
-
while (u < v) {
|
|
873
|
-
// Fast integer average without overflow.
|
|
874
|
-
// eslint-disable-next-line no-bitwise
|
|
875
|
-
var c = (u >>> 1) + (v >>> 1) + (u & v & 1);
|
|
876
|
-
if (a[result[c]] < a[i]) {
|
|
877
|
-
u = c + 1;
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
v = c;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
if (a[i] < a[result[u]]) {
|
|
884
|
-
if (u > 0) lisTemp[i] = result[u - 1];
|
|
885
|
-
result[u] = i;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
u = result.length;
|
|
889
|
-
v = result[u - 1];
|
|
890
|
-
while (u-- > 0) {
|
|
891
|
-
result[u] = v;
|
|
892
|
-
v = lisTemp[v];
|
|
893
|
-
}
|
|
894
|
-
lisTemp.length = 0;
|
|
895
|
-
return result
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
function getNextSibling(vnodes, i, nextSibling) {
|
|
899
|
-
for (; i < vnodes.length; i++) {
|
|
900
|
-
if (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom
|
|
901
|
-
}
|
|
902
|
-
return nextSibling
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// This covers a really specific edge case:
|
|
906
|
-
// - Parent node is keyed and contains child
|
|
907
|
-
// - Child is removed, returns unresolved promise in `onbeforeremove`
|
|
908
|
-
// - Parent node is moved in keyed diff
|
|
909
|
-
// - Remaining children still need moved appropriately
|
|
910
|
-
//
|
|
911
|
-
// Ideally, I'd track removed nodes as well, but that introduces a lot more
|
|
912
|
-
// complexity and I'm not exactly interested in doing that.
|
|
913
|
-
function moveNodes(parent, vnode, nextSibling) {
|
|
914
|
-
var frag = $doc.createDocumentFragment();
|
|
915
|
-
moveChildToFrag(parent, frag, vnode);
|
|
916
|
-
insertNode(parent, frag, nextSibling);
|
|
917
|
-
}
|
|
918
|
-
function moveChildToFrag(parent, frag, vnode) {
|
|
919
|
-
// Dodge the recursion overhead in a few of the most common cases.
|
|
920
|
-
while (vnode.dom != null && vnode.dom.parentNode === parent) {
|
|
921
|
-
if (typeof vnode.tag !== "string") {
|
|
922
|
-
vnode = vnode.instance;
|
|
923
|
-
if (vnode != null) continue
|
|
924
|
-
} else if (vnode.tag === "<") {
|
|
925
|
-
for (var i = 0; i < vnode.instance.length; i++) {
|
|
926
|
-
frag.appendChild(vnode.instance[i]);
|
|
927
|
-
}
|
|
928
|
-
} else if (vnode.tag !== "[") {
|
|
929
|
-
// Don't recurse for text nodes *or* elements, just fragments
|
|
930
|
-
frag.appendChild(vnode.dom);
|
|
931
|
-
} else if (vnode.children.length === 1) {
|
|
932
|
-
vnode = vnode.children[0];
|
|
933
|
-
if (vnode != null) continue
|
|
934
|
-
} else {
|
|
935
|
-
for (var i = 0; i < vnode.children.length; i++) {
|
|
936
|
-
var child = vnode.children[i];
|
|
937
|
-
if (child != null) moveChildToFrag(parent, frag, child);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
break
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
function insertNode(parent, dom, nextSibling) {
|
|
945
|
-
if (nextSibling != null) parent.insertBefore(dom, nextSibling);
|
|
946
|
-
else parent.appendChild(dom);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
function maybeSetContentEditable(vnode) {
|
|
950
|
-
if (vnode.attrs == null || (
|
|
951
|
-
vnode.attrs.contenteditable == null && // attribute
|
|
952
|
-
vnode.attrs.contentEditable == null // property
|
|
953
|
-
)) return false
|
|
954
|
-
var children = vnode.children;
|
|
955
|
-
if (children != null && children.length === 1 && children[0].tag === "<") {
|
|
956
|
-
var content = children[0].children;
|
|
957
|
-
if (vnode.dom.innerHTML !== content) vnode.dom.innerHTML = content;
|
|
958
|
-
}
|
|
959
|
-
else if (vnode.text != null || children != null && children.length !== 0) throw new Error("Child node of a contenteditable must be trusted")
|
|
960
|
-
return true
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
//remove
|
|
964
|
-
function removeNodes(parent, vnodes, start, end) {
|
|
965
|
-
for (var i = start; i < end; i++) {
|
|
966
|
-
var vnode = vnodes[i];
|
|
967
|
-
if (vnode != null) removeNode(parent, vnode);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
function removeNode(parent, vnode) {
|
|
971
|
-
var mask = 0;
|
|
972
|
-
var original = vnode.state;
|
|
973
|
-
var stateResult, attrsResult;
|
|
974
|
-
if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeremove === "function") {
|
|
975
|
-
var result = callHook.call(vnode.state.onbeforeremove, vnode);
|
|
976
|
-
if (result != null && typeof result.then === "function") {
|
|
977
|
-
mask = 1;
|
|
978
|
-
stateResult = result;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") {
|
|
982
|
-
var result = callHook.call(vnode.attrs.onbeforeremove, vnode);
|
|
983
|
-
if (result != null && typeof result.then === "function") {
|
|
984
|
-
// eslint-disable-next-line no-bitwise
|
|
985
|
-
mask |= 2;
|
|
986
|
-
attrsResult = result;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
checkState(vnode, original);
|
|
990
|
-
|
|
991
|
-
// If we can, try to fast-path it and avoid all the overhead of awaiting
|
|
992
|
-
if (!mask) {
|
|
993
|
-
onremove(vnode);
|
|
994
|
-
removeChild(parent, vnode);
|
|
995
|
-
} else {
|
|
996
|
-
if (stateResult != null) {
|
|
997
|
-
var next = function () {
|
|
998
|
-
// eslint-disable-next-line no-bitwise
|
|
999
|
-
if (mask & 1) { mask &= 2; if (!mask) reallyRemove(); }
|
|
1000
|
-
};
|
|
1001
|
-
stateResult.then(next, next);
|
|
1002
|
-
}
|
|
1003
|
-
if (attrsResult != null) {
|
|
1004
|
-
var next = function () {
|
|
1005
|
-
// eslint-disable-next-line no-bitwise
|
|
1006
|
-
if (mask & 2) { mask &= 1; if (!mask) reallyRemove(); }
|
|
1007
|
-
};
|
|
1008
|
-
attrsResult.then(next, next);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
function reallyRemove() {
|
|
1013
|
-
checkState(vnode, original);
|
|
1014
|
-
onremove(vnode);
|
|
1015
|
-
removeChild(parent, vnode);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
function removeHTML(parent, vnode) {
|
|
1019
|
-
for (var i = 0; i < vnode.instance.length; i++) {
|
|
1020
|
-
parent.removeChild(vnode.instance[i]);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
function removeChild(parent, vnode) {
|
|
1024
|
-
// Dodge the recursion overhead in a few of the most common cases.
|
|
1025
|
-
while (vnode.dom != null && vnode.dom.parentNode === parent) {
|
|
1026
|
-
if (typeof vnode.tag !== "string") {
|
|
1027
|
-
vnode = vnode.instance;
|
|
1028
|
-
if (vnode != null) continue
|
|
1029
|
-
} else if (vnode.tag === "<") {
|
|
1030
|
-
removeHTML(parent, vnode);
|
|
1031
|
-
} else {
|
|
1032
|
-
if (vnode.tag !== "[") {
|
|
1033
|
-
parent.removeChild(vnode.dom);
|
|
1034
|
-
if (!Array.isArray(vnode.children)) break
|
|
1035
|
-
}
|
|
1036
|
-
if (vnode.children.length === 1) {
|
|
1037
|
-
vnode = vnode.children[0];
|
|
1038
|
-
if (vnode != null) continue
|
|
1039
|
-
} else {
|
|
1040
|
-
for (var i = 0; i < vnode.children.length; i++) {
|
|
1041
|
-
var child = vnode.children[i];
|
|
1042
|
-
if (child != null) removeChild(parent, child);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
break
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
function onremove(vnode) {
|
|
1050
|
-
if (typeof vnode.tag !== "string" && typeof vnode.state.onremove === "function") callHook.call(vnode.state.onremove, vnode);
|
|
1051
|
-
if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode);
|
|
1052
|
-
if (typeof vnode.tag !== "string") {
|
|
1053
|
-
if (vnode.instance != null) onremove(vnode.instance);
|
|
1054
|
-
} else {
|
|
1055
|
-
var children = vnode.children;
|
|
1056
|
-
if (Array.isArray(children)) {
|
|
1057
|
-
for (var i = 0; i < children.length; i++) {
|
|
1058
|
-
var child = children[i];
|
|
1059
|
-
if (child != null) onremove(child);
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
//attrs
|
|
1066
|
-
function setAttrs(vnode, attrs, ns) {
|
|
1067
|
-
for (var key in attrs) {
|
|
1068
|
-
setAttr(vnode, key, null, attrs[key], ns);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
function setAttr(vnode, key, old, value, ns) {
|
|
1072
|
-
if (key === "key" || key === "is" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object") return
|
|
1073
|
-
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value)
|
|
1074
|
-
if (key.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value);
|
|
1075
|
-
else if (key === "style") updateStyle(vnode.dom, old, value);
|
|
1076
|
-
else if (hasPropertyKey(vnode, key, ns)) {
|
|
1077
|
-
if (key === "value") {
|
|
1078
|
-
// Only do the coercion if we're actually going to check the value.
|
|
1079
|
-
/* eslint-disable no-implicit-coercion */
|
|
1080
|
-
//setting input[value] to same value by typing on focused element moves cursor to end in Chrome
|
|
1081
|
-
if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === "" + value && vnode.dom === activeElement()) return
|
|
1082
|
-
//setting select[value] to same value while having select open blinks select dropdown in Chrome
|
|
1083
|
-
if (vnode.tag === "select" && old !== null && vnode.dom.value === "" + value) return
|
|
1084
|
-
//setting option[value] to same value while having select open blinks select dropdown in Chrome
|
|
1085
|
-
if (vnode.tag === "option" && old !== null && vnode.dom.value === "" + value) return
|
|
1086
|
-
/* eslint-enable no-implicit-coercion */
|
|
1087
|
-
}
|
|
1088
|
-
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
|
|
1089
|
-
if (vnode.tag === "input" && key === "type") vnode.dom.setAttribute(key, value);
|
|
1090
|
-
else vnode.dom[key] = value;
|
|
1091
|
-
} else {
|
|
1092
|
-
if (typeof value === "boolean") {
|
|
1093
|
-
if (value) vnode.dom.setAttribute(key, "");
|
|
1094
|
-
else vnode.dom.removeAttribute(key);
|
|
1095
|
-
}
|
|
1096
|
-
else vnode.dom.setAttribute(key === "className" ? "class" : key, value);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
function removeAttr(vnode, key, old, ns) {
|
|
1100
|
-
if (key === "key" || key === "is" || old == null || isLifecycleMethod(key)) return
|
|
1101
|
-
if (key[0] === "o" && key[1] === "n" && !isLifecycleMethod(key)) updateEvent(vnode, key, undefined);
|
|
1102
|
-
else if (key === "style") updateStyle(vnode.dom, old, null);
|
|
1103
|
-
else if (
|
|
1104
|
-
hasPropertyKey(vnode, key, ns)
|
|
1105
|
-
&& key !== "className"
|
|
1106
|
-
&& !(key === "value" && (
|
|
1107
|
-
vnode.tag === "option"
|
|
1108
|
-
|| vnode.tag === "select" && vnode.dom.selectedIndex === -1 && vnode.dom === activeElement()
|
|
1109
|
-
))
|
|
1110
|
-
&& !(vnode.tag === "input" && key === "type")
|
|
1111
|
-
) {
|
|
1112
|
-
vnode.dom[key] = null;
|
|
1113
|
-
} else {
|
|
1114
|
-
var nsLastIndex = key.indexOf(":");
|
|
1115
|
-
if (nsLastIndex !== -1) key = key.slice(nsLastIndex + 1);
|
|
1116
|
-
if (old !== false) vnode.dom.removeAttribute(key === "className" ? "class" : key);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
function setLateSelectAttrs(vnode, attrs) {
|
|
1120
|
-
if ("value" in attrs) {
|
|
1121
|
-
if(attrs.value === null) {
|
|
1122
|
-
if (vnode.dom.selectedIndex !== -1) vnode.dom.value = null;
|
|
1123
|
-
} else {
|
|
1124
|
-
var normalized = "" + attrs.value; // eslint-disable-line no-implicit-coercion
|
|
1125
|
-
if (vnode.dom.value !== normalized || vnode.dom.selectedIndex === -1) {
|
|
1126
|
-
vnode.dom.value = normalized;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
if ("selectedIndex" in attrs) setAttr(vnode, "selectedIndex", null, attrs.selectedIndex, undefined);
|
|
1131
|
-
}
|
|
1132
|
-
function updateAttrs(vnode, old, attrs, ns) {
|
|
1133
|
-
if (attrs != null) {
|
|
1134
|
-
for (var key in attrs) {
|
|
1135
|
-
setAttr(vnode, key, old && old[key], attrs[key], ns);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
var val;
|
|
1139
|
-
if (old != null) {
|
|
1140
|
-
for (var key in old) {
|
|
1141
|
-
if (((val = old[key]) != null) && (attrs == null || attrs[key] == null)) {
|
|
1142
|
-
removeAttr(vnode, key, val, ns);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
function isFormAttribute(vnode, attr) {
|
|
1148
|
-
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom === activeElement() || vnode.tag === "option" && vnode.dom.parentNode === $doc.activeElement
|
|
1149
|
-
}
|
|
1150
|
-
function isLifecycleMethod(attr) {
|
|
1151
|
-
return attr === "oninit" || attr === "oncreate" || attr === "onupdate" || attr === "onremove" || attr === "onbeforeremove" || attr === "onbeforeupdate"
|
|
1152
|
-
}
|
|
1153
|
-
function hasPropertyKey(vnode, key, ns) {
|
|
1154
|
-
// Filter out namespaced keys
|
|
1155
|
-
return ns === undefined && (
|
|
1156
|
-
// If it's a custom element, just keep it.
|
|
1157
|
-
vnode.tag.indexOf("-") > -1 || vnode.attrs != null && vnode.attrs.is ||
|
|
1158
|
-
// If it's a normal element, let's try to avoid a few browser bugs.
|
|
1159
|
-
key !== "href" && key !== "list" && key !== "form" && key !== "width" && key !== "height"// && key !== "type"
|
|
1160
|
-
// Defer the property check until *after* we check everything.
|
|
1161
|
-
) && key in vnode.dom
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
//style
|
|
1165
|
-
var uppercaseRegex = /[A-Z]/g;
|
|
1166
|
-
function toLowerCase(capital) { return "-" + capital.toLowerCase() }
|
|
1167
|
-
function normalizeKey(key) {
|
|
1168
|
-
return key[0] === "-" && key[1] === "-" ? key :
|
|
1169
|
-
key === "cssFloat" ? "float" :
|
|
1170
|
-
key.replace(uppercaseRegex, toLowerCase)
|
|
1171
|
-
}
|
|
1172
|
-
function updateStyle(element, old, style) {
|
|
1173
|
-
if (old === style) ; else if (style == null) {
|
|
1174
|
-
// New style is missing, just clear it.
|
|
1175
|
-
element.style.cssText = "";
|
|
1176
|
-
} else if (typeof style !== "object") {
|
|
1177
|
-
// New style is a string, let engine deal with patching.
|
|
1178
|
-
element.style.cssText = style;
|
|
1179
|
-
} else if (old == null || typeof old !== "object") {
|
|
1180
|
-
// `old` is missing or a string, `style` is an object.
|
|
1181
|
-
element.style.cssText = "";
|
|
1182
|
-
// Add new style properties
|
|
1183
|
-
for (var key in style) {
|
|
1184
|
-
var value = style[key];
|
|
1185
|
-
if (value != null) element.style.setProperty(normalizeKey(key), String(value));
|
|
1186
|
-
}
|
|
1187
|
-
} else {
|
|
1188
|
-
// Both old & new are (different) objects.
|
|
1189
|
-
// Update style properties that have changed
|
|
1190
|
-
for (var key in style) {
|
|
1191
|
-
var value = style[key];
|
|
1192
|
-
if (value != null && (value = String(value)) !== String(old[key])) {
|
|
1193
|
-
element.style.setProperty(normalizeKey(key), value);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
// Remove style properties that no longer exist
|
|
1197
|
-
for (var key in old) {
|
|
1198
|
-
if (old[key] != null && style[key] == null) {
|
|
1199
|
-
element.style.removeProperty(normalizeKey(key));
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
// Here's an explanation of how this works:
|
|
1206
|
-
// 1. The event names are always (by design) prefixed by `on`.
|
|
1207
|
-
// 2. The EventListener interface accepts either a function or an object
|
|
1208
|
-
// with a `handleEvent` method.
|
|
1209
|
-
// 3. The object does not inherit from `Object.prototype`, to avoid
|
|
1210
|
-
// any potential interference with that (e.g. setters).
|
|
1211
|
-
// 4. The event name is remapped to the handler before calling it.
|
|
1212
|
-
// 5. In function-based event handlers, `ev.target === this`. We replicate
|
|
1213
|
-
// that below.
|
|
1214
|
-
// 6. In function-based event handlers, `return false` prevents the default
|
|
1215
|
-
// action and stops event propagation. We replicate that below.
|
|
1216
|
-
function EventDict() {
|
|
1217
|
-
// Save this, so the current redraw is correctly tracked.
|
|
1218
|
-
this._ = currentRedraw;
|
|
1219
|
-
}
|
|
1220
|
-
EventDict.prototype = Object.create(null);
|
|
1221
|
-
EventDict.prototype.handleEvent = function (ev) {
|
|
1222
|
-
var handler = this["on" + ev.type];
|
|
1223
|
-
var result;
|
|
1224
|
-
if (typeof handler === "function") result = handler.call(ev.currentTarget, ev);
|
|
1225
|
-
else if (typeof handler.handleEvent === "function") handler.handleEvent(ev);
|
|
1226
|
-
if (this._ && ev.redraw !== false) (0, this._)();
|
|
1227
|
-
if (result === false) {
|
|
1228
|
-
ev.preventDefault();
|
|
1229
|
-
ev.stopPropagation();
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
|
-
|
|
1233
|
-
//event
|
|
1234
|
-
function updateEvent(vnode, key, value) {
|
|
1235
|
-
if (vnode.events != null) {
|
|
1236
|
-
if (vnode.events[key] === value) return
|
|
1237
|
-
if (value != null && (typeof value === "function" || typeof value === "object")) {
|
|
1238
|
-
if (vnode.events[key] == null) vnode.dom.addEventListener(key.slice(2), vnode.events, false);
|
|
1239
|
-
vnode.events[key] = value;
|
|
1240
|
-
} else {
|
|
1241
|
-
if (vnode.events[key] != null) vnode.dom.removeEventListener(key.slice(2), vnode.events, false);
|
|
1242
|
-
vnode.events[key] = undefined;
|
|
1243
|
-
}
|
|
1244
|
-
} else if (value != null && (typeof value === "function" || typeof value === "object")) {
|
|
1245
|
-
vnode.events = new EventDict();
|
|
1246
|
-
vnode.dom.addEventListener(key.slice(2), vnode.events, false);
|
|
1247
|
-
vnode.events[key] = value;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
//lifecycle
|
|
1252
|
-
function initLifecycle(source, vnode, hooks) {
|
|
1253
|
-
if (typeof source.oninit === "function") callHook.call(source.oninit, vnode);
|
|
1254
|
-
if (typeof source.oncreate === "function") hooks.push(callHook.bind(source.oncreate, vnode));
|
|
1255
|
-
}
|
|
1256
|
-
function updateLifecycle(source, vnode, hooks) {
|
|
1257
|
-
if (typeof source.onupdate === "function") hooks.push(callHook.bind(source.onupdate, vnode));
|
|
1258
|
-
}
|
|
1259
|
-
function shouldNotUpdate(vnode, old) {
|
|
1260
|
-
do {
|
|
1261
|
-
if (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === "function") {
|
|
1262
|
-
var force = callHook.call(vnode.attrs.onbeforeupdate, vnode, old);
|
|
1263
|
-
if (force !== undefined && !force) break
|
|
1264
|
-
}
|
|
1265
|
-
if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeupdate === "function") {
|
|
1266
|
-
var force = callHook.call(vnode.state.onbeforeupdate, vnode, old);
|
|
1267
|
-
if (force !== undefined && !force) break
|
|
1268
|
-
}
|
|
1269
|
-
return false
|
|
1270
|
-
} while (false); // eslint-disable-line no-constant-condition
|
|
1271
|
-
vnode.dom = old.dom;
|
|
1272
|
-
vnode.domSize = old.domSize;
|
|
1273
|
-
vnode.instance = old.instance;
|
|
1274
|
-
// One would think having the actual latest attributes would be ideal,
|
|
1275
|
-
// but it doesn't let us properly diff based on our current internal
|
|
1276
|
-
// representation. We have to save not only the old DOM info, but also
|
|
1277
|
-
// the attributes used to create it, as we diff *that*, not against the
|
|
1278
|
-
// DOM directly (with a few exceptions in `setAttr`). And, of course, we
|
|
1279
|
-
// need to save the children and text as they are conceptually not
|
|
1280
|
-
// unlike special "attributes" internally.
|
|
1281
|
-
vnode.attrs = old.attrs;
|
|
1282
|
-
vnode.children = old.children;
|
|
1283
|
-
vnode.text = old.text;
|
|
1284
|
-
return true
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
return function(dom, vnodes, redraw) {
|
|
1288
|
-
if (!dom) throw new TypeError("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.")
|
|
1289
|
-
var hooks = [];
|
|
1290
|
-
var active = activeElement();
|
|
1291
|
-
var namespace = dom.namespaceURI;
|
|
1292
|
-
|
|
1293
|
-
// First time rendering into a node clears it out
|
|
1294
|
-
if (dom.vnodes == null) dom.textContent = "";
|
|
1295
|
-
|
|
1296
|
-
vnodes = vnode.normalizeChildren(Array.isArray(vnodes) ? vnodes : [vnodes]);
|
|
1297
|
-
var prevRedraw = currentRedraw;
|
|
1298
|
-
try {
|
|
1299
|
-
currentRedraw = typeof redraw === "function" ? redraw : undefined;
|
|
1300
|
-
updateNodes(dom, dom.vnodes, vnodes, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace);
|
|
1301
|
-
} finally {
|
|
1302
|
-
currentRedraw = prevRedraw;
|
|
1303
|
-
}
|
|
1304
|
-
dom.vnodes = vnodes;
|
|
1305
|
-
// `document.activeElement` can return null: https://html.spec.whatwg.org/multipage/interaction.html#dom-document-activeelement
|
|
1306
|
-
if (active != null && activeElement() !== active && typeof active.focus === "function") active.focus();
|
|
1307
|
-
for (var i = 0; i < hooks.length; i++) hooks[i]();
|
|
1308
|
-
}
|
|
1309
|
-
};
|
|
1310
|
-
|
|
1311
|
-
var render = render$1(window);
|
|
1312
|
-
|
|
1313
|
-
var mountRedraw$1 = function(render, schedule, console) {
|
|
1314
|
-
var subscriptions = [];
|
|
1315
|
-
var rendering = false;
|
|
1316
|
-
var pending = false;
|
|
1317
|
-
|
|
1318
|
-
function sync() {
|
|
1319
|
-
if (rendering) throw new Error("Nested m.redraw.sync() call")
|
|
1320
|
-
rendering = true;
|
|
1321
|
-
for (var i = 0; i < subscriptions.length; i += 2) {
|
|
1322
|
-
try { render(subscriptions[i], vnode(subscriptions[i + 1]), redraw); }
|
|
1323
|
-
catch (e) { console.error(e); }
|
|
1324
|
-
}
|
|
1325
|
-
rendering = false;
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
function redraw() {
|
|
1329
|
-
if (!pending) {
|
|
1330
|
-
pending = true;
|
|
1331
|
-
schedule(function() {
|
|
1332
|
-
pending = false;
|
|
1333
|
-
sync();
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
redraw.sync = sync;
|
|
1339
|
-
|
|
1340
|
-
function mount(root, component) {
|
|
1341
|
-
if (component != null && component.view == null && typeof component !== "function") {
|
|
1342
|
-
throw new TypeError("m.mount(element, component) expects a component, not a vnode")
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
var index = subscriptions.indexOf(root);
|
|
1346
|
-
if (index >= 0) {
|
|
1347
|
-
subscriptions.splice(index, 2);
|
|
1348
|
-
render(root, [], redraw);
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
if (component != null) {
|
|
1352
|
-
subscriptions.push(root, component);
|
|
1353
|
-
render(root, vnode(component), redraw);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
return {mount: mount, redraw: redraw}
|
|
1358
|
-
};
|
|
1359
|
-
|
|
1360
|
-
var mountRedraw = mountRedraw$1(render, requestAnimationFrame, console);
|
|
1361
|
-
|
|
1362
|
-
var build$2 = function(object) {
|
|
1363
|
-
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
|
1364
|
-
|
|
1365
|
-
var args = [];
|
|
1366
|
-
for (var key in object) {
|
|
1367
|
-
destructure(key, object[key]);
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
return args.join("&")
|
|
1371
|
-
|
|
1372
|
-
function destructure(key, value) {
|
|
1373
|
-
if (Array.isArray(value)) {
|
|
1374
|
-
for (var i = 0; i < value.length; i++) {
|
|
1375
|
-
destructure(key + "[" + i + "]", value[i]);
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
else if (Object.prototype.toString.call(value) === "[object Object]") {
|
|
1379
|
-
for (var i in value) {
|
|
1380
|
-
destructure(key + "[" + i + "]", value[i]);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""));
|
|
1384
|
-
}
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
var assign$1 = Object.assign || function(target, source) {
|
|
1388
|
-
if(source) Object.keys(source).forEach(function(key) { target[key] = source[key]; });
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
// Returns `path` from `template` + `params`
|
|
1392
|
-
var build$1 = function(template, params) {
|
|
1393
|
-
if ((/:([^\/\.-]+)(\.{3})?:/).test(template)) {
|
|
1394
|
-
throw new SyntaxError("Template parameter names *must* be separated")
|
|
1395
|
-
}
|
|
1396
|
-
if (params == null) return template
|
|
1397
|
-
var queryIndex = template.indexOf("?");
|
|
1398
|
-
var hashIndex = template.indexOf("#");
|
|
1399
|
-
var queryEnd = hashIndex < 0 ? template.length : hashIndex;
|
|
1400
|
-
var pathEnd = queryIndex < 0 ? queryEnd : queryIndex;
|
|
1401
|
-
var path = template.slice(0, pathEnd);
|
|
1402
|
-
var query = {};
|
|
1403
|
-
|
|
1404
|
-
assign$1(query, params);
|
|
1405
|
-
|
|
1406
|
-
var resolved = path.replace(/:([^\/\.-]+)(\.{3})?/g, function(m, key, variadic) {
|
|
1407
|
-
delete query[key];
|
|
1408
|
-
// If no such parameter exists, don't interpolate it.
|
|
1409
|
-
if (params[key] == null) return m
|
|
1410
|
-
// Escape normal parameters, but not variadic ones.
|
|
1411
|
-
return variadic ? params[key] : encodeURIComponent(String(params[key]))
|
|
1412
|
-
});
|
|
1413
|
-
|
|
1414
|
-
// In case the template substitution adds new query/hash parameters.
|
|
1415
|
-
var newQueryIndex = resolved.indexOf("?");
|
|
1416
|
-
var newHashIndex = resolved.indexOf("#");
|
|
1417
|
-
var newQueryEnd = newHashIndex < 0 ? resolved.length : newHashIndex;
|
|
1418
|
-
var newPathEnd = newQueryIndex < 0 ? newQueryEnd : newQueryIndex;
|
|
1419
|
-
var result = resolved.slice(0, newPathEnd);
|
|
1420
|
-
|
|
1421
|
-
if (queryIndex >= 0) result += template.slice(queryIndex, queryEnd);
|
|
1422
|
-
if (newQueryIndex >= 0) result += (queryIndex < 0 ? "?" : "&") + resolved.slice(newQueryIndex, newQueryEnd);
|
|
1423
|
-
var querystring = build$2(query);
|
|
1424
|
-
if (querystring) result += (queryIndex < 0 && newQueryIndex < 0 ? "?" : "&") + querystring;
|
|
1425
|
-
if (hashIndex >= 0) result += template.slice(hashIndex);
|
|
1426
|
-
if (newHashIndex >= 0) result += (hashIndex < 0 ? "" : "&") + resolved.slice(newHashIndex);
|
|
1427
|
-
return result
|
|
1428
|
-
};
|
|
1429
|
-
|
|
1430
|
-
var request$1 = function($window, Promise, oncompletion) {
|
|
1431
|
-
var callbackCount = 0;
|
|
1432
|
-
|
|
1433
|
-
function PromiseProxy(executor) {
|
|
1434
|
-
return new Promise(executor)
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
// In case the global Promise is some userland library's where they rely on
|
|
1438
|
-
// `foo instanceof this.constructor`, `this.constructor.resolve(value)`, or
|
|
1439
|
-
// similar. Let's *not* break them.
|
|
1440
|
-
PromiseProxy.prototype = Promise.prototype;
|
|
1441
|
-
PromiseProxy.__proto__ = Promise; // eslint-disable-line no-proto
|
|
1442
|
-
|
|
1443
|
-
function makeRequest(factory) {
|
|
1444
|
-
return function(url, args) {
|
|
1445
|
-
if (typeof url !== "string") { args = url; url = url.url; }
|
|
1446
|
-
else if (args == null) args = {};
|
|
1447
|
-
var promise = new Promise(function(resolve, reject) {
|
|
1448
|
-
factory(build$1(url, args.params), args, function (data) {
|
|
1449
|
-
if (typeof args.type === "function") {
|
|
1450
|
-
if (Array.isArray(data)) {
|
|
1451
|
-
for (var i = 0; i < data.length; i++) {
|
|
1452
|
-
data[i] = new args.type(data[i]);
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
else data = new args.type(data);
|
|
1456
|
-
}
|
|
1457
|
-
resolve(data);
|
|
1458
|
-
}, reject);
|
|
1459
|
-
});
|
|
1460
|
-
if (args.background === true) return promise
|
|
1461
|
-
var count = 0;
|
|
1462
|
-
function complete() {
|
|
1463
|
-
if (--count === 0 && typeof oncompletion === "function") oncompletion();
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
return wrap(promise)
|
|
1467
|
-
|
|
1468
|
-
function wrap(promise) {
|
|
1469
|
-
var then = promise.then;
|
|
1470
|
-
// Set the constructor, so engines know to not await or resolve
|
|
1471
|
-
// this as a native promise. At the time of writing, this is
|
|
1472
|
-
// only necessary for V8, but their behavior is the correct
|
|
1473
|
-
// behavior per spec. See this spec issue for more details:
|
|
1474
|
-
// https://github.com/tc39/ecma262/issues/1577. Also, see the
|
|
1475
|
-
// corresponding comment in `request/tests/test-request.js` for
|
|
1476
|
-
// a bit more background on the issue at hand.
|
|
1477
|
-
promise.constructor = PromiseProxy;
|
|
1478
|
-
promise.then = function() {
|
|
1479
|
-
count++;
|
|
1480
|
-
var next = then.apply(promise, arguments);
|
|
1481
|
-
next.then(complete, function(e) {
|
|
1482
|
-
complete();
|
|
1483
|
-
if (count === 0) throw e
|
|
1484
|
-
});
|
|
1485
|
-
return wrap(next)
|
|
1486
|
-
};
|
|
1487
|
-
return promise
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
function hasHeader(args, name) {
|
|
1493
|
-
for (var key in args.headers) {
|
|
1494
|
-
if ({}.hasOwnProperty.call(args.headers, key) && name.test(key)) return true
|
|
1495
|
-
}
|
|
1496
|
-
return false
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
return {
|
|
1500
|
-
request: makeRequest(function(url, args, resolve, reject) {
|
|
1501
|
-
var method = args.method != null ? args.method.toUpperCase() : "GET";
|
|
1502
|
-
var body = args.body;
|
|
1503
|
-
var assumeJSON = (args.serialize == null || args.serialize === JSON.serialize) && !(body instanceof $window.FormData);
|
|
1504
|
-
var responseType = args.responseType || (typeof args.extract === "function" ? "" : "json");
|
|
1505
|
-
|
|
1506
|
-
var xhr = new $window.XMLHttpRequest(), aborted = false;
|
|
1507
|
-
var original = xhr, replacedAbort;
|
|
1508
|
-
var abort = xhr.abort;
|
|
1509
|
-
|
|
1510
|
-
xhr.abort = function() {
|
|
1511
|
-
aborted = true;
|
|
1512
|
-
abort.call(this);
|
|
1513
|
-
};
|
|
1514
|
-
|
|
1515
|
-
xhr.open(method, url, args.async !== false, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined);
|
|
1516
|
-
|
|
1517
|
-
if (assumeJSON && body != null && !hasHeader(args, /^content-type$/i)) {
|
|
1518
|
-
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|
1519
|
-
}
|
|
1520
|
-
if (typeof args.deserialize !== "function" && !hasHeader(args, /^accept$/i)) {
|
|
1521
|
-
xhr.setRequestHeader("Accept", "application/json, text/*");
|
|
1522
|
-
}
|
|
1523
|
-
if (args.withCredentials) xhr.withCredentials = args.withCredentials;
|
|
1524
|
-
if (args.timeout) xhr.timeout = args.timeout;
|
|
1525
|
-
xhr.responseType = responseType;
|
|
1526
|
-
|
|
1527
|
-
for (var key in args.headers) {
|
|
1528
|
-
if ({}.hasOwnProperty.call(args.headers, key)) {
|
|
1529
|
-
xhr.setRequestHeader(key, args.headers[key]);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
xhr.onreadystatechange = function(ev) {
|
|
1534
|
-
// Don't throw errors on xhr.abort().
|
|
1535
|
-
if (aborted) return
|
|
1536
|
-
|
|
1537
|
-
if (ev.target.readyState === 4) {
|
|
1538
|
-
try {
|
|
1539
|
-
var success = (ev.target.status >= 200 && ev.target.status < 300) || ev.target.status === 304 || (/^file:\/\//i).test(url);
|
|
1540
|
-
// When the response type isn't "" or "text",
|
|
1541
|
-
// `xhr.responseText` is the wrong thing to use.
|
|
1542
|
-
// Browsers do the right thing and throw here, and we
|
|
1543
|
-
// should honor that and do the right thing by
|
|
1544
|
-
// preferring `xhr.response` where possible/practical.
|
|
1545
|
-
var response = ev.target.response, message;
|
|
1546
|
-
|
|
1547
|
-
if (responseType === "json") {
|
|
1548
|
-
// For IE and Edge, which don't implement
|
|
1549
|
-
// `responseType: "json"`.
|
|
1550
|
-
if (!ev.target.responseType && typeof args.extract !== "function") response = JSON.parse(ev.target.responseText);
|
|
1551
|
-
} else if (!responseType || responseType === "text") {
|
|
1552
|
-
// Only use this default if it's text. If a parsed
|
|
1553
|
-
// document is needed on old IE and friends (all
|
|
1554
|
-
// unsupported), the user should use a custom
|
|
1555
|
-
// `config` instead. They're already using this at
|
|
1556
|
-
// their own risk.
|
|
1557
|
-
if (response == null) response = ev.target.responseText;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
if (typeof args.extract === "function") {
|
|
1561
|
-
response = args.extract(ev.target, args);
|
|
1562
|
-
success = true;
|
|
1563
|
-
} else if (typeof args.deserialize === "function") {
|
|
1564
|
-
response = args.deserialize(response);
|
|
1565
|
-
}
|
|
1566
|
-
if (success) resolve(response);
|
|
1567
|
-
else {
|
|
1568
|
-
try { message = ev.target.responseText; }
|
|
1569
|
-
catch (e) { message = response; }
|
|
1570
|
-
var error = new Error(message);
|
|
1571
|
-
error.code = ev.target.status;
|
|
1572
|
-
error.response = response;
|
|
1573
|
-
reject(error);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
catch (e) {
|
|
1577
|
-
reject(e);
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
};
|
|
1581
|
-
|
|
1582
|
-
if (typeof args.config === "function") {
|
|
1583
|
-
xhr = args.config(xhr, args, url) || xhr;
|
|
1584
|
-
|
|
1585
|
-
// Propagate the `abort` to any replacement XHR as well.
|
|
1586
|
-
if (xhr !== original) {
|
|
1587
|
-
replacedAbort = xhr.abort;
|
|
1588
|
-
xhr.abort = function() {
|
|
1589
|
-
aborted = true;
|
|
1590
|
-
replacedAbort.call(this);
|
|
1591
|
-
};
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
if (body == null) xhr.send();
|
|
1596
|
-
else if (typeof args.serialize === "function") xhr.send(args.serialize(body));
|
|
1597
|
-
else if (body instanceof $window.FormData) xhr.send(body);
|
|
1598
|
-
else xhr.send(JSON.stringify(body));
|
|
1599
|
-
}),
|
|
1600
|
-
jsonp: makeRequest(function(url, args, resolve, reject) {
|
|
1601
|
-
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++;
|
|
1602
|
-
var script = $window.document.createElement("script");
|
|
1603
|
-
$window[callbackName] = function(data) {
|
|
1604
|
-
delete $window[callbackName];
|
|
1605
|
-
script.parentNode.removeChild(script);
|
|
1606
|
-
resolve(data);
|
|
1607
|
-
};
|
|
1608
|
-
script.onerror = function() {
|
|
1609
|
-
delete $window[callbackName];
|
|
1610
|
-
script.parentNode.removeChild(script);
|
|
1611
|
-
reject(new Error("JSONP request failed"));
|
|
1612
|
-
};
|
|
1613
|
-
script.src = url + (url.indexOf("?") < 0 ? "?" : "&") +
|
|
1614
|
-
encodeURIComponent(args.callbackKey || "callback") + "=" +
|
|
1615
|
-
encodeURIComponent(callbackName);
|
|
1616
|
-
$window.document.documentElement.appendChild(script);
|
|
1617
|
-
}),
|
|
1618
|
-
}
|
|
1619
|
-
};
|
|
1620
|
-
|
|
1621
|
-
var request = request$1(window, promise, mountRedraw.redraw);
|
|
1622
|
-
|
|
1623
|
-
var parse$1 = function(string) {
|
|
1624
|
-
if (string === "" || string == null) return {}
|
|
1625
|
-
if (string.charAt(0) === "?") string = string.slice(1);
|
|
1626
|
-
|
|
1627
|
-
var entries = string.split("&"), counters = {}, data = {};
|
|
1628
|
-
for (var i = 0; i < entries.length; i++) {
|
|
1629
|
-
var entry = entries[i].split("=");
|
|
1630
|
-
var key = decodeURIComponent(entry[0]);
|
|
1631
|
-
var value = entry.length === 2 ? decodeURIComponent(entry[1]) : "";
|
|
1632
|
-
|
|
1633
|
-
if (value === "true") value = true;
|
|
1634
|
-
else if (value === "false") value = false;
|
|
1635
|
-
|
|
1636
|
-
var levels = key.split(/\]\[?|\[/);
|
|
1637
|
-
var cursor = data;
|
|
1638
|
-
if (key.indexOf("[") > -1) levels.pop();
|
|
1639
|
-
for (var j = 0; j < levels.length; j++) {
|
|
1640
|
-
var level = levels[j], nextLevel = levels[j + 1];
|
|
1641
|
-
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10));
|
|
1642
|
-
if (level === "") {
|
|
1643
|
-
var key = levels.slice(0, j).join();
|
|
1644
|
-
if (counters[key] == null) {
|
|
1645
|
-
counters[key] = Array.isArray(cursor) ? cursor.length : 0;
|
|
1646
|
-
}
|
|
1647
|
-
level = counters[key]++;
|
|
1648
|
-
}
|
|
1649
|
-
// Disallow direct prototype pollution
|
|
1650
|
-
else if (level === "__proto__") break
|
|
1651
|
-
if (j === levels.length - 1) cursor[level] = value;
|
|
1652
|
-
else {
|
|
1653
|
-
// Read own properties exclusively to disallow indirect
|
|
1654
|
-
// prototype pollution
|
|
1655
|
-
var desc = Object.getOwnPropertyDescriptor(cursor, level);
|
|
1656
|
-
if (desc != null) desc = desc.value;
|
|
1657
|
-
if (desc == null) cursor[level] = desc = isNumber ? [] : {};
|
|
1658
|
-
cursor = desc;
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
return data
|
|
1663
|
-
};
|
|
1664
|
-
|
|
1665
|
-
// Returns `{path, params}` from `url`
|
|
1666
|
-
var parse = function(url) {
|
|
1667
|
-
var queryIndex = url.indexOf("?");
|
|
1668
|
-
var hashIndex = url.indexOf("#");
|
|
1669
|
-
var queryEnd = hashIndex < 0 ? url.length : hashIndex;
|
|
1670
|
-
var pathEnd = queryIndex < 0 ? queryEnd : queryIndex;
|
|
1671
|
-
var path = url.slice(0, pathEnd).replace(/\/{2,}/g, "/");
|
|
1672
|
-
|
|
1673
|
-
if (!path) path = "/";
|
|
1674
|
-
else {
|
|
1675
|
-
if (path[0] !== "/") path = "/" + path;
|
|
1676
|
-
if (path.length > 1 && path[path.length - 1] === "/") path = path.slice(0, -1);
|
|
1677
|
-
}
|
|
1678
|
-
return {
|
|
1679
|
-
path: path,
|
|
1680
|
-
params: queryIndex < 0
|
|
1681
|
-
? {}
|
|
1682
|
-
: parse$1(url.slice(queryIndex + 1, queryEnd)),
|
|
1683
|
-
}
|
|
1684
|
-
};
|
|
1685
|
-
|
|
1686
|
-
// Compiles a template into a function that takes a resolved path (without query
|
|
1687
|
-
// strings) and returns an object containing the template parameters with their
|
|
1688
|
-
// parsed values. This expects the input of the compiled template to be the
|
|
1689
|
-
// output of `parsePathname`. Note that it does *not* remove query parameters
|
|
1690
|
-
// specified in the template.
|
|
1691
|
-
var compileTemplate = function(template) {
|
|
1692
|
-
var templateData = parse(template);
|
|
1693
|
-
var templateKeys = Object.keys(templateData.params);
|
|
1694
|
-
var keys = [];
|
|
1695
|
-
var regexp = new RegExp("^" + templateData.path.replace(
|
|
1696
|
-
// I escape literal text so people can use things like `:file.:ext` or
|
|
1697
|
-
// `:lang-:locale` in routes. This is all merged into one pass so I
|
|
1698
|
-
// don't also accidentally escape `-` and make it harder to detect it to
|
|
1699
|
-
// ban it from template parameters.
|
|
1700
|
-
/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,
|
|
1701
|
-
function(m, key, extra) {
|
|
1702
|
-
if (key == null) return "\\" + m
|
|
1703
|
-
keys.push({k: key, r: extra === "..."});
|
|
1704
|
-
if (extra === "...") return "(.*)"
|
|
1705
|
-
if (extra === ".") return "([^/]+)\\."
|
|
1706
|
-
return "([^/]+)" + (extra || "")
|
|
1707
|
-
}
|
|
1708
|
-
) + "$");
|
|
1709
|
-
return function(data) {
|
|
1710
|
-
// First, check the params. Usually, there isn't any, and it's just
|
|
1711
|
-
// checking a static set.
|
|
1712
|
-
for (var i = 0; i < templateKeys.length; i++) {
|
|
1713
|
-
if (templateData.params[templateKeys[i]] !== data.params[templateKeys[i]]) return false
|
|
1714
|
-
}
|
|
1715
|
-
// If no interpolations exist, let's skip all the ceremony
|
|
1716
|
-
if (!keys.length) return regexp.test(data.path)
|
|
1717
|
-
var values = regexp.exec(data.path);
|
|
1718
|
-
if (values == null) return false
|
|
1719
|
-
for (var i = 0; i < keys.length; i++) {
|
|
1720
|
-
data.params[keys[i].k] = keys[i].r ? values[i + 1] : decodeURIComponent(values[i + 1]);
|
|
1721
|
-
}
|
|
1722
|
-
return true
|
|
1723
|
-
}
|
|
1724
|
-
};
|
|
1725
|
-
|
|
1726
|
-
var sentinel = {};
|
|
1727
|
-
|
|
1728
|
-
var router = function($window, mountRedraw) {
|
|
1729
|
-
var fireAsync;
|
|
1730
|
-
|
|
1731
|
-
function setPath(path, data, options) {
|
|
1732
|
-
path = build$1(path, data);
|
|
1733
|
-
if (fireAsync != null) {
|
|
1734
|
-
fireAsync();
|
|
1735
|
-
var state = options ? options.state : null;
|
|
1736
|
-
var title = options ? options.title : null;
|
|
1737
|
-
if (options && options.replace) $window.history.replaceState(state, title, route.prefix + path);
|
|
1738
|
-
else $window.history.pushState(state, title, route.prefix + path);
|
|
1739
|
-
}
|
|
1740
|
-
else {
|
|
1741
|
-
$window.location.href = route.prefix + path;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
var currentResolver = sentinel, component, attrs, currentPath, lastUpdate;
|
|
1746
|
-
|
|
1747
|
-
var SKIP = route.SKIP = {};
|
|
1748
|
-
|
|
1749
|
-
function route(root, defaultRoute, routes) {
|
|
1750
|
-
if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined")
|
|
1751
|
-
// 0 = start
|
|
1752
|
-
// 1 = init
|
|
1753
|
-
// 2 = ready
|
|
1754
|
-
var state = 0;
|
|
1755
|
-
|
|
1756
|
-
var compiled = Object.keys(routes).map(function(route) {
|
|
1757
|
-
if (route[0] !== "/") throw new SyntaxError("Routes must start with a `/`")
|
|
1758
|
-
if ((/:([^\/\.-]+)(\.{3})?:/).test(route)) {
|
|
1759
|
-
throw new SyntaxError("Route parameter names must be separated with either `/`, `.`, or `-`")
|
|
1760
|
-
}
|
|
1761
|
-
return {
|
|
1762
|
-
route: route,
|
|
1763
|
-
component: routes[route],
|
|
1764
|
-
check: compileTemplate(route),
|
|
1765
|
-
}
|
|
1766
|
-
});
|
|
1767
|
-
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout;
|
|
1768
|
-
var p = promise.resolve();
|
|
1769
|
-
var scheduled = false;
|
|
1770
|
-
var onremove;
|
|
1771
|
-
|
|
1772
|
-
fireAsync = null;
|
|
1773
|
-
|
|
1774
|
-
if (defaultRoute != null) {
|
|
1775
|
-
var defaultData = parse(defaultRoute);
|
|
1776
|
-
|
|
1777
|
-
if (!compiled.some(function (i) { return i.check(defaultData) })) {
|
|
1778
|
-
throw new ReferenceError("Default route doesn't match any known routes")
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
function resolveRoute() {
|
|
1783
|
-
scheduled = false;
|
|
1784
|
-
// Consider the pathname holistically. The prefix might even be invalid,
|
|
1785
|
-
// but that's not our problem.
|
|
1786
|
-
var prefix = $window.location.hash;
|
|
1787
|
-
if (route.prefix[0] !== "#") {
|
|
1788
|
-
prefix = $window.location.search + prefix;
|
|
1789
|
-
if (route.prefix[0] !== "?") {
|
|
1790
|
-
prefix = $window.location.pathname + prefix;
|
|
1791
|
-
if (prefix[0] !== "/") prefix = "/" + prefix;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
// This seemingly useless `.concat()` speeds up the tests quite a bit,
|
|
1795
|
-
// since the representation is consistently a relatively poorly
|
|
1796
|
-
// optimized cons string.
|
|
1797
|
-
var path = prefix.concat()
|
|
1798
|
-
.replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)
|
|
1799
|
-
.slice(route.prefix.length);
|
|
1800
|
-
var data = parse(path);
|
|
1801
|
-
|
|
1802
|
-
assign$1(data.params, $window.history.state);
|
|
1803
|
-
|
|
1804
|
-
function fail() {
|
|
1805
|
-
if (path === defaultRoute) throw new Error("Could not resolve default route " + defaultRoute)
|
|
1806
|
-
setPath(defaultRoute, null, {replace: true});
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
loop(0);
|
|
1810
|
-
function loop(i) {
|
|
1811
|
-
// 0 = init
|
|
1812
|
-
// 1 = scheduled
|
|
1813
|
-
// 2 = done
|
|
1814
|
-
for (; i < compiled.length; i++) {
|
|
1815
|
-
if (compiled[i].check(data)) {
|
|
1816
|
-
var payload = compiled[i].component;
|
|
1817
|
-
var matchedRoute = compiled[i].route;
|
|
1818
|
-
var localComp = payload;
|
|
1819
|
-
var update = lastUpdate = function(comp) {
|
|
1820
|
-
if (update !== lastUpdate) return
|
|
1821
|
-
if (comp === SKIP) return loop(i + 1)
|
|
1822
|
-
component = comp != null && (typeof comp.view === "function" || typeof comp === "function")? comp : "div";
|
|
1823
|
-
attrs = data.params, currentPath = path, lastUpdate = null;
|
|
1824
|
-
currentResolver = payload.render ? payload : null;
|
|
1825
|
-
if (state === 2) mountRedraw.redraw();
|
|
1826
|
-
else {
|
|
1827
|
-
state = 2;
|
|
1828
|
-
mountRedraw.redraw.sync();
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
// There's no understating how much I *wish* I could
|
|
1832
|
-
// use `async`/`await` here...
|
|
1833
|
-
if (payload.view || typeof payload === "function") {
|
|
1834
|
-
payload = {};
|
|
1835
|
-
update(localComp);
|
|
1836
|
-
}
|
|
1837
|
-
else if (payload.onmatch) {
|
|
1838
|
-
p.then(function () {
|
|
1839
|
-
return payload.onmatch(data.params, path, matchedRoute)
|
|
1840
|
-
}).then(update, fail);
|
|
1841
|
-
}
|
|
1842
|
-
else update("div");
|
|
1843
|
-
return
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
fail();
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
// Set it unconditionally so `m.route.set` and `m.route.Link` both work,
|
|
1851
|
-
// even if neither `pushState` nor `hashchange` are supported. It's
|
|
1852
|
-
// cleared if `hashchange` is used, since that makes it automatically
|
|
1853
|
-
// async.
|
|
1854
|
-
fireAsync = function() {
|
|
1855
|
-
if (!scheduled) {
|
|
1856
|
-
scheduled = true;
|
|
1857
|
-
callAsync(resolveRoute);
|
|
1858
|
-
}
|
|
1859
|
-
};
|
|
1860
|
-
|
|
1861
|
-
if (typeof $window.history.pushState === "function") {
|
|
1862
|
-
onremove = function() {
|
|
1863
|
-
$window.removeEventListener("popstate", fireAsync, false);
|
|
1864
|
-
};
|
|
1865
|
-
$window.addEventListener("popstate", fireAsync, false);
|
|
1866
|
-
} else if (route.prefix[0] === "#") {
|
|
1867
|
-
fireAsync = null;
|
|
1868
|
-
onremove = function() {
|
|
1869
|
-
$window.removeEventListener("hashchange", resolveRoute, false);
|
|
1870
|
-
};
|
|
1871
|
-
$window.addEventListener("hashchange", resolveRoute, false);
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
return mountRedraw.mount(root, {
|
|
1875
|
-
onbeforeupdate: function() {
|
|
1876
|
-
state = state ? 2 : 1;
|
|
1877
|
-
return !(!state || sentinel === currentResolver)
|
|
1878
|
-
},
|
|
1879
|
-
oncreate: resolveRoute,
|
|
1880
|
-
onremove: onremove,
|
|
1881
|
-
view: function() {
|
|
1882
|
-
if (!state || sentinel === currentResolver) return
|
|
1883
|
-
// Wrap in a fragment to preserve existing key semantics
|
|
1884
|
-
var vnode$1 = [vnode(component, attrs.key, attrs)];
|
|
1885
|
-
if (currentResolver) vnode$1 = currentResolver.render(vnode$1[0]);
|
|
1886
|
-
return vnode$1
|
|
1887
|
-
},
|
|
1888
|
-
})
|
|
1889
|
-
}
|
|
1890
|
-
route.set = function(path, data, options) {
|
|
1891
|
-
if (lastUpdate != null) {
|
|
1892
|
-
options = options || {};
|
|
1893
|
-
options.replace = true;
|
|
1894
|
-
}
|
|
1895
|
-
lastUpdate = null;
|
|
1896
|
-
setPath(path, data, options);
|
|
1897
|
-
};
|
|
1898
|
-
route.get = function() {return currentPath};
|
|
1899
|
-
route.prefix = "#!";
|
|
1900
|
-
route.Link = {
|
|
1901
|
-
view: function(vnode) {
|
|
1902
|
-
var options = vnode.attrs.options;
|
|
1903
|
-
// Remove these so they don't get overwritten
|
|
1904
|
-
var attrs = {}, onclick, href;
|
|
1905
|
-
assign$1(attrs, vnode.attrs);
|
|
1906
|
-
// The first two are internal, but the rest are magic attributes
|
|
1907
|
-
// that need censored to not screw up rendering.
|
|
1908
|
-
attrs.selector = attrs.options = attrs.key = attrs.oninit =
|
|
1909
|
-
attrs.oncreate = attrs.onbeforeupdate = attrs.onupdate =
|
|
1910
|
-
attrs.onbeforeremove = attrs.onremove = null;
|
|
1911
|
-
|
|
1912
|
-
// Do this now so we can get the most current `href` and `disabled`.
|
|
1913
|
-
// Those attributes may also be specified in the selector, and we
|
|
1914
|
-
// should honor that.
|
|
1915
|
-
var child = hyperscript_1$1(vnode.attrs.selector || "a", attrs, vnode.children);
|
|
1916
|
-
|
|
1917
|
-
// Let's provide a *right* way to disable a route link, rather than
|
|
1918
|
-
// letting people screw up accessibility on accident.
|
|
1919
|
-
//
|
|
1920
|
-
// The attribute is coerced so users don't get surprised over
|
|
1921
|
-
// `disabled: 0` resulting in a button that's somehow routable
|
|
1922
|
-
// despite being visibly disabled.
|
|
1923
|
-
if (child.attrs.disabled = Boolean(child.attrs.disabled)) {
|
|
1924
|
-
child.attrs.href = null;
|
|
1925
|
-
child.attrs["aria-disabled"] = "true";
|
|
1926
|
-
// If you *really* do want to do this on a disabled link, use
|
|
1927
|
-
// an `oncreate` hook to add it.
|
|
1928
|
-
child.attrs.onclick = null;
|
|
1929
|
-
} else {
|
|
1930
|
-
onclick = child.attrs.onclick;
|
|
1931
|
-
href = child.attrs.href;
|
|
1932
|
-
child.attrs.href = route.prefix + href;
|
|
1933
|
-
child.attrs.onclick = function(e) {
|
|
1934
|
-
var result;
|
|
1935
|
-
if (typeof onclick === "function") {
|
|
1936
|
-
result = onclick.call(e.currentTarget, e);
|
|
1937
|
-
} else if (onclick == null || typeof onclick !== "object") ; else if (typeof onclick.handleEvent === "function") {
|
|
1938
|
-
onclick.handleEvent(e);
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
// Adapted from React Router's implementation:
|
|
1942
|
-
// https://github.com/ReactTraining/react-router/blob/520a0acd48ae1b066eb0b07d6d4d1790a1d02482/packages/react-router-dom/modules/Link.js
|
|
1943
|
-
//
|
|
1944
|
-
// Try to be flexible and intuitive in how we handle links.
|
|
1945
|
-
// Fun fact: links aren't as obvious to get right as you
|
|
1946
|
-
// would expect. There's a lot more valid ways to click a
|
|
1947
|
-
// link than this, and one might want to not simply click a
|
|
1948
|
-
// link, but right click or command-click it to copy the
|
|
1949
|
-
// link target, etc. Nope, this isn't just for blind people.
|
|
1950
|
-
if (
|
|
1951
|
-
// Skip if `onclick` prevented default
|
|
1952
|
-
result !== false && !e.defaultPrevented &&
|
|
1953
|
-
// Ignore everything but left clicks
|
|
1954
|
-
(e.button === 0 || e.which === 0 || e.which === 1) &&
|
|
1955
|
-
// Let the browser handle `target=_blank`, etc.
|
|
1956
|
-
(!e.currentTarget.target || e.currentTarget.target === "_self") &&
|
|
1957
|
-
// No modifier keys
|
|
1958
|
-
!e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey
|
|
1959
|
-
) {
|
|
1960
|
-
e.preventDefault();
|
|
1961
|
-
e.redraw = false;
|
|
1962
|
-
route.set(href, null, options);
|
|
1963
|
-
}
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
|
-
return child
|
|
1967
|
-
},
|
|
1968
|
-
};
|
|
1969
|
-
route.param = function(key) {
|
|
1970
|
-
return attrs && key != null ? attrs[key] : attrs
|
|
1971
|
-
};
|
|
1972
|
-
|
|
1973
|
-
return route
|
|
1974
|
-
};
|
|
1975
|
-
|
|
1976
|
-
var route = router(window, mountRedraw);
|
|
1977
|
-
|
|
1978
|
-
var m = function m() { return hyperscript_1.apply(this, arguments) };
|
|
1979
|
-
m.m = hyperscript_1;
|
|
1980
|
-
m.trust = hyperscript_1.trust;
|
|
1981
|
-
m.fragment = hyperscript_1.fragment;
|
|
1982
|
-
m.mount = mountRedraw.mount;
|
|
1983
|
-
m.route = route;
|
|
1984
|
-
m.render = render;
|
|
1985
|
-
m.redraw = mountRedraw.redraw;
|
|
1986
|
-
m.request = request.request;
|
|
1987
|
-
m.jsonp = request.jsonp;
|
|
1988
|
-
m.parseQueryString = parse$1;
|
|
1989
|
-
m.buildQueryString = build$2;
|
|
1990
|
-
m.parsePathname = parse;
|
|
1991
|
-
m.buildPathname = build$1;
|
|
1992
|
-
m.vnode = vnode;
|
|
1993
|
-
m.PromisePolyfill = polyfill;
|
|
1994
|
-
|
|
1995
|
-
var mithril = m;
|
|
1996
|
-
|
|
1997
|
-
var registry = {};
|
|
1998
|
-
/**
|
|
1999
|
-
* Gets a registered component for a given type name
|
|
2000
|
-
*
|
|
2001
|
-
* @public
|
|
2002
|
-
* @param type - The component type
|
|
2003
|
-
*/
|
|
2004
|
-
function getComponent(type) {
|
|
2005
|
-
if (registry[type]) {
|
|
2006
|
-
return registry[type];
|
|
2007
|
-
}
|
|
2008
|
-
throw new Error("Component of type '" + type + "' was not found");
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Registers a component
|
|
2012
|
-
*
|
|
2013
|
-
* @public
|
|
2014
|
-
* @param type - The component type name
|
|
2015
|
-
* @param comp - The component
|
|
2016
|
-
* @param override - Allows to override an already registered component
|
|
2017
|
-
*/
|
|
2018
|
-
function component(type, comp, override) {
|
|
2019
|
-
if (override === void 0) { override = false; }
|
|
2020
|
-
if (registry[type] && !override) {
|
|
2021
|
-
console.warn("Component ignored. Name '" + type + "' is already registered.");
|
|
2022
|
-
}
|
|
2023
|
-
else {
|
|
2024
|
-
registry[type] = comp;
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
/**
|
|
2029
|
-
* Renders a registered component using the model
|
|
2030
|
-
*
|
|
2031
|
-
* @public
|
|
2032
|
-
* @param model - The model
|
|
2033
|
-
*/
|
|
2034
|
-
function renderModel(model) {
|
|
2035
|
-
if (!model.type) {
|
|
2036
|
-
console.error(new Error('Given data is missing the .type property. Component can resolve the component'), model);
|
|
2037
|
-
return null;
|
|
2038
|
-
}
|
|
2039
|
-
if (model.hidden) {
|
|
2040
|
-
return null;
|
|
2041
|
-
}
|
|
2042
|
-
return mithril(getComponent(model.type), { data: model });
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
/**
|
|
2046
|
-
* Gets a value of a view model
|
|
2047
|
-
*
|
|
2048
|
-
* @public
|
|
2049
|
-
* @param model - The model of a component
|
|
2050
|
-
*/
|
|
2051
|
-
function getValue(model) {
|
|
2052
|
-
return decode(model, readValue(model));
|
|
2053
|
-
}
|
|
2054
|
-
/**
|
|
2055
|
-
* Sets a value on a view model
|
|
2056
|
-
*
|
|
2057
|
-
* @public
|
|
2058
|
-
* @param model - The model of a component
|
|
2059
|
-
* @param value - The value for the component
|
|
2060
|
-
* @returns the encoded value as it was written to the model
|
|
2061
|
-
*/
|
|
2062
|
-
function setValue(model, value) {
|
|
2063
|
-
var encoded = encode(model, value);
|
|
2064
|
-
writeValue(model, encoded);
|
|
2065
|
-
return encoded;
|
|
2066
|
-
}
|
|
2067
|
-
function readValue(model) {
|
|
2068
|
-
if ('target' in model &&
|
|
2069
|
-
model.target &&
|
|
2070
|
-
model.property != null &&
|
|
2071
|
-
model.property in model.target) {
|
|
2072
|
-
return model.target[model.property];
|
|
2073
|
-
}
|
|
2074
|
-
if ('value' in model) {
|
|
2075
|
-
return model.value;
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
function writeValue(model, value) {
|
|
2079
|
-
if ('target' in model && model.target && model.property != null) {
|
|
2080
|
-
model.target[model.property] = value;
|
|
2081
|
-
}
|
|
2082
|
-
else if (isWriteable(model, 'value')) {
|
|
2083
|
-
model.value = value;
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
function isWriteable(obj, key) {
|
|
2087
|
-
var desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
2088
|
-
return !desc || !!desc.writable || !!desc.set;
|
|
2089
|
-
}
|
|
2090
|
-
function encode(source, value) {
|
|
2091
|
-
return 'codec' in source && source.codec ? source.codec.encode(value) : value;
|
|
2092
|
-
}
|
|
2093
|
-
function decode(source, value) {
|
|
2094
|
-
return 'codec' in source && source.codec ? source.codec.decode(value) : value;
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
/**
|
|
2098
|
-
* Checks if value is a string
|
|
2099
|
-
* @internal
|
|
2100
|
-
*/
|
|
2101
|
-
function isString(v) {
|
|
2102
|
-
return typeof v === 'string';
|
|
2103
|
-
}
|
|
2104
|
-
/**
|
|
2105
|
-
* Checks if value is a number
|
|
2106
|
-
* @internal
|
|
2107
|
-
*/
|
|
2108
|
-
function isNumber(v) {
|
|
2109
|
-
return typeof v === 'number';
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* Checks if value is a function
|
|
2113
|
-
* @internal
|
|
2114
|
-
*/
|
|
2115
|
-
function isFunction(v) {
|
|
2116
|
-
return typeof v === 'function';
|
|
2117
|
-
}
|
|
2118
|
-
/**
|
|
2119
|
-
* Checks if value is an array
|
|
2120
|
-
* @internal
|
|
2121
|
-
*/
|
|
2122
|
-
function isArray(v) {
|
|
2123
|
-
return Array.isArray(v);
|
|
2124
|
-
}
|
|
2125
|
-
/**
|
|
2126
|
-
* Checks if value is an object
|
|
2127
|
-
* @internal
|
|
2128
|
-
*/
|
|
2129
|
-
function isObject(v) {
|
|
2130
|
-
return v != null && typeof v === 'object' && !isArray(v);
|
|
2131
|
-
}
|
|
2132
|
-
/**
|
|
2133
|
-
* Calls a function if it is not null
|
|
2134
|
-
* @internal
|
|
2135
|
-
*/
|
|
2136
|
-
function call(cb) {
|
|
2137
|
-
var args = [];
|
|
2138
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2139
|
-
args[_i - 1] = arguments[_i];
|
|
2140
|
-
}
|
|
2141
|
-
return isFunction(cb) ? cb.apply(void 0, args) : null;
|
|
2142
|
-
}
|
|
2143
|
-
/**
|
|
2144
|
-
* Resolves a property to its value
|
|
2145
|
-
* @param value - the function or value to resolve
|
|
2146
|
-
*/
|
|
2147
|
-
function resolve(value) {
|
|
2148
|
-
return isFunction(value) ? value() : value;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
* Calls the callback of object is not null
|
|
2152
|
-
* @internal
|
|
2153
|
-
*/
|
|
2154
|
-
function use(obj, cb) {
|
|
2155
|
-
return obj == null ? null : cb(obj);
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Clamps a number value
|
|
2159
|
-
* @internal
|
|
2160
|
-
*/
|
|
2161
|
-
function clamp(v, min, max) {
|
|
2162
|
-
if (v != null) {
|
|
2163
|
-
if (min != null && v < min) {
|
|
2164
|
-
return min;
|
|
2165
|
-
}
|
|
2166
|
-
if (max != null && v > max) {
|
|
2167
|
-
return max;
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
return v;
|
|
2171
|
-
}
|
|
2172
|
-
/**
|
|
2173
|
-
* Builds a css class from various argument types
|
|
2174
|
-
* @param exp
|
|
2175
|
-
*/
|
|
2176
|
-
function cssClass(exp) {
|
|
2177
|
-
if (!exp) {
|
|
2178
|
-
return null;
|
|
2179
|
-
}
|
|
2180
|
-
if (isString(exp)) {
|
|
2181
|
-
return exp;
|
|
2182
|
-
}
|
|
2183
|
-
if (isArray(exp)) {
|
|
2184
|
-
return exp.map(cssClass).join(' ');
|
|
2185
|
-
}
|
|
2186
|
-
return Object.keys(exp)
|
|
2187
|
-
.filter(function (it) { return resolve(exp[it]); })
|
|
2188
|
-
.filter(function (it) { return isString(it) && !!it; })
|
|
2189
|
-
.join(' ');
|
|
2190
|
-
}
|
|
2191
|
-
/**
|
|
2192
|
-
* Pads a string
|
|
2193
|
-
* @internal
|
|
2194
|
-
*/
|
|
2195
|
-
function padLeft(value, length, char) {
|
|
2196
|
-
while (value.length < length) {
|
|
2197
|
-
value = "" + char + value;
|
|
2198
|
-
}
|
|
2199
|
-
return value;
|
|
2200
|
-
}
|
|
2201
|
-
/**
|
|
2202
|
-
* @internal
|
|
2203
|
-
*/
|
|
2204
|
-
function twuiClass(name, variation) {
|
|
2205
|
-
return "twui-" + name + (variation ? "-" + variation : '');
|
|
2206
|
-
}
|
|
2207
|
-
/**
|
|
2208
|
-
* Gets current mouse coordinates from mouse or touch event
|
|
2209
|
-
* @internal
|
|
2210
|
-
*/
|
|
2211
|
-
function getMouseXY(e) {
|
|
2212
|
-
var cx = 0;
|
|
2213
|
-
var cy = 0;
|
|
2214
|
-
if ('touches' in e) {
|
|
2215
|
-
cx = e.touches.item(0).pageX;
|
|
2216
|
-
cy = e.touches.item(0).pageY;
|
|
2217
|
-
}
|
|
2218
|
-
else {
|
|
2219
|
-
cx = e.pageX;
|
|
2220
|
-
cy = e.pageY;
|
|
2221
|
-
}
|
|
2222
|
-
return [cx, cy];
|
|
2223
|
-
}
|
|
2224
|
-
function getTouchPosition(target, e) {
|
|
2225
|
-
var rect = target.getBoundingClientRect();
|
|
2226
|
-
var tx = window.pageXOffset || document.documentElement.scrollLeft;
|
|
2227
|
-
var ty = window.pageYOffset || document.documentElement.scrollTop;
|
|
2228
|
-
var cw = target.clientWidth;
|
|
2229
|
-
var ch = target.clientHeight;
|
|
2230
|
-
var _a = getMouseXY(e), cx = _a[0], cy = _a[1];
|
|
2231
|
-
var x = cx - tx - rect.left;
|
|
2232
|
-
var y = cy - ty - rect.top;
|
|
2233
|
-
return {
|
|
2234
|
-
width: cw,
|
|
2235
|
-
height: ch,
|
|
2236
|
-
x: x,
|
|
2237
|
-
y: y,
|
|
2238
|
-
normalizedX: x / cw,
|
|
2239
|
-
normalizedY: y / ch,
|
|
2240
|
-
};
|
|
2241
|
-
}
|
|
2242
|
-
/**
|
|
2243
|
-
* @internal
|
|
2244
|
-
*/
|
|
2245
|
-
function viewFn(fn) {
|
|
2246
|
-
return function (node) {
|
|
2247
|
-
return use(node.attrs.data, function (data) { return fn(data, node); });
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
function dragUtil(_a) {
|
|
2251
|
-
var onStart = _a.onStart, onMove = _a.onMove, onEnd = _a.onEnd;
|
|
2252
|
-
var util = {
|
|
2253
|
-
target: null,
|
|
2254
|
-
activate: function (e) {
|
|
2255
|
-
util.deactivate();
|
|
2256
|
-
util.target = e.target;
|
|
2257
|
-
if (onStart) {
|
|
2258
|
-
onStart(e);
|
|
2259
|
-
}
|
|
2260
|
-
if (onMove) {
|
|
2261
|
-
document.addEventListener('mousemove', onMove, { passive: false });
|
|
2262
|
-
document.addEventListener('touchmove', onMove, { passive: false });
|
|
2263
|
-
}
|
|
2264
|
-
if (onEnd) {
|
|
2265
|
-
document.addEventListener('mouseup', onEnd);
|
|
2266
|
-
document.addEventListener('touchend', onEnd);
|
|
2267
|
-
document.addEventListener('touchcancel', onEnd);
|
|
2268
|
-
}
|
|
2269
|
-
},
|
|
2270
|
-
deactivate: function () {
|
|
2271
|
-
util.target = null;
|
|
2272
|
-
if (onMove) {
|
|
2273
|
-
document.removeEventListener('mousemove', onMove);
|
|
2274
|
-
document.removeEventListener('touchmove', onMove);
|
|
2275
|
-
}
|
|
2276
|
-
if (onEnd) {
|
|
2277
|
-
document.removeEventListener('mouseup', onEnd);
|
|
2278
|
-
document.removeEventListener('touchend', onEnd);
|
|
2279
|
-
document.removeEventListener('touchcancel', onEnd);
|
|
2280
|
-
}
|
|
2281
|
-
},
|
|
2282
|
-
onStart: onStart,
|
|
2283
|
-
onMove: onMove,
|
|
2284
|
-
onEnd: onEnd,
|
|
2285
|
-
};
|
|
2286
|
-
return util;
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
var TYPE$8 = 'angle';
|
|
2290
|
-
var AngleComponent = function (vnode) {
|
|
2291
|
-
var angle = 0;
|
|
2292
|
-
var dragged = false;
|
|
2293
|
-
var pos = [0, 0];
|
|
2294
|
-
function toDeg(value) {
|
|
2295
|
-
return value * (180 / Math.PI);
|
|
2296
|
-
}
|
|
2297
|
-
function toRad(value) {
|
|
2298
|
-
return value * (Math.PI / 180);
|
|
2299
|
-
}
|
|
2300
|
-
function toScreen(value) {
|
|
2301
|
-
return clamp((value / 2 + 0.5) * 100, 0, 100);
|
|
2302
|
-
}
|
|
2303
|
-
function fetchValue(node) {
|
|
2304
|
-
var _a;
|
|
2305
|
-
var data = node.attrs.data;
|
|
2306
|
-
angle = (_a = getValue(data)) !== null && _a !== void 0 ? _a : angle;
|
|
2307
|
-
if (data.degree) {
|
|
2308
|
-
angle = toRad(angle);
|
|
2309
|
-
}
|
|
2310
|
-
updatePositions();
|
|
2311
|
-
}
|
|
2312
|
-
function onChange(type) {
|
|
2313
|
-
updatePositions();
|
|
2314
|
-
var data = vnode.attrs.data;
|
|
2315
|
-
var value = data.degree ? toRad(angle) : angle;
|
|
2316
|
-
var written = setValue(data, value);
|
|
2317
|
-
call(type === 'input' ? data.onInput : data.onChange, data, written);
|
|
2318
|
-
}
|
|
2319
|
-
function updatePositions() {
|
|
2320
|
-
pos[0] = Math.cos(angle);
|
|
2321
|
-
pos[1] = Math.sin(angle);
|
|
2322
|
-
}
|
|
2323
|
-
function onStartPhi(e) {
|
|
2324
|
-
dragged = true;
|
|
2325
|
-
drag.activate(e);
|
|
2326
|
-
}
|
|
2327
|
-
var drag = dragUtil({
|
|
2328
|
-
onStart: function (e) {
|
|
2329
|
-
drag.onMove(e);
|
|
2330
|
-
},
|
|
2331
|
-
onMove: function (e) {
|
|
2332
|
-
e.preventDefault();
|
|
2333
|
-
var position = getTouchPosition(drag.target.parentElement, e);
|
|
2334
|
-
var px = position.normalizedX - 0.5;
|
|
2335
|
-
var py = position.normalizedY - 0.5;
|
|
2336
|
-
if (dragged) {
|
|
2337
|
-
// [-PI;PI]
|
|
2338
|
-
angle = Math.atan2(px, py);
|
|
2339
|
-
// convert to range [0;2PI]
|
|
2340
|
-
angle += angle < 0 ? 2 * Math.PI : 0;
|
|
2341
|
-
}
|
|
2342
|
-
onChange('input');
|
|
2343
|
-
mithril.redraw();
|
|
2344
|
-
},
|
|
2345
|
-
onEnd: function (e) {
|
|
2346
|
-
drag.deactivate();
|
|
2347
|
-
dragged = false;
|
|
2348
|
-
onChange('change');
|
|
2349
|
-
mithril.redraw();
|
|
2350
|
-
},
|
|
2351
|
-
});
|
|
2352
|
-
function onPhiInput(model, value) {
|
|
2353
|
-
angle = toRad(value);
|
|
2354
|
-
onChange('input');
|
|
2355
|
-
}
|
|
2356
|
-
function onPhiChange(model, value) {
|
|
2357
|
-
angle = toRad(value);
|
|
2358
|
-
onChange('change');
|
|
2359
|
-
}
|
|
2360
|
-
return {
|
|
2361
|
-
onremove: function () {
|
|
2362
|
-
drag.deactivate();
|
|
2363
|
-
},
|
|
2364
|
-
oninit: function (node) {
|
|
2365
|
-
fetchValue(node);
|
|
2366
|
-
},
|
|
2367
|
-
onupdate: function (node) {
|
|
2368
|
-
fetchValue(node);
|
|
2369
|
-
},
|
|
2370
|
-
view: function () {
|
|
2371
|
-
return mithril('div', {
|
|
2372
|
-
class: twuiClass(TYPE$8),
|
|
2373
|
-
style: {
|
|
2374
|
-
'--angle-value': toDeg(-angle) + 90 + "deg",
|
|
2375
|
-
'--angle-percent': (toDeg(angle) / 360) * 100 + "%",
|
|
2376
|
-
},
|
|
2377
|
-
}, mithril('div.left-container', mithril('div.pane', {
|
|
2378
|
-
style: {
|
|
2379
|
-
position: 'relative',
|
|
2380
|
-
width: '100%',
|
|
2381
|
-
'padding-top': '100%',
|
|
2382
|
-
},
|
|
2383
|
-
}, mithril('div.angle-pane', {
|
|
2384
|
-
class: cssClass({
|
|
2385
|
-
'is-dragging': dragged,
|
|
2386
|
-
}),
|
|
2387
|
-
style: {
|
|
2388
|
-
position: 'absolute',
|
|
2389
|
-
top: '0.5rem',
|
|
2390
|
-
left: '0.5rem',
|
|
2391
|
-
width: 'calc(100% - 1rem)',
|
|
2392
|
-
height: 'calc(100% - 1rem)',
|
|
2393
|
-
},
|
|
2394
|
-
}, mithril('div.angle-knob', {
|
|
2395
|
-
onmousedown: onStartPhi,
|
|
2396
|
-
ontouchstart: onStartPhi,
|
|
2397
|
-
style: {
|
|
2398
|
-
position: 'absolute',
|
|
2399
|
-
width: '15px',
|
|
2400
|
-
height: '15px',
|
|
2401
|
-
top: "calc(" + toScreen(pos[0]) + "% - 7px)",
|
|
2402
|
-
left: "calc(" + toScreen(pos[1]) + "% - 7px)",
|
|
2403
|
-
},
|
|
2404
|
-
})))), mithril('div.right-container', mithril('label', mithril.trust('α')), renderModel({
|
|
2405
|
-
type: 'number',
|
|
2406
|
-
min: 0,
|
|
2407
|
-
max: 360,
|
|
2408
|
-
step: 0.1,
|
|
2409
|
-
value: toDeg(angle),
|
|
2410
|
-
onInput: onPhiInput,
|
|
2411
|
-
onChange: onPhiChange,
|
|
2412
|
-
})));
|
|
2413
|
-
},
|
|
2414
|
-
};
|
|
2415
|
-
};
|
|
2416
|
-
component(TYPE$8, AngleComponent);
|
|
2417
|
-
function angleCodec(_a) {
|
|
2418
|
-
var _b = _a === void 0 ? {} : _a, axes = _b.axes, length = _b.length, result = _b.result;
|
|
2419
|
-
axes = axes || { x: 'right', y: 'up' };
|
|
2420
|
-
var keys = Object.keys(axes);
|
|
2421
|
-
var radius = function () {
|
|
2422
|
-
return (typeof length === 'function' ? length() : length) || 1;
|
|
2423
|
-
};
|
|
2424
|
-
return {
|
|
2425
|
-
decode: function (value) {
|
|
2426
|
-
var x = 0;
|
|
2427
|
-
var y = 0;
|
|
2428
|
-
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
2429
|
-
var key = keys_1[_i];
|
|
2430
|
-
switch (axes[key]) {
|
|
2431
|
-
case 'right':
|
|
2432
|
-
y = value[key];
|
|
2433
|
-
break;
|
|
2434
|
-
case 'left':
|
|
2435
|
-
y = -value[key];
|
|
2436
|
-
break;
|
|
2437
|
-
case 'up':
|
|
2438
|
-
case 'front':
|
|
2439
|
-
x = -value[key];
|
|
2440
|
-
break;
|
|
2441
|
-
case 'down':
|
|
2442
|
-
case 'back':
|
|
2443
|
-
x = value[key];
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
var r = radius();
|
|
2447
|
-
x /= r;
|
|
2448
|
-
y /= r;
|
|
2449
|
-
return Math.atan2(y, x) || 0;
|
|
2450
|
-
},
|
|
2451
|
-
encode: function (angle) {
|
|
2452
|
-
var r = radius();
|
|
2453
|
-
var x = r * Math.cos(angle);
|
|
2454
|
-
var y = r * Math.sin(angle);
|
|
2455
|
-
var value = result() || {};
|
|
2456
|
-
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
|
2457
|
-
var key = keys_2[_i];
|
|
2458
|
-
switch (axes[key]) {
|
|
2459
|
-
case 'right':
|
|
2460
|
-
value[key] = y;
|
|
2461
|
-
break;
|
|
2462
|
-
case 'left':
|
|
2463
|
-
value[key] = -y;
|
|
2464
|
-
break;
|
|
2465
|
-
case 'up':
|
|
2466
|
-
case 'front':
|
|
2467
|
-
value[key] = -x;
|
|
2468
|
-
break;
|
|
2469
|
-
case 'down':
|
|
2470
|
-
case 'back':
|
|
2471
|
-
value[key] = x;
|
|
2472
|
-
break;
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
return value;
|
|
2476
|
-
},
|
|
2477
|
-
};
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
var TYPE$7 = 'checkbox';
|
|
2481
|
-
var CheckboxComponent = function (node) {
|
|
2482
|
-
function onChange(e) {
|
|
2483
|
-
var data = node.attrs.data;
|
|
2484
|
-
var checked = e.target.checked;
|
|
2485
|
-
var written = setValue(data, checked);
|
|
2486
|
-
call(data.onChange, data, written);
|
|
2487
|
-
}
|
|
2488
|
-
return {
|
|
2489
|
-
view: viewFn(function (data) {
|
|
2490
|
-
var _a;
|
|
2491
|
-
var checked = getValue(data) === true;
|
|
2492
|
-
return mithril('label', {
|
|
2493
|
-
class: cssClass((_a = {},
|
|
2494
|
-
_a[twuiClass(TYPE$7)] = true,
|
|
2495
|
-
_a.checked = checked,
|
|
2496
|
-
_a.disabled = data.disabled,
|
|
2497
|
-
_a)),
|
|
2498
|
-
}, mithril('input', {
|
|
2499
|
-
type: 'checkbox',
|
|
2500
|
-
checked: checked,
|
|
2501
|
-
onchange: onChange,
|
|
2502
|
-
disabled: data.disabled,
|
|
2503
|
-
}), data.text);
|
|
2504
|
-
}),
|
|
2505
|
-
};
|
|
2506
|
-
};
|
|
2507
|
-
component(TYPE$7, CheckboxComponent);
|
|
2508
|
-
|
|
2509
|
-
/*! *****************************************************************************
|
|
2510
|
-
Copyright (c) Microsoft Corporation.
|
|
2511
|
-
|
|
2512
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
2513
|
-
purpose with or without fee is hereby granted.
|
|
2514
|
-
|
|
2515
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2516
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2517
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2518
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2519
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2520
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2521
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
2522
|
-
***************************************************************************** */
|
|
2523
|
-
|
|
2524
|
-
var __assign = function() {
|
|
2525
|
-
__assign = Object.assign || function __assign(t) {
|
|
2526
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2527
|
-
s = arguments[i];
|
|
2528
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2529
|
-
}
|
|
2530
|
-
return t;
|
|
2531
|
-
};
|
|
2532
|
-
return __assign.apply(this, arguments);
|
|
2533
|
-
};
|
|
2534
|
-
|
|
2535
|
-
/**
|
|
2536
|
-
* Converts hsv to rgb
|
|
2537
|
-
*
|
|
2538
|
-
* @public
|
|
2539
|
-
* @param hsv - HSV components where H is in range [0:360] and S and V are in range [0:1]
|
|
2540
|
-
* @returns RGB color components in range [0:1]
|
|
2541
|
-
*/
|
|
2542
|
-
function hsv2rgb(hsv) {
|
|
2543
|
-
var H = hsv.h % 360;
|
|
2544
|
-
var S = clamp(hsv.s, 0, 1);
|
|
2545
|
-
var V = clamp(hsv.v, 0, 1);
|
|
2546
|
-
var C = V * S;
|
|
2547
|
-
var X = C * (1 - Math.abs(((H / 60) % 2) - 1));
|
|
2548
|
-
var m = V - C;
|
|
2549
|
-
var rgb = { r: 0, g: 0, b: 0 };
|
|
2550
|
-
if (H < 60) {
|
|
2551
|
-
rgb.r = C;
|
|
2552
|
-
rgb.g = X;
|
|
2553
|
-
rgb.b = 0;
|
|
2554
|
-
}
|
|
2555
|
-
else if (H < 120) {
|
|
2556
|
-
rgb.r = X;
|
|
2557
|
-
rgb.g = C;
|
|
2558
|
-
rgb.b = 0;
|
|
2559
|
-
}
|
|
2560
|
-
else if (H < 180) {
|
|
2561
|
-
rgb.r = 0;
|
|
2562
|
-
rgb.g = C;
|
|
2563
|
-
rgb.b = X;
|
|
2564
|
-
}
|
|
2565
|
-
else if (H < 240) {
|
|
2566
|
-
rgb.r = 0;
|
|
2567
|
-
rgb.g = X;
|
|
2568
|
-
rgb.b = C;
|
|
2569
|
-
}
|
|
2570
|
-
else if (H < 300) {
|
|
2571
|
-
rgb.r = X;
|
|
2572
|
-
rgb.g = 0;
|
|
2573
|
-
rgb.b = C;
|
|
2574
|
-
}
|
|
2575
|
-
else {
|
|
2576
|
-
rgb.r = C;
|
|
2577
|
-
rgb.g = 0;
|
|
2578
|
-
rgb.b = X;
|
|
2579
|
-
}
|
|
2580
|
-
rgb.r += m;
|
|
2581
|
-
rgb.g += m;
|
|
2582
|
-
rgb.b += m;
|
|
2583
|
-
return rgb;
|
|
2584
|
-
}
|
|
2585
|
-
/**
|
|
2586
|
-
* Converts rgb to hsv
|
|
2587
|
-
*
|
|
2588
|
-
* @public
|
|
2589
|
-
* @remarks
|
|
2590
|
-
* The RGB components are assumed to be in range [0:1].
|
|
2591
|
-
* The resulting H component is in range [0:360] and S and V in range [0:1]
|
|
2592
|
-
*/
|
|
2593
|
-
function rgb2hsv(rgb) {
|
|
2594
|
-
var r = rgb.r;
|
|
2595
|
-
var g = rgb.g;
|
|
2596
|
-
var b = rgb.b;
|
|
2597
|
-
var V = Math.max(r, g, b);
|
|
2598
|
-
var d = V - Math.min(r, g, b);
|
|
2599
|
-
var S = 0;
|
|
2600
|
-
var H = 0;
|
|
2601
|
-
if (d !== 0) {
|
|
2602
|
-
S = d / V;
|
|
2603
|
-
if (V === r) {
|
|
2604
|
-
H = (g - b) / d + (g < b ? 6 : 0);
|
|
2605
|
-
H = (H % 6) * 60;
|
|
2606
|
-
}
|
|
2607
|
-
else if (V === g) {
|
|
2608
|
-
H = (b - r) / d + 2;
|
|
2609
|
-
H = H * 60;
|
|
2610
|
-
}
|
|
2611
|
-
else {
|
|
2612
|
-
H = (r - g) / d + 4;
|
|
2613
|
-
H = H * 60;
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
return { h: H, s: S, v: V };
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
var ArrayColorFormat = /** @class */ (function () {
|
|
2620
|
-
function ArrayColorFormat(components, normalized) {
|
|
2621
|
-
this.components = components;
|
|
2622
|
-
this.normalized = normalized;
|
|
2623
|
-
}
|
|
2624
|
-
ArrayColorFormat.prototype.parse = function (v) {
|
|
2625
|
-
var _this = this;
|
|
2626
|
-
v = v || [];
|
|
2627
|
-
var result = { r: 0, g: 0, b: 0, a: 1 };
|
|
2628
|
-
this.components.forEach(function (key, i) {
|
|
2629
|
-
result[key] = (v[i] || 0) / (_this.normalized ? 1 : 255);
|
|
2630
|
-
});
|
|
2631
|
-
return result;
|
|
2632
|
-
};
|
|
2633
|
-
ArrayColorFormat.prototype.format = function (rgba) {
|
|
2634
|
-
var _this = this;
|
|
2635
|
-
return this.components.map(function (key) { return (_this.normalized ? rgba[key] : Math.round(rgba[key] * 255)) || 0; });
|
|
2636
|
-
};
|
|
2637
|
-
return ArrayColorFormat;
|
|
2638
|
-
}());
|
|
2639
|
-
|
|
2640
|
-
var CssStringFormat = /** @class */ (function () {
|
|
2641
|
-
function CssStringFormat(components) {
|
|
2642
|
-
this.components = components;
|
|
2643
|
-
}
|
|
2644
|
-
CssStringFormat.prototype.parse = function (value) {
|
|
2645
|
-
value = value || 'rgba(0, 0, 0)';
|
|
2646
|
-
var result = { r: 0, g: 0, b: 0, a: 1 };
|
|
2647
|
-
var values = value
|
|
2648
|
-
.replace(/[rgba\(\)]/gi, '')
|
|
2649
|
-
.split(/,\s*?/gi)
|
|
2650
|
-
.map(Number);
|
|
2651
|
-
this.components.forEach(function (key, i) {
|
|
2652
|
-
result[key] = (values[i] || 0) / (key === 'a' ? 1 : 255);
|
|
2653
|
-
});
|
|
2654
|
-
return result;
|
|
2655
|
-
};
|
|
2656
|
-
CssStringFormat.prototype.format = function (rgba) {
|
|
2657
|
-
return (this.components.join('') +
|
|
2658
|
-
'(' +
|
|
2659
|
-
this.components
|
|
2660
|
-
.map(function (key) {
|
|
2661
|
-
return key === 'a' ? rgba[key] : Math.round(rgba[key] * 255);
|
|
2662
|
-
})
|
|
2663
|
-
.join(', ') +
|
|
2664
|
-
')');
|
|
2665
|
-
};
|
|
2666
|
-
return CssStringFormat;
|
|
2667
|
-
}());
|
|
2668
|
-
|
|
2669
|
-
var HexStringFormat = /** @class */ (function () {
|
|
2670
|
-
function HexStringFormat(components) {
|
|
2671
|
-
this.components = components;
|
|
2672
|
-
}
|
|
2673
|
-
HexStringFormat.prototype.parse = function (value) {
|
|
2674
|
-
value = value || '#000';
|
|
2675
|
-
var result = { r: 0, g: 0, b: 0, a: 1 };
|
|
2676
|
-
var v = value.match(/[0-9a-f]+/i)[0];
|
|
2677
|
-
if (v.length === this.components.length) {
|
|
2678
|
-
v = v
|
|
2679
|
-
.split('')
|
|
2680
|
-
.map(function (it) { return "" + it + it; })
|
|
2681
|
-
.join('');
|
|
2682
|
-
}
|
|
2683
|
-
this.components.forEach(function (key, i) {
|
|
2684
|
-
result[key] = parseInt(v.substr(i * 2, 2), 16) / 255;
|
|
2685
|
-
});
|
|
2686
|
-
return result;
|
|
2687
|
-
};
|
|
2688
|
-
HexStringFormat.prototype.format = function (rgba) {
|
|
2689
|
-
return ('#' +
|
|
2690
|
-
this.components
|
|
2691
|
-
.map(function (key) { return padLeft(Math.round(rgba[key] * 255).toString(16), 2, '0'); })
|
|
2692
|
-
.join(''));
|
|
2693
|
-
};
|
|
2694
|
-
return HexStringFormat;
|
|
2695
|
-
}());
|
|
2696
|
-
|
|
2697
|
-
// tslint:disable:no-bitwise
|
|
2698
|
-
var NumberColorFormat = /** @class */ (function () {
|
|
2699
|
-
function NumberColorFormat(components) {
|
|
2700
|
-
this.components = components;
|
|
2701
|
-
this.componentsRev = components.slice().reverse();
|
|
2702
|
-
}
|
|
2703
|
-
NumberColorFormat.prototype.parse = function (v) {
|
|
2704
|
-
v = v || 0;
|
|
2705
|
-
var result = { r: 0, g: 0, b: 0, a: 1 };
|
|
2706
|
-
this.components.forEach(function (key, i) {
|
|
2707
|
-
result[key] = ((v >> (i * 8)) & 255) / 255;
|
|
2708
|
-
});
|
|
2709
|
-
return result;
|
|
2710
|
-
};
|
|
2711
|
-
NumberColorFormat.prototype.format = function (rgba) {
|
|
2712
|
-
var val = this.componentsRev
|
|
2713
|
-
.map(function (key) {
|
|
2714
|
-
return padLeft(Math.round(rgba[key] * 255 || 0).toString(16), 2, '0');
|
|
2715
|
-
})
|
|
2716
|
-
.join('');
|
|
2717
|
-
return parseInt('0x' + val, 16);
|
|
2718
|
-
};
|
|
2719
|
-
return NumberColorFormat;
|
|
2720
|
-
}());
|
|
2721
|
-
|
|
2722
|
-
var ObjectColorFormat = /** @class */ (function () {
|
|
2723
|
-
function ObjectColorFormat(components, normalized) {
|
|
2724
|
-
this.components = components;
|
|
2725
|
-
this.normalized = normalized;
|
|
2726
|
-
}
|
|
2727
|
-
ObjectColorFormat.prototype.parse = function (v) {
|
|
2728
|
-
var _this = this;
|
|
2729
|
-
v = v || {};
|
|
2730
|
-
var result = { r: 0, g: 0, b: 0, a: 1 };
|
|
2731
|
-
this.components.forEach(function (key, i) {
|
|
2732
|
-
result[key] = (v[key] || 0) / (_this.normalized ? 1 : 255);
|
|
2733
|
-
});
|
|
2734
|
-
return result;
|
|
2735
|
-
};
|
|
2736
|
-
ObjectColorFormat.prototype.format = function (rgba) {
|
|
2737
|
-
var _this = this;
|
|
2738
|
-
var result = {};
|
|
2739
|
-
this.components.forEach(function (key, i) {
|
|
2740
|
-
result[key] =
|
|
2741
|
-
(_this.normalized ? rgba[key] : Math.round(rgba[key] * 255)) || 0;
|
|
2742
|
-
});
|
|
2743
|
-
return result;
|
|
2744
|
-
};
|
|
2745
|
-
return ObjectColorFormat;
|
|
2746
|
-
}());
|
|
2747
|
-
|
|
2748
|
-
var formatter = {};
|
|
2749
|
-
/**
|
|
2750
|
-
* Gets a formatter implementation for the given format
|
|
2751
|
-
*
|
|
2752
|
-
* @public
|
|
2753
|
-
* @param format - The format code
|
|
2754
|
-
*/
|
|
2755
|
-
function getColorFormatter(format) {
|
|
2756
|
-
if (format === void 0) { format = 'rgb'; }
|
|
2757
|
-
if (format in formatter) {
|
|
2758
|
-
return formatter[format];
|
|
2759
|
-
}
|
|
2760
|
-
var components = (format.match(/[rgba]+/)[0] || '').split('');
|
|
2761
|
-
if (/(\[n?\])/.test(format)) {
|
|
2762
|
-
formatter[format] = new ArrayColorFormat(components, /\[n\]/.test(format));
|
|
2763
|
-
}
|
|
2764
|
-
else if (/(\{n?\})/.test(format)) {
|
|
2765
|
-
formatter[format] = new ObjectColorFormat(components, /\{n\}/.test(format));
|
|
2766
|
-
}
|
|
2767
|
-
else if (/0x/.test(format)) {
|
|
2768
|
-
formatter[format] = new NumberColorFormat(components);
|
|
2769
|
-
}
|
|
2770
|
-
else if (/(\(\))/.test(format)) {
|
|
2771
|
-
formatter[format] = new CssStringFormat(components);
|
|
2772
|
-
}
|
|
2773
|
-
else {
|
|
2774
|
-
formatter[format] = new HexStringFormat(components);
|
|
2775
|
-
}
|
|
2776
|
-
return formatter[format];
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
|
-
component('color-picker', function (node) {
|
|
2780
|
-
var hue = 0; // range [0,1]
|
|
2781
|
-
var sat = 0; // range [0,1]
|
|
2782
|
-
var val = 0; // range [0,1]
|
|
2783
|
-
var a = 0; // range [0,1]
|
|
2784
|
-
function getHSVA(s, v) {
|
|
2785
|
-
if (s === void 0) { s = sat; }
|
|
2786
|
-
if (v === void 0) { v = val; }
|
|
2787
|
-
return {
|
|
2788
|
-
h: hue * 360,
|
|
2789
|
-
s: s,
|
|
2790
|
-
v: v,
|
|
2791
|
-
a: a,
|
|
2792
|
-
};
|
|
2793
|
-
}
|
|
2794
|
-
function getRGB(s, v) {
|
|
2795
|
-
if (s === void 0) { s = sat; }
|
|
2796
|
-
if (v === void 0) { v = val; }
|
|
2797
|
-
return hsv2rgb(getHSVA(s, v));
|
|
2798
|
-
}
|
|
2799
|
-
function getRGBA(s, v, alpha) {
|
|
2800
|
-
if (s === void 0) { s = sat; }
|
|
2801
|
-
if (v === void 0) { v = val; }
|
|
2802
|
-
if (alpha === void 0) { alpha = a; }
|
|
2803
|
-
return __assign(__assign({}, getRGB(s, v)), { a: alpha });
|
|
2804
|
-
}
|
|
2805
|
-
function setHSV(hsv) {
|
|
2806
|
-
hue = hsv.h / 360;
|
|
2807
|
-
sat = hsv.s;
|
|
2808
|
-
val = hsv.v;
|
|
2809
|
-
}
|
|
2810
|
-
function setHSVA(hsv) {
|
|
2811
|
-
setHSV(hsv);
|
|
2812
|
-
a = hsv.a;
|
|
2813
|
-
}
|
|
2814
|
-
function getHexRGB(s, v) {
|
|
2815
|
-
return getColorFormatter('#rgb').format(getRGBA(s, v));
|
|
2816
|
-
}
|
|
2817
|
-
function getHexRGBA(s, v) {
|
|
2818
|
-
return getColorFormatter('#rgba').format(getRGBA(s, v));
|
|
2819
|
-
}
|
|
2820
|
-
function getCssRGBA(s, v, alpha) {
|
|
2821
|
-
if (s === void 0) { s = sat; }
|
|
2822
|
-
if (v === void 0) { v = val; }
|
|
2823
|
-
if (alpha === void 0) { alpha = a; }
|
|
2824
|
-
return getColorFormatter('rgba()').format(getRGBA(s, v, alpha));
|
|
2825
|
-
}
|
|
2826
|
-
function parseInput(value, format) {
|
|
2827
|
-
var rgba = getColorFormatter(format || 'rgb').parse(value);
|
|
2828
|
-
setHSVA(__assign(__assign({}, rgb2hsv(rgba)), { a: rgba.a }));
|
|
2829
|
-
}
|
|
2830
|
-
function formatOutput(format) {
|
|
2831
|
-
return getColorFormatter(format).format(getRGBA());
|
|
2832
|
-
}
|
|
2833
|
-
function triggerInput() {
|
|
2834
|
-
use(node.attrs.data, function (data) {
|
|
2835
|
-
var value = formatOutput(data.format);
|
|
2836
|
-
var written = setValue(data, value);
|
|
2837
|
-
call(data.onInput, data, written);
|
|
2838
|
-
});
|
|
2839
|
-
}
|
|
2840
|
-
function triggerChange() {
|
|
2841
|
-
use(node.attrs.data, function (data) {
|
|
2842
|
-
var value = formatOutput(data.format);
|
|
2843
|
-
var written = setValue(data, value);
|
|
2844
|
-
call(data.onChange, data, written);
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
function hasAlpha() {
|
|
2848
|
-
return use(node.attrs.data, function (data) {
|
|
2849
|
-
return data.format && data.format.match(/a/i);
|
|
2850
|
-
});
|
|
2851
|
-
}
|
|
2852
|
-
//
|
|
2853
|
-
// manual input
|
|
2854
|
-
//
|
|
2855
|
-
function inputR(e) {
|
|
2856
|
-
input(e, 'r');
|
|
2857
|
-
}
|
|
2858
|
-
function inputG(e) {
|
|
2859
|
-
input(e, 'g');
|
|
2860
|
-
}
|
|
2861
|
-
function inputB(e) {
|
|
2862
|
-
input(e, 'b');
|
|
2863
|
-
}
|
|
2864
|
-
function input(e, field) {
|
|
2865
|
-
var color = getRGBA();
|
|
2866
|
-
color[field] = parseInt(e.target.value, 10) / 255;
|
|
2867
|
-
setHSV(rgb2hsv(color));
|
|
2868
|
-
triggerInput();
|
|
2869
|
-
triggerChange();
|
|
2870
|
-
}
|
|
2871
|
-
function inputHex(e) {
|
|
2872
|
-
parseInput(e.target.value, hasAlpha() ? 'rgba' : 'rgb');
|
|
2873
|
-
triggerInput();
|
|
2874
|
-
triggerChange();
|
|
2875
|
-
}
|
|
2876
|
-
//
|
|
2877
|
-
// drag input
|
|
2878
|
-
//
|
|
2879
|
-
var target;
|
|
2880
|
-
var kind;
|
|
2881
|
-
function beginPickSV(e) {
|
|
2882
|
-
kind = 'sv';
|
|
2883
|
-
enableDrag(e.target);
|
|
2884
|
-
onMouseMove(e);
|
|
2885
|
-
}
|
|
2886
|
-
function beginPickH(e) {
|
|
2887
|
-
kind = 'h';
|
|
2888
|
-
enableDrag(e.target);
|
|
2889
|
-
onMouseMove(e);
|
|
2890
|
-
}
|
|
2891
|
-
function beginPickA(e) {
|
|
2892
|
-
kind = 'a';
|
|
2893
|
-
enableDrag(e.target);
|
|
2894
|
-
onMouseMove(e);
|
|
2895
|
-
}
|
|
2896
|
-
function enableDrag(el) {
|
|
2897
|
-
disableDrag();
|
|
2898
|
-
target = el;
|
|
2899
|
-
var options = { passive: false };
|
|
2900
|
-
document.addEventListener('mousemove', onMouseMove, options);
|
|
2901
|
-
document.addEventListener('mouseup', onMouseUp, options);
|
|
2902
|
-
document.addEventListener('touchmove', onMouseMove, options);
|
|
2903
|
-
document.addEventListener('touchend', onMouseUp, options);
|
|
2904
|
-
document.addEventListener('touchcancel', onMouseUp, options);
|
|
2905
|
-
}
|
|
2906
|
-
function disableDrag() {
|
|
2907
|
-
document.removeEventListener('mousemove', onMouseMove);
|
|
2908
|
-
document.removeEventListener('mouseup', onMouseUp);
|
|
2909
|
-
document.removeEventListener('touchmove', onMouseMove);
|
|
2910
|
-
document.removeEventListener('touchend', onMouseUp);
|
|
2911
|
-
document.removeEventListener('touchcancel', onMouseUp);
|
|
2912
|
-
}
|
|
2913
|
-
function onMouseMove(e) {
|
|
2914
|
-
if (!target) {
|
|
2915
|
-
return;
|
|
2916
|
-
}
|
|
2917
|
-
e.preventDefault();
|
|
2918
|
-
var rect = target.getBoundingClientRect();
|
|
2919
|
-
var tx = window.pageXOffset || document.documentElement.scrollLeft;
|
|
2920
|
-
var ty = window.pageYOffset || document.documentElement.scrollTop;
|
|
2921
|
-
var cw = target.clientWidth;
|
|
2922
|
-
var ch = target.clientHeight;
|
|
2923
|
-
var _a = getMouseXY(e), cx = _a[0], cy = _a[1];
|
|
2924
|
-
cx = clamp((cx - tx - rect.left) / cw, 0, 1);
|
|
2925
|
-
cy = clamp((cy - ty - rect.top) / ch, 0, 1);
|
|
2926
|
-
if (kind === 'sv') {
|
|
2927
|
-
sat = cx;
|
|
2928
|
-
val = 1 - cy;
|
|
2929
|
-
}
|
|
2930
|
-
if (kind === 'h') {
|
|
2931
|
-
hue = 1 - cx;
|
|
2932
|
-
}
|
|
2933
|
-
if (kind === 'a') {
|
|
2934
|
-
a = cx;
|
|
2935
|
-
}
|
|
2936
|
-
triggerInput();
|
|
2937
|
-
mithril.redraw();
|
|
2938
|
-
}
|
|
2939
|
-
function onMouseUp() {
|
|
2940
|
-
if (target != null) {
|
|
2941
|
-
target = null;
|
|
2942
|
-
disableDrag();
|
|
2943
|
-
triggerChange();
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
return {
|
|
2947
|
-
onremove: function () {
|
|
2948
|
-
disableDrag();
|
|
2949
|
-
},
|
|
2950
|
-
oninit: function () {
|
|
2951
|
-
use(node.attrs.data, function (data) {
|
|
2952
|
-
parseInput(getValue(data), data.format);
|
|
2953
|
-
});
|
|
2954
|
-
},
|
|
2955
|
-
view: function () {
|
|
2956
|
-
return use(node.attrs.data, function (data) {
|
|
2957
|
-
var rgba = getRGBA();
|
|
2958
|
-
return mithril('div', {
|
|
2959
|
-
class: twuiClass(data.type),
|
|
2960
|
-
}, mithril('.color-picker-inputs', mithril("input.input-hex[type='text']", {
|
|
2961
|
-
value: hasAlpha() ? getHexRGBA() : getHexRGB(),
|
|
2962
|
-
onchange: inputHex,
|
|
2963
|
-
}), mithril("input.input-r[type='number']", {
|
|
2964
|
-
min: 0,
|
|
2965
|
-
max: 255,
|
|
2966
|
-
step: 1,
|
|
2967
|
-
value: Math.round(rgba.r * 255),
|
|
2968
|
-
onchange: inputR,
|
|
2969
|
-
}), mithril("input.input-g[type='number']", {
|
|
2970
|
-
min: 0,
|
|
2971
|
-
max: 255,
|
|
2972
|
-
step: 1,
|
|
2973
|
-
value: Math.round(rgba.g * 255),
|
|
2974
|
-
onchange: inputG,
|
|
2975
|
-
}), mithril("input.input-b[type='number']", {
|
|
2976
|
-
min: 0,
|
|
2977
|
-
max: 255,
|
|
2978
|
-
step: 1,
|
|
2979
|
-
value: Math.round(rgba.b * 255),
|
|
2980
|
-
onchange: inputB,
|
|
2981
|
-
})), mithril('.color-picker-panel', mithril('.color-picker-sv', {
|
|
2982
|
-
tabindex: 0,
|
|
2983
|
-
onmousedown: beginPickSV,
|
|
2984
|
-
ontouchstart: beginPickSV,
|
|
2985
|
-
style: {
|
|
2986
|
-
'background-color': "" + getCssRGBA(1, 1, 1),
|
|
2987
|
-
'user-select': 'none',
|
|
2988
|
-
},
|
|
2989
|
-
}, mithril('.color-picker-sv-bg', {
|
|
2990
|
-
style: {
|
|
2991
|
-
background: 'linear-gradient(to right,rgba(255,255,255,1),rgba(255,255,255,0))',
|
|
2992
|
-
'user-select': 'none',
|
|
2993
|
-
'pointer-events': 'none',
|
|
2994
|
-
},
|
|
2995
|
-
}), mithril('.color-picker-sv-bg', {
|
|
2996
|
-
style: {
|
|
2997
|
-
background: 'linear-gradient(to top,rgba(0,0,0,1),rgba(0,0,0,0))',
|
|
2998
|
-
'user-select': 'none',
|
|
2999
|
-
'pointer-events': 'none',
|
|
3000
|
-
},
|
|
3001
|
-
}), mithril('.color-picker-sv-cursor', {
|
|
3002
|
-
style: {
|
|
3003
|
-
'user-select': 'none',
|
|
3004
|
-
'pointer-events': 'none',
|
|
3005
|
-
'background-color': "" + getCssRGBA(hue, sat, 1),
|
|
3006
|
-
left: sat * 100 + "%",
|
|
3007
|
-
top: (1 - val) * 100 + "%",
|
|
3008
|
-
},
|
|
3009
|
-
})), mithril('.color-picker-h', {
|
|
3010
|
-
tabindex: 0,
|
|
3011
|
-
onmousedown: beginPickH,
|
|
3012
|
-
ontouchstart: beginPickH,
|
|
3013
|
-
style: {
|
|
3014
|
-
'user-select': 'none',
|
|
3015
|
-
background: 'linear-gradient(to right, #f00 0, #f0f 17% , #00f 33% , #0ff 50% , #0f0 67% , #ff0 83% , #f00 100%)',
|
|
3016
|
-
},
|
|
3017
|
-
}, mithril('.color-picker-h-cursor', {
|
|
3018
|
-
style: {
|
|
3019
|
-
'user-select': 'none',
|
|
3020
|
-
'pointer-events': 'none',
|
|
3021
|
-
'background-color': "" + getCssRGBA(1, 1, 1),
|
|
3022
|
-
position: 'absolute',
|
|
3023
|
-
left: (1 - hue) * 100 + "%",
|
|
3024
|
-
},
|
|
3025
|
-
})), !hasAlpha()
|
|
3026
|
-
? null
|
|
3027
|
-
: mithril('.color-picker-a', {
|
|
3028
|
-
tabindex: 0,
|
|
3029
|
-
onmousedown: beginPickA,
|
|
3030
|
-
ontouchstart: beginPickA,
|
|
3031
|
-
style: {
|
|
3032
|
-
'user-select': 'none',
|
|
3033
|
-
},
|
|
3034
|
-
}, mithril('.color-picker-a-bg', {
|
|
3035
|
-
style: {
|
|
3036
|
-
background: "linear-gradient(to right, " + getCssRGBA(sat, val, 0) + ", " + getCssRGBA(sat, val, 1) + ")",
|
|
3037
|
-
},
|
|
3038
|
-
}), mithril('.color-picker-a-cursor', {
|
|
3039
|
-
style: {
|
|
3040
|
-
'user-select': 'none',
|
|
3041
|
-
'pointer-events': 'none',
|
|
3042
|
-
position: 'absolute',
|
|
3043
|
-
left: a * 100 + "%",
|
|
3044
|
-
},
|
|
3045
|
-
}))));
|
|
3046
|
-
});
|
|
3047
|
-
},
|
|
3048
|
-
};
|
|
3049
|
-
});
|
|
3050
|
-
|
|
3051
|
-
component('color', function () {
|
|
3052
|
-
var data;
|
|
3053
|
-
var opened = false;
|
|
3054
|
-
var value;
|
|
3055
|
-
var rgba;
|
|
3056
|
-
var rgbaFromatter = getColorFormatter('rgba()');
|
|
3057
|
-
function fetchState(node) {
|
|
3058
|
-
data = node.attrs.data;
|
|
3059
|
-
value = getValue(data);
|
|
3060
|
-
rgba = rgbaFromatter.format(getColorFormatter(data.format).parse(value));
|
|
3061
|
-
}
|
|
3062
|
-
function toggle() {
|
|
3063
|
-
opened = !opened;
|
|
3064
|
-
}
|
|
3065
|
-
function onPickerInput(p, v) {
|
|
3066
|
-
var written = setValue(data, v);
|
|
3067
|
-
call(data.onInput, data, written);
|
|
3068
|
-
}
|
|
3069
|
-
function onPickerChange(p, v) {
|
|
3070
|
-
var written = setValue(data, v);
|
|
3071
|
-
call(data.onChange, data, written);
|
|
3072
|
-
}
|
|
3073
|
-
function getText() {
|
|
3074
|
-
if (isString(value)) {
|
|
3075
|
-
return value;
|
|
3076
|
-
}
|
|
3077
|
-
if (isNumber(value)) {
|
|
3078
|
-
return '0x' + padLeft(value.toString(16), 8, '0');
|
|
3079
|
-
}
|
|
3080
|
-
if (isArray(value)) {
|
|
3081
|
-
return value
|
|
3082
|
-
.map(function (it) { return (it < 1 && it > 0 ? it.toFixed(2) : it); })
|
|
3083
|
-
.join(' , ');
|
|
3084
|
-
}
|
|
3085
|
-
if (isObject(value)) {
|
|
3086
|
-
return Object.keys(value)
|
|
3087
|
-
.map(function (k) {
|
|
3088
|
-
var it = value[k];
|
|
3089
|
-
return k + ": " + (it < 1 && it > 0 ? it.toFixed(2) : it);
|
|
3090
|
-
})
|
|
3091
|
-
.join(' ');
|
|
3092
|
-
}
|
|
3093
|
-
if (value == null) {
|
|
3094
|
-
return 'null';
|
|
3095
|
-
}
|
|
3096
|
-
return '?';
|
|
3097
|
-
}
|
|
3098
|
-
return {
|
|
3099
|
-
oninit: function (node) {
|
|
3100
|
-
fetchState(node);
|
|
3101
|
-
},
|
|
3102
|
-
onupdate: function (node) {
|
|
3103
|
-
fetchState(node);
|
|
3104
|
-
},
|
|
3105
|
-
view: function () {
|
|
3106
|
-
var _a;
|
|
3107
|
-
return mithril('div', {
|
|
3108
|
-
class: cssClass((_a = {},
|
|
3109
|
-
_a[twuiClass(data.type)] = true,
|
|
3110
|
-
_a[twuiClass(data.type + '-open')] = opened,
|
|
3111
|
-
_a)),
|
|
3112
|
-
}, mithril("button[type='button']", {
|
|
3113
|
-
style: { 'background-color': rgba },
|
|
3114
|
-
onclick: toggle,
|
|
3115
|
-
}, getText() || '?'), renderModel({
|
|
3116
|
-
type: 'color-picker',
|
|
3117
|
-
value: value,
|
|
3118
|
-
format: data.format,
|
|
3119
|
-
onInput: onPickerInput,
|
|
3120
|
-
onChange: onPickerChange,
|
|
3121
|
-
hidden: !opened,
|
|
3122
|
-
}));
|
|
3123
|
-
},
|
|
3124
|
-
};
|
|
3125
|
-
});
|
|
3126
|
-
|
|
3127
|
-
var NumberComponent = function () {
|
|
3128
|
-
var type;
|
|
3129
|
-
var min;
|
|
3130
|
-
var max;
|
|
3131
|
-
var step;
|
|
3132
|
-
var disabled;
|
|
3133
|
-
var placeholder;
|
|
3134
|
-
var isSlider;
|
|
3135
|
-
var value;
|
|
3136
|
-
var percent;
|
|
3137
|
-
var vnode;
|
|
3138
|
-
// let data: NumberModel
|
|
3139
|
-
function fetchState(node) {
|
|
3140
|
-
vnode = node;
|
|
3141
|
-
var data = node.attrs.data;
|
|
3142
|
-
type = data.type;
|
|
3143
|
-
isSlider = data.type === 'slider';
|
|
3144
|
-
min = isSlider && data.min == null ? 0 : data.min;
|
|
3145
|
-
max = isSlider && data.max == null ? 1 : data.max;
|
|
3146
|
-
step = data.step;
|
|
3147
|
-
value = getValue(data);
|
|
3148
|
-
disabled = data.disabled;
|
|
3149
|
-
percent = isSlider ? ((value - min) / (max - min)) * 100 : 0;
|
|
3150
|
-
}
|
|
3151
|
-
function setModelValue(e, v) {
|
|
3152
|
-
v = value = clamp(isNaN(v) ? null : v, min, max);
|
|
3153
|
-
var data = vnode.attrs.data;
|
|
3154
|
-
var written = setValue(data, v);
|
|
3155
|
-
call(e === 'input' ? data.onInput : data.onChange, data, written);
|
|
3156
|
-
mithril.redraw();
|
|
3157
|
-
}
|
|
3158
|
-
function onInput(e) {
|
|
3159
|
-
var el = e.target;
|
|
3160
|
-
setModelValue('input', parseFloat(el.value));
|
|
3161
|
-
}
|
|
3162
|
-
function onChange(e) {
|
|
3163
|
-
var el = e.target;
|
|
3164
|
-
setModelValue('change', parseFloat(el.value));
|
|
3165
|
-
}
|
|
3166
|
-
function limit(v) {
|
|
3167
|
-
v = clamp(v, min, max);
|
|
3168
|
-
if (step != null) {
|
|
3169
|
-
v = Math.round(v / step) * step;
|
|
3170
|
-
}
|
|
3171
|
-
return parseFloat(v.toFixed(5));
|
|
3172
|
-
}
|
|
3173
|
-
var drag = dragUtil({
|
|
3174
|
-
onStart: function (e) {
|
|
3175
|
-
drag.onMove(e);
|
|
3176
|
-
},
|
|
3177
|
-
onMove: function (e) {
|
|
3178
|
-
e.preventDefault();
|
|
3179
|
-
var s = getTouchPosition(drag.target, e).normalizedX;
|
|
3180
|
-
setModelValue('input', limit(min + s * (max - min)));
|
|
3181
|
-
},
|
|
3182
|
-
onEnd: function () {
|
|
3183
|
-
setModelValue('change', value);
|
|
3184
|
-
drag.deactivate();
|
|
3185
|
-
},
|
|
3186
|
-
});
|
|
3187
|
-
function onDragStart(e) {
|
|
3188
|
-
if (!disabled) {
|
|
3189
|
-
drag.activate(e);
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
function onKeydown(e) {
|
|
3193
|
-
var code = e.key || e.keyCode;
|
|
3194
|
-
var dir = code === 'ArrowLeft' ? -1 : code === 'ArrowRight' ? 1 : 0;
|
|
3195
|
-
var add = (step || 1) * dir;
|
|
3196
|
-
if (add) {
|
|
3197
|
-
setModelValue('change', limit((value || 0) + add));
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
function onWheel(e) {
|
|
3201
|
-
e.preventDefault();
|
|
3202
|
-
var dir = (e.ctrlKey ? 0.5 : 1) * clamp(e.deltaY, -1, 1);
|
|
3203
|
-
var add = (step || 0.2) * dir;
|
|
3204
|
-
if (add) {
|
|
3205
|
-
setModelValue('change', limit((value || 0) - add));
|
|
3206
|
-
}
|
|
3207
|
-
}
|
|
3208
|
-
function onFocus() {
|
|
3209
|
-
}
|
|
3210
|
-
function onBlur() {
|
|
3211
|
-
}
|
|
3212
|
-
function slider() {
|
|
3213
|
-
return mithril('.twui-progress', __assign({ style: 'user-select: none;', class: cssClass({
|
|
3214
|
-
disabled: !!disabled,
|
|
3215
|
-
}) }, (disabled
|
|
3216
|
-
? {}
|
|
3217
|
-
: {
|
|
3218
|
-
tabindex: 0,
|
|
3219
|
-
onmousedown: onDragStart,
|
|
3220
|
-
ontouchstart: onDragStart,
|
|
3221
|
-
onkeydown: onKeydown,
|
|
3222
|
-
onwheel: onWheel,
|
|
3223
|
-
})), mithril('.twui-progress-bar', {
|
|
3224
|
-
style: {
|
|
3225
|
-
width: percent + "%",
|
|
3226
|
-
'pointer-events': 'none',
|
|
3227
|
-
'user-select': 'none',
|
|
3228
|
-
},
|
|
3229
|
-
}));
|
|
3230
|
-
}
|
|
3231
|
-
return {
|
|
3232
|
-
onremove: function () {
|
|
3233
|
-
drag.deactivate();
|
|
3234
|
-
},
|
|
3235
|
-
oninit: function (node) {
|
|
3236
|
-
fetchState(node);
|
|
3237
|
-
},
|
|
3238
|
-
onupdate: function (node) {
|
|
3239
|
-
fetchState(node);
|
|
3240
|
-
},
|
|
3241
|
-
view: function () {
|
|
3242
|
-
return mithril('div', {
|
|
3243
|
-
class: twuiClass(type),
|
|
3244
|
-
}, isSlider ? slider() : null, mithril("input[type='number']", {
|
|
3245
|
-
min: min,
|
|
3246
|
-
max: max,
|
|
3247
|
-
step: step,
|
|
3248
|
-
value: value,
|
|
3249
|
-
oninput: onInput,
|
|
3250
|
-
onchange: onChange,
|
|
3251
|
-
onwheel: onWheel,
|
|
3252
|
-
onfocus: onFocus,
|
|
3253
|
-
onblur: onBlur,
|
|
3254
|
-
placeholder: placeholder,
|
|
3255
|
-
disabled: disabled,
|
|
3256
|
-
}));
|
|
3257
|
-
},
|
|
3258
|
-
};
|
|
3259
|
-
};
|
|
3260
|
-
component('number', NumberComponent);
|
|
3261
|
-
component('slider', NumberComponent);
|
|
3262
|
-
|
|
3263
|
-
var TYPE$6 = 'point';
|
|
3264
|
-
var DEFAULT_RANGE = [0, 1];
|
|
3265
|
-
var DEFAULT_KEYS = ['x', 'y'];
|
|
3266
|
-
component(TYPE$6, function (vnode) {
|
|
3267
|
-
var kx;
|
|
3268
|
-
var ky;
|
|
3269
|
-
var xRange = DEFAULT_RANGE;
|
|
3270
|
-
var yRange = DEFAULT_RANGE;
|
|
3271
|
-
var vx = 0;
|
|
3272
|
-
var vy = 0;
|
|
3273
|
-
var x = 0;
|
|
3274
|
-
var y = 0;
|
|
3275
|
-
var rx;
|
|
3276
|
-
var ry;
|
|
3277
|
-
var snap;
|
|
3278
|
-
function fetchValue(node) {
|
|
3279
|
-
var _a;
|
|
3280
|
-
var _b;
|
|
3281
|
-
var data = node.attrs.data;
|
|
3282
|
-
var keys = data.keys || DEFAULT_KEYS;
|
|
3283
|
-
kx = keys[0];
|
|
3284
|
-
ky = keys[1];
|
|
3285
|
-
var value = (_b = getValue(data)) !== null && _b !== void 0 ? _b : (_a = {},
|
|
3286
|
-
_a[kx] = vx,
|
|
3287
|
-
_a[ky] = vy,
|
|
3288
|
-
_a);
|
|
3289
|
-
snap = data.snap;
|
|
3290
|
-
vx = value[kx] || 0;
|
|
3291
|
-
vy = value[ky] || 0;
|
|
3292
|
-
xRange = data.xRange || xRange;
|
|
3293
|
-
yRange = data.yRange || yRange;
|
|
3294
|
-
x = (vx - xRange[0]) / (xRange[1] - xRange[0]);
|
|
3295
|
-
y = (vy - yRange[0]) / (yRange[1] - yRange[0]);
|
|
3296
|
-
var reset = data.reset;
|
|
3297
|
-
if (reset) {
|
|
3298
|
-
rx = (reset[0] - xRange[0]) / (xRange[1] - xRange[0]);
|
|
3299
|
-
ry = (reset[1] - yRange[0]) / (yRange[1] - yRange[0]);
|
|
3300
|
-
}
|
|
3301
|
-
}
|
|
3302
|
-
function updateValue() {
|
|
3303
|
-
vx = xRange[0] + (xRange[1] - xRange[0]) * x;
|
|
3304
|
-
vy = yRange[0] + (yRange[1] - yRange[0]) * y;
|
|
3305
|
-
if (snap > 0) {
|
|
3306
|
-
vx = Math.floor(vx / snap) * snap;
|
|
3307
|
-
vy = Math.floor(vy / snap) * snap;
|
|
3308
|
-
x = (vx - xRange[0]) / (xRange[1] - xRange[0]);
|
|
3309
|
-
y = (vy - yRange[0]) / (yRange[1] - yRange[0]);
|
|
3310
|
-
}
|
|
3311
|
-
}
|
|
3312
|
-
function onChange(type) {
|
|
3313
|
-
var _a;
|
|
3314
|
-
var _b;
|
|
3315
|
-
updateValue();
|
|
3316
|
-
var data = vnode.attrs.data;
|
|
3317
|
-
var value = (_b = getValue(data)) !== null && _b !== void 0 ? _b : (_a = {},
|
|
3318
|
-
_a[kx] = vx,
|
|
3319
|
-
_a[ky] = vy,
|
|
3320
|
-
_a);
|
|
3321
|
-
value[kx] = vx;
|
|
3322
|
-
value[ky] = vy;
|
|
3323
|
-
call(type === 'input' ? data.onInput : data.onChange, data, value);
|
|
3324
|
-
}
|
|
3325
|
-
function onMouseDown(e) {
|
|
3326
|
-
drag.activate(e);
|
|
3327
|
-
}
|
|
3328
|
-
var drag = dragUtil({
|
|
3329
|
-
onMove: function (e) {
|
|
3330
|
-
e.preventDefault();
|
|
3331
|
-
var target = drag.target;
|
|
3332
|
-
var rect = target.getBoundingClientRect();
|
|
3333
|
-
var tx = window.pageXOffset || document.documentElement.scrollLeft;
|
|
3334
|
-
var ty = window.pageYOffset || document.documentElement.scrollTop;
|
|
3335
|
-
var cw = target.clientWidth;
|
|
3336
|
-
var ch = target.clientHeight;
|
|
3337
|
-
var _a = getMouseXY(e), cx = _a[0], cy = _a[1];
|
|
3338
|
-
x = clamp((cx - tx - rect.left) / cw, 0, 1);
|
|
3339
|
-
y = clamp((cy - ty - rect.top) / ch, 0, 1);
|
|
3340
|
-
onChange('input');
|
|
3341
|
-
mithril.redraw();
|
|
3342
|
-
},
|
|
3343
|
-
onEnd: function () {
|
|
3344
|
-
drag.deactivate();
|
|
3345
|
-
if (rx != null && ry != null) {
|
|
3346
|
-
x = rx;
|
|
3347
|
-
y = ry;
|
|
3348
|
-
onChange('input');
|
|
3349
|
-
}
|
|
3350
|
-
onChange('change');
|
|
3351
|
-
mithril.redraw();
|
|
3352
|
-
},
|
|
3353
|
-
});
|
|
3354
|
-
return {
|
|
3355
|
-
onremove: drag.deactivate,
|
|
3356
|
-
oninit: fetchValue,
|
|
3357
|
-
onupdate: fetchValue,
|
|
3358
|
-
view: function () {
|
|
3359
|
-
return mithril('div', {
|
|
3360
|
-
class: twuiClass(TYPE$6),
|
|
3361
|
-
tabindex: 0,
|
|
3362
|
-
onmousedown: onMouseDown,
|
|
3363
|
-
ontouchstart: onMouseDown,
|
|
3364
|
-
}, mithril('.point-x-axis', {
|
|
3365
|
-
style: {
|
|
3366
|
-
'pointer-events': 'none',
|
|
3367
|
-
position: 'absolute',
|
|
3368
|
-
left: 0,
|
|
3369
|
-
right: 0,
|
|
3370
|
-
top: y * 100 + "%",
|
|
3371
|
-
height: "1px",
|
|
3372
|
-
},
|
|
3373
|
-
}), mithril('.point-y-axis', {
|
|
3374
|
-
style: {
|
|
3375
|
-
'pointer-events': 'none',
|
|
3376
|
-
position: 'absolute',
|
|
3377
|
-
left: x * 100 + "%",
|
|
3378
|
-
top: 0,
|
|
3379
|
-
bottom: 0,
|
|
3380
|
-
width: "1px",
|
|
3381
|
-
},
|
|
3382
|
-
}), mithril('.point-cursor', {
|
|
3383
|
-
style: {
|
|
3384
|
-
'pointer-events': 'none',
|
|
3385
|
-
left: x * 100 + "%",
|
|
3386
|
-
top: y * 100 + "%",
|
|
3387
|
-
position: 'absolute',
|
|
3388
|
-
width: '11px',
|
|
3389
|
-
height: '11px',
|
|
3390
|
-
'margin-top': '-5px',
|
|
3391
|
-
'margin-left': '-5px',
|
|
3392
|
-
border: '1px solid white',
|
|
3393
|
-
'border-radius': '5px',
|
|
3394
|
-
'box-shadow': '0px 0px 2px 1px rgba(0, 0, 0, 0.75)',
|
|
3395
|
-
},
|
|
3396
|
-
}));
|
|
3397
|
-
},
|
|
3398
|
-
};
|
|
3399
|
-
});
|
|
3400
|
-
|
|
3401
|
-
var TYPE$5 = 'position';
|
|
3402
|
-
var defaultKeys = ['x', 'y', 'z'];
|
|
3403
|
-
component(TYPE$5, function (node) {
|
|
3404
|
-
function onChange(type, field, v) {
|
|
3405
|
-
var data = node.attrs.data;
|
|
3406
|
-
var value = getValue(data) || {};
|
|
3407
|
-
value[field] = isNaN(v) ? null : v;
|
|
3408
|
-
var written = setValue(data, value);
|
|
3409
|
-
call(type === 'input' ? data.onInput : data.onChange, data, written, field);
|
|
3410
|
-
}
|
|
3411
|
-
return {
|
|
3412
|
-
view: viewFn(function (data) {
|
|
3413
|
-
var keys = data.keys || defaultKeys;
|
|
3414
|
-
var value = getValue(data);
|
|
3415
|
-
return mithril('div', {
|
|
3416
|
-
class: twuiClass(TYPE$5),
|
|
3417
|
-
}, keys.map(function (field) {
|
|
3418
|
-
return renderModel({
|
|
3419
|
-
type: 'number',
|
|
3420
|
-
min: data.min,
|
|
3421
|
-
max: data.max,
|
|
3422
|
-
step: data.step,
|
|
3423
|
-
value: value === null || value === void 0 ? void 0 : value[field],
|
|
3424
|
-
disabled: data.disabled,
|
|
3425
|
-
onInput: function (_, v) { return onChange('input', field, v); },
|
|
3426
|
-
onChange: function (_, v) { return onChange('change', field, v); },
|
|
3427
|
-
placeholder: field,
|
|
3428
|
-
});
|
|
3429
|
-
}));
|
|
3430
|
-
}),
|
|
3431
|
-
};
|
|
3432
|
-
});
|
|
3433
|
-
|
|
3434
|
-
var emptyArray = [];
|
|
3435
|
-
function optionsFromFlatArray(arr) {
|
|
3436
|
-
var res = [];
|
|
3437
|
-
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
|
|
3438
|
-
var it_1 = arr_1[_i];
|
|
3439
|
-
if (isString(it_1) || isNumber(it_1)) {
|
|
3440
|
-
res.push({ value: it_1, label: String(it_1) });
|
|
3441
|
-
continue;
|
|
3442
|
-
}
|
|
3443
|
-
if ('value' in it_1) {
|
|
3444
|
-
res.push(it_1);
|
|
3445
|
-
continue;
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
return res;
|
|
3449
|
-
}
|
|
3450
|
-
function optionsFromArray(arr) {
|
|
3451
|
-
var res = [];
|
|
3452
|
-
for (var _i = 0, arr_2 = arr; _i < arr_2.length; _i++) {
|
|
3453
|
-
var it_2 = arr_2[_i];
|
|
3454
|
-
if (isString(it_2) || isNumber(it_2) || it_2 == null) {
|
|
3455
|
-
res.push({ value: it_2, label: String(it_2) });
|
|
3456
|
-
}
|
|
3457
|
-
else if ('value' in it_2) {
|
|
3458
|
-
res.push(it_2);
|
|
3459
|
-
}
|
|
3460
|
-
else if ('options' in it_2) {
|
|
3461
|
-
res.push({
|
|
3462
|
-
label: it_2.label,
|
|
3463
|
-
disabled: it_2.disabled,
|
|
3464
|
-
options: Array.isArray(it_2.options)
|
|
3465
|
-
? optionsFromFlatArray(it_2.options)
|
|
3466
|
-
: optionsFromObject(it_2.options),
|
|
3467
|
-
});
|
|
3468
|
-
}
|
|
3469
|
-
}
|
|
3470
|
-
return res;
|
|
3471
|
-
}
|
|
3472
|
-
function optionsFromObject(obj) {
|
|
3473
|
-
return Object.keys(obj)
|
|
3474
|
-
.sort()
|
|
3475
|
-
.map(function (key) { return ({ value: obj[key], label: key }); });
|
|
3476
|
-
}
|
|
3477
|
-
function getOptions(node) {
|
|
3478
|
-
var options = node.attrs.data.options;
|
|
3479
|
-
if (!options) {
|
|
3480
|
-
return emptyArray;
|
|
3481
|
-
}
|
|
3482
|
-
if (Array.isArray(options)) {
|
|
3483
|
-
return optionsFromArray(options);
|
|
3484
|
-
}
|
|
3485
|
-
return optionsFromObject(options);
|
|
3486
|
-
}
|
|
3487
|
-
component('select', function (node) {
|
|
3488
|
-
var options;
|
|
3489
|
-
function getSelectedIndex() {
|
|
3490
|
-
var data = node.attrs.data;
|
|
3491
|
-
var value = getValue(data);
|
|
3492
|
-
var i = 0;
|
|
3493
|
-
for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
|
|
3494
|
-
var o0 = options_1[_i];
|
|
3495
|
-
if ('options' in o0) {
|
|
3496
|
-
for (var _a = 0, _b = o0.options; _a < _b.length; _a++) {
|
|
3497
|
-
var o1 = _b[_a];
|
|
3498
|
-
if (o1.value === value) {
|
|
3499
|
-
return i;
|
|
3500
|
-
}
|
|
3501
|
-
i++;
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
else {
|
|
3505
|
-
if (o0.value === value) {
|
|
3506
|
-
return i;
|
|
3507
|
-
}
|
|
3508
|
-
i++;
|
|
3509
|
-
}
|
|
3510
|
-
}
|
|
3511
|
-
}
|
|
3512
|
-
function getSelectionAt(index) {
|
|
3513
|
-
var i = 0;
|
|
3514
|
-
for (var _i = 0, options_2 = options; _i < options_2.length; _i++) {
|
|
3515
|
-
var o0 = options_2[_i];
|
|
3516
|
-
if ('options' in o0) {
|
|
3517
|
-
for (var _a = 0, _b = o0.options; _a < _b.length; _a++) {
|
|
3518
|
-
var o1 = _b[_a];
|
|
3519
|
-
if (i === index) {
|
|
3520
|
-
return o1.value;
|
|
3521
|
-
}
|
|
3522
|
-
i += 1;
|
|
3523
|
-
}
|
|
3524
|
-
}
|
|
3525
|
-
else {
|
|
3526
|
-
if (i === index) {
|
|
3527
|
-
return o0.value;
|
|
3528
|
-
}
|
|
3529
|
-
i += 1;
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
return null;
|
|
3533
|
-
}
|
|
3534
|
-
function onChange(e) {
|
|
3535
|
-
var el = e.target;
|
|
3536
|
-
var data = node.attrs.data;
|
|
3537
|
-
var value = getSelectionAt(el.selectedIndex);
|
|
3538
|
-
var written = setValue(data, value);
|
|
3539
|
-
call(data.onChange, data, written);
|
|
3540
|
-
}
|
|
3541
|
-
return {
|
|
3542
|
-
view: viewFn(function (data) {
|
|
3543
|
-
options = getOptions(node);
|
|
3544
|
-
return mithril('select', {
|
|
3545
|
-
class: twuiClass(data.type),
|
|
3546
|
-
selectedIndex: getSelectedIndex(),
|
|
3547
|
-
onchange: onChange,
|
|
3548
|
-
disabled: data.disabled,
|
|
3549
|
-
}, options.map(function (it) {
|
|
3550
|
-
if ('options' in it) {
|
|
3551
|
-
return mithril('optgroup', {
|
|
3552
|
-
disabled: !!it.disabled,
|
|
3553
|
-
label: it.label || '',
|
|
3554
|
-
}, it.options.map(option));
|
|
3555
|
-
}
|
|
3556
|
-
return option(it);
|
|
3557
|
-
}));
|
|
3558
|
-
}),
|
|
3559
|
-
};
|
|
3560
|
-
});
|
|
3561
|
-
function option(it) {
|
|
3562
|
-
return mithril('option', {
|
|
3563
|
-
value: it.value,
|
|
3564
|
-
label: it.label,
|
|
3565
|
-
disabled: !!it.disabled,
|
|
3566
|
-
}, it.label || '');
|
|
3567
|
-
}
|
|
3568
|
-
|
|
3569
|
-
var TYPE$4 = 'spherical';
|
|
3570
|
-
var KEYS = ['phi', 'theta'];
|
|
3571
|
-
var SphericalComponent = function (vnode) {
|
|
3572
|
-
var phi = 0; // azimuth [0, 2PI]
|
|
3573
|
-
var theta = 0; // inclination [0, PI]
|
|
3574
|
-
var backface = false;
|
|
3575
|
-
var v2Phi = [0, 0];
|
|
3576
|
-
var v2Theta = [0, 0];
|
|
3577
|
-
var draggedKnob;
|
|
3578
|
-
function toDeg(value) {
|
|
3579
|
-
return value * (180 / Math.PI);
|
|
3580
|
-
}
|
|
3581
|
-
function toRad(value) {
|
|
3582
|
-
return value * (Math.PI / 180);
|
|
3583
|
-
}
|
|
3584
|
-
function toScreen(value) {
|
|
3585
|
-
return clamp((value / 2 + 0.5) * 100, 0, 100);
|
|
3586
|
-
}
|
|
3587
|
-
function read(node) {
|
|
3588
|
-
var data = node.attrs.data;
|
|
3589
|
-
var value = getValue(data) || {
|
|
3590
|
-
phi: data.degree ? toDeg(phi) : phi,
|
|
3591
|
-
theta: data.degree ? toDeg(theta) : theta,
|
|
3592
|
-
};
|
|
3593
|
-
var _a = data.keys || KEYS, kPhi = _a[0], kTheta = _a[1];
|
|
3594
|
-
return { data: data, value: value, kPhi: kPhi, kTheta: kTheta };
|
|
3595
|
-
}
|
|
3596
|
-
function fetchValue(node) {
|
|
3597
|
-
var _a = read(node), data = _a.data, value = _a.value, kPhi = _a.kPhi, kTheta = _a.kTheta;
|
|
3598
|
-
phi = value[kPhi] || 0;
|
|
3599
|
-
theta = value[kTheta] || 0;
|
|
3600
|
-
if (data.degree) {
|
|
3601
|
-
phi = toRad(phi);
|
|
3602
|
-
theta = toRad(theta);
|
|
3603
|
-
}
|
|
3604
|
-
var p2 = Math.PI / 2;
|
|
3605
|
-
while (theta < 0) {
|
|
3606
|
-
theta += p2;
|
|
3607
|
-
}
|
|
3608
|
-
while (theta > p2) {
|
|
3609
|
-
theta -= p2;
|
|
3610
|
-
}
|
|
3611
|
-
backface = theta > Math.PI / 2;
|
|
3612
|
-
updatePositions();
|
|
3613
|
-
}
|
|
3614
|
-
function onChange(type) {
|
|
3615
|
-
updatePositions();
|
|
3616
|
-
var _a = read(vnode), data = _a.data, value = _a.value, kPhi = _a.kPhi, kTheta = _a.kTheta;
|
|
3617
|
-
value[kPhi] = data.degree ? toDeg(phi) : phi;
|
|
3618
|
-
value[kTheta] = data.degree ? toDeg(theta) : theta;
|
|
3619
|
-
var written = setValue(data, value);
|
|
3620
|
-
call(type === 'input' ? data.onInput : data.onChange, data, written);
|
|
3621
|
-
}
|
|
3622
|
-
function updatePositions() {
|
|
3623
|
-
v2Phi[0] = Math.cos(phi);
|
|
3624
|
-
v2Phi[1] = Math.sin(phi);
|
|
3625
|
-
v2Theta[0] = Math.sin(theta) * Math.cos(phi);
|
|
3626
|
-
v2Theta[1] = Math.sin(theta) * Math.sin(phi);
|
|
3627
|
-
}
|
|
3628
|
-
function onStartPhi(e) {
|
|
3629
|
-
draggedKnob = 'phi';
|
|
3630
|
-
drag.activate(e);
|
|
3631
|
-
}
|
|
3632
|
-
function onStartTheta(e) {
|
|
3633
|
-
draggedKnob = 'theta';
|
|
3634
|
-
drag.activate(e);
|
|
3635
|
-
}
|
|
3636
|
-
var drag = dragUtil({
|
|
3637
|
-
onStart: function (e) {
|
|
3638
|
-
drag.onMove(e);
|
|
3639
|
-
},
|
|
3640
|
-
onMove: function (e) {
|
|
3641
|
-
e.preventDefault();
|
|
3642
|
-
var position = getTouchPosition(drag.target.parentElement, e);
|
|
3643
|
-
var px = position.normalizedX - 0.5;
|
|
3644
|
-
var py = position.normalizedY - 0.5;
|
|
3645
|
-
if (draggedKnob === 'phi') {
|
|
3646
|
-
// [-PI;PI]
|
|
3647
|
-
phi = Math.atan2(px, py);
|
|
3648
|
-
// convert to range [0;2PI]
|
|
3649
|
-
phi += phi < 0 ? 2 * Math.PI : 0;
|
|
3650
|
-
}
|
|
3651
|
-
else if (draggedKnob === 'theta') {
|
|
3652
|
-
// closest point on segment
|
|
3653
|
-
// p0: [0, 0], p1: vPhi
|
|
3654
|
-
var ab = v2Phi;
|
|
3655
|
-
var ac = [py, px];
|
|
3656
|
-
var t = (ab[0] * ac[0] + ab[1] * ac[1]) / Math.sqrt(ab[0] * ab[0] + ab[1] * ab[1]);
|
|
3657
|
-
theta = Math.PI * clamp(t, 0, 0.5);
|
|
3658
|
-
if (backface) {
|
|
3659
|
-
theta = Math.PI - theta;
|
|
3660
|
-
}
|
|
3661
|
-
}
|
|
3662
|
-
onChange('input');
|
|
3663
|
-
mithril.redraw();
|
|
3664
|
-
},
|
|
3665
|
-
onEnd: function (e) {
|
|
3666
|
-
drag.deactivate();
|
|
3667
|
-
draggedKnob = null;
|
|
3668
|
-
onChange('change');
|
|
3669
|
-
mithril.redraw();
|
|
3670
|
-
},
|
|
3671
|
-
});
|
|
3672
|
-
function onPhiInput(model, value) {
|
|
3673
|
-
phi = toRad(value);
|
|
3674
|
-
onChange('input');
|
|
3675
|
-
}
|
|
3676
|
-
function onPhiChange(model, value) {
|
|
3677
|
-
phi = toRad(value);
|
|
3678
|
-
onChange('change');
|
|
3679
|
-
}
|
|
3680
|
-
function onThetaInput(model, value) {
|
|
3681
|
-
theta = toRad(value);
|
|
3682
|
-
onChange('input');
|
|
3683
|
-
}
|
|
3684
|
-
function onThetaChange(model, value) {
|
|
3685
|
-
theta = toRad(value);
|
|
3686
|
-
onChange('change');
|
|
3687
|
-
}
|
|
3688
|
-
function onBackfaceChange(model, value) {
|
|
3689
|
-
backface = value;
|
|
3690
|
-
theta = Math.PI - theta;
|
|
3691
|
-
onChange('change');
|
|
3692
|
-
setTimeout(function () { return mithril.redraw(); });
|
|
3693
|
-
}
|
|
3694
|
-
return {
|
|
3695
|
-
onremove: function () {
|
|
3696
|
-
drag.deactivate();
|
|
3697
|
-
},
|
|
3698
|
-
oninit: function (node) {
|
|
3699
|
-
fetchValue(node);
|
|
3700
|
-
},
|
|
3701
|
-
onupdate: function (node) {
|
|
3702
|
-
fetchValue(node);
|
|
3703
|
-
},
|
|
3704
|
-
view: function () {
|
|
3705
|
-
return mithril('div', {
|
|
3706
|
-
class: twuiClass(TYPE$4),
|
|
3707
|
-
style: {
|
|
3708
|
-
'--spherical-phi': toDeg(-phi) + 90 + "deg",
|
|
3709
|
-
},
|
|
3710
|
-
}, mithril('div.left-container', mithril('div.pane', {
|
|
3711
|
-
style: {
|
|
3712
|
-
position: 'relative',
|
|
3713
|
-
width: '100%',
|
|
3714
|
-
'padding-top': '100%',
|
|
3715
|
-
},
|
|
3716
|
-
}, mithril('div.phi-pane', {
|
|
3717
|
-
class: cssClass({
|
|
3718
|
-
'is-dragging': draggedKnob === 'phi',
|
|
3719
|
-
}),
|
|
3720
|
-
style: {
|
|
3721
|
-
position: 'absolute',
|
|
3722
|
-
top: '0.5rem',
|
|
3723
|
-
left: '0.5rem',
|
|
3724
|
-
width: 'calc(100% - 1rem)',
|
|
3725
|
-
height: 'calc(100% - 1rem)',
|
|
3726
|
-
},
|
|
3727
|
-
}, mithril('div.phi-knob', {
|
|
3728
|
-
onmousedown: onStartPhi,
|
|
3729
|
-
ontouchstart: onStartPhi,
|
|
3730
|
-
style: {
|
|
3731
|
-
position: 'absolute',
|
|
3732
|
-
width: '15px',
|
|
3733
|
-
height: '15px',
|
|
3734
|
-
top: "calc(" + toScreen(v2Phi[0]) + "% - 7px)",
|
|
3735
|
-
left: "calc(" + toScreen(v2Phi[1]) + "% - 7px)",
|
|
3736
|
-
},
|
|
3737
|
-
})), mithril('div.theta-pane', {
|
|
3738
|
-
class: cssClass({
|
|
3739
|
-
'is-dragging': draggedKnob === 'theta',
|
|
3740
|
-
}),
|
|
3741
|
-
style: {
|
|
3742
|
-
position: 'absolute',
|
|
3743
|
-
top: '1.5rem',
|
|
3744
|
-
left: '1.5rem',
|
|
3745
|
-
width: 'calc(100% - 3rem)',
|
|
3746
|
-
height: 'calc(100% - 3rem)',
|
|
3747
|
-
},
|
|
3748
|
-
}, mithril('div.theta-knob', {
|
|
3749
|
-
onmousedown: onStartTheta,
|
|
3750
|
-
ontouchstart: onStartTheta,
|
|
3751
|
-
style: {
|
|
3752
|
-
position: 'absolute',
|
|
3753
|
-
width: '15px',
|
|
3754
|
-
height: '15px',
|
|
3755
|
-
top: "calc(" + toScreen(v2Theta[0]) + "% - 7px)",
|
|
3756
|
-
left: "calc(" + toScreen(v2Theta[1]) + "% - 7px)",
|
|
3757
|
-
},
|
|
3758
|
-
})))), mithril('div.right-container', mithril('label', mithril.trust('φ')), renderModel({
|
|
3759
|
-
type: 'number',
|
|
3760
|
-
min: 0,
|
|
3761
|
-
max: 360,
|
|
3762
|
-
step: 0.1,
|
|
3763
|
-
value: toDeg(phi),
|
|
3764
|
-
onInput: onPhiInput,
|
|
3765
|
-
onChange: onPhiChange,
|
|
3766
|
-
}), mithril('label', mithril.trust('θ')), renderModel({
|
|
3767
|
-
type: 'number',
|
|
3768
|
-
min: 0,
|
|
3769
|
-
max: 180,
|
|
3770
|
-
step: 0.1,
|
|
3771
|
-
value: toDeg(theta),
|
|
3772
|
-
onInput: onThetaInput,
|
|
3773
|
-
onChange: onThetaChange,
|
|
3774
|
-
}), renderModel({
|
|
3775
|
-
type: 'checkbox',
|
|
3776
|
-
value: backface,
|
|
3777
|
-
text: 'Backface',
|
|
3778
|
-
onChange: onBackfaceChange,
|
|
3779
|
-
})));
|
|
3780
|
-
},
|
|
3781
|
-
};
|
|
3782
|
-
};
|
|
3783
|
-
component(TYPE$4, SphericalComponent);
|
|
3784
|
-
function sphericalCodec(_a) {
|
|
3785
|
-
var _b = _a === void 0 ? {} : _a, axes = _b.axes, length = _b.length, result = _b.result;
|
|
3786
|
-
axes = axes || { x: 'right', y: 'up', z: 'back' };
|
|
3787
|
-
var keys = Object.keys(axes);
|
|
3788
|
-
var radius = function () {
|
|
3789
|
-
return (typeof length === 'function' ? length() : length) || 1;
|
|
3790
|
-
};
|
|
3791
|
-
return {
|
|
3792
|
-
decode: function (value) {
|
|
3793
|
-
var x = 0;
|
|
3794
|
-
var y = 0;
|
|
3795
|
-
var z = 0;
|
|
3796
|
-
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
3797
|
-
var key = keys_1[_i];
|
|
3798
|
-
switch (axes[key]) {
|
|
3799
|
-
case 'right':
|
|
3800
|
-
y = value[key];
|
|
3801
|
-
break;
|
|
3802
|
-
case 'left':
|
|
3803
|
-
y = -value[key];
|
|
3804
|
-
break;
|
|
3805
|
-
case 'back':
|
|
3806
|
-
x = value[key];
|
|
3807
|
-
break;
|
|
3808
|
-
case 'front':
|
|
3809
|
-
x = -value[key];
|
|
3810
|
-
break;
|
|
3811
|
-
case 'up':
|
|
3812
|
-
z = value[key];
|
|
3813
|
-
break;
|
|
3814
|
-
case 'down':
|
|
3815
|
-
z = -value[key];
|
|
3816
|
-
break;
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
var r = radius();
|
|
3820
|
-
x /= r;
|
|
3821
|
-
y /= r;
|
|
3822
|
-
z /= r;
|
|
3823
|
-
return {
|
|
3824
|
-
phi: Math.atan2(y, x) || 0,
|
|
3825
|
-
theta: Math.atan(Math.sqrt(x * x + y * y) / z) || 0,
|
|
3826
|
-
};
|
|
3827
|
-
},
|
|
3828
|
-
encode: function (_a) {
|
|
3829
|
-
var phi = _a.phi, theta = _a.theta;
|
|
3830
|
-
var r = radius();
|
|
3831
|
-
var x = r * Math.sin(theta) * Math.cos(phi);
|
|
3832
|
-
var y = r * Math.sin(theta) * Math.sin(phi);
|
|
3833
|
-
var z = r * Math.cos(theta);
|
|
3834
|
-
var value = (result === null || result === void 0 ? void 0 : result()) || {};
|
|
3835
|
-
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
|
3836
|
-
var key = keys_2[_i];
|
|
3837
|
-
switch (axes[key]) {
|
|
3838
|
-
case 'right':
|
|
3839
|
-
value[key] = y;
|
|
3840
|
-
break;
|
|
3841
|
-
case 'left':
|
|
3842
|
-
value[key] = -y;
|
|
3843
|
-
break;
|
|
3844
|
-
case 'back':
|
|
3845
|
-
value[key] = x;
|
|
3846
|
-
break;
|
|
3847
|
-
case 'front':
|
|
3848
|
-
value[key] = -x;
|
|
3849
|
-
break;
|
|
3850
|
-
case 'up':
|
|
3851
|
-
value[key] = z;
|
|
3852
|
-
break;
|
|
3853
|
-
case 'down':
|
|
3854
|
-
value[key] = -z;
|
|
3855
|
-
break;
|
|
3856
|
-
}
|
|
3857
|
-
}
|
|
3858
|
-
return value;
|
|
3859
|
-
},
|
|
3860
|
-
};
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
component('text', function (node) {
|
|
3864
|
-
function onChange(e) {
|
|
3865
|
-
var el = e.target;
|
|
3866
|
-
var data = node.attrs.data;
|
|
3867
|
-
var written = setValue(data, el.value);
|
|
3868
|
-
call(e.type === 'input' ? data.onInput : data.onChange, data, written);
|
|
3869
|
-
}
|
|
3870
|
-
return {
|
|
3871
|
-
view: viewFn(function (data) {
|
|
3872
|
-
return mithril("input[type='text']", {
|
|
3873
|
-
class: twuiClass(data.type),
|
|
3874
|
-
value: getValue(data),
|
|
3875
|
-
oninput: onChange,
|
|
3876
|
-
onchange: onChange,
|
|
3877
|
-
placeholder: data.placeholder,
|
|
3878
|
-
disabled: data.disabled,
|
|
3879
|
-
});
|
|
3880
|
-
}),
|
|
3881
|
-
};
|
|
3882
|
-
});
|
|
3883
|
-
|
|
3884
|
-
var TYPE$3 = 'accordion';
|
|
3885
|
-
var EMPTY = [];
|
|
3886
|
-
component(TYPE$3, function () {
|
|
3887
|
-
return {
|
|
3888
|
-
view: viewFn(function (data) {
|
|
3889
|
-
var children = data.children || EMPTY;
|
|
3890
|
-
data.expand = detectExpanded(data.expand, children);
|
|
3891
|
-
return mithril.fragment({}, children.map(function (group, i) {
|
|
3892
|
-
group.type = 'group';
|
|
3893
|
-
group.collapsible = true;
|
|
3894
|
-
group.collapsed = i !== data.expand;
|
|
3895
|
-
return renderModel(group);
|
|
3896
|
-
}));
|
|
3897
|
-
}),
|
|
3898
|
-
};
|
|
3899
|
-
});
|
|
3900
|
-
function detectExpanded(index, list) {
|
|
3901
|
-
var result = null;
|
|
3902
|
-
for (var i = 0; i < list.length; i++) {
|
|
3903
|
-
if (!list[i].collapsed) {
|
|
3904
|
-
if (i !== index) {
|
|
3905
|
-
return i;
|
|
3906
|
-
}
|
|
3907
|
-
if (result == null) {
|
|
3908
|
-
result = i;
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
}
|
|
3912
|
-
return result;
|
|
3913
|
-
}
|
|
3914
|
-
|
|
3915
|
-
var TYPE$2 = 'container';
|
|
3916
|
-
component(TYPE$2, function () {
|
|
3917
|
-
return {
|
|
3918
|
-
view: viewFn(function (data) {
|
|
3919
|
-
var _a;
|
|
3920
|
-
var _b;
|
|
3921
|
-
return mithril('div', {
|
|
3922
|
-
class: cssClass((_a = {},
|
|
3923
|
-
_a[twuiClass(TYPE$2)] = true,
|
|
3924
|
-
_a[twuiClass(TYPE$2, 'horizontal')] = data.horizontal,
|
|
3925
|
-
_a)),
|
|
3926
|
-
style: data.style,
|
|
3927
|
-
}, mithril.fragment({}, (_b = data.children) === null || _b === void 0 ? void 0 : _b.map(renderModel)));
|
|
3928
|
-
}),
|
|
3929
|
-
};
|
|
3930
|
-
});
|
|
3931
|
-
|
|
3932
|
-
var TYPE$1 = 'group';
|
|
3933
|
-
component(TYPE$1, function (node) {
|
|
3934
|
-
function onClick(e) {
|
|
3935
|
-
use(node.attrs.data, function (data) {
|
|
3936
|
-
data.collapsed = !data.collapsed;
|
|
3937
|
-
call(data.onToggle, data);
|
|
3938
|
-
if (data.collapsed) {
|
|
3939
|
-
call(data.onCollapse, data);
|
|
3940
|
-
}
|
|
3941
|
-
else {
|
|
3942
|
-
call(data.onExpand, data);
|
|
3943
|
-
}
|
|
3944
|
-
});
|
|
3945
|
-
}
|
|
3946
|
-
function title(data) {
|
|
3947
|
-
if (!data.title && !data.collapsible) {
|
|
3948
|
-
return null;
|
|
3949
|
-
}
|
|
3950
|
-
return mithril('div', {
|
|
3951
|
-
class: twuiClass(TYPE$1, 'title'),
|
|
3952
|
-
onclick: data.collapsible ? onClick : null,
|
|
3953
|
-
}, data.title);
|
|
3954
|
-
}
|
|
3955
|
-
function children(data) {
|
|
3956
|
-
var _a;
|
|
3957
|
-
if (data.collapsed || !data.children) {
|
|
3958
|
-
return [];
|
|
3959
|
-
}
|
|
3960
|
-
return (_a = data.children) === null || _a === void 0 ? void 0 : _a.map(function (it) {
|
|
3961
|
-
if (isString(it.label)) {
|
|
3962
|
-
return mithril('div', { class: twuiClass(TYPE$1, 'control') }, mithril('label', it.label), mithril('section', renderModel(it)));
|
|
3963
|
-
}
|
|
3964
|
-
return renderModel(it);
|
|
3965
|
-
});
|
|
3966
|
-
}
|
|
3967
|
-
return {
|
|
3968
|
-
view: viewFn(function (data) {
|
|
3969
|
-
var _a;
|
|
3970
|
-
return mithril('div', {
|
|
3971
|
-
class: cssClass((_a = {},
|
|
3972
|
-
_a[twuiClass(TYPE$1)] = true,
|
|
3973
|
-
_a[twuiClass(TYPE$1, 'collapsible')] = data.collapsible,
|
|
3974
|
-
_a[twuiClass(TYPE$1, 'collapsed')] = data.collapsed,
|
|
3975
|
-
_a)),
|
|
3976
|
-
style: data.style,
|
|
3977
|
-
}, mithril.fragment({}, [title(data)]), mithril.fragment({}, [children(data)]));
|
|
3978
|
-
}),
|
|
3979
|
-
};
|
|
3980
|
-
});
|
|
3981
|
-
|
|
3982
|
-
component('tabs', function () {
|
|
3983
|
-
return {
|
|
3984
|
-
view: viewFn(function (data) {
|
|
3985
|
-
var tabs = data.children || [];
|
|
3986
|
-
var active = clamp(data.active || 0, 0, tabs.length - 1);
|
|
3987
|
-
var tab = tabs[active];
|
|
3988
|
-
return mithril('div', {
|
|
3989
|
-
class: twuiClass(data.type),
|
|
3990
|
-
}, mithril('div', {
|
|
3991
|
-
key: data.type + "-list",
|
|
3992
|
-
class: twuiClass(data.type + "-list"),
|
|
3993
|
-
}, tabs.map(function (it, index) {
|
|
3994
|
-
return mithril("button[type='button']", {
|
|
3995
|
-
key: data.type + "-" + index,
|
|
3996
|
-
onclick: function () { return (data.active = index); },
|
|
3997
|
-
class: active === index ? 'is-active' : '',
|
|
3998
|
-
}, it.label || it.title);
|
|
3999
|
-
})), mithril.fragment({ key: "panel-" + data.active }, [
|
|
4000
|
-
renderModel({
|
|
4001
|
-
type: 'group',
|
|
4002
|
-
children: tab.children,
|
|
4003
|
-
style: tab.style,
|
|
4004
|
-
}),
|
|
4005
|
-
]));
|
|
4006
|
-
}),
|
|
4007
|
-
};
|
|
4008
|
-
});
|
|
4009
|
-
|
|
4010
|
-
var type = 'button';
|
|
4011
|
-
component(type, function (node) {
|
|
4012
|
-
return {
|
|
4013
|
-
view: viewFn(function (data) {
|
|
4014
|
-
return mithril(type, {
|
|
4015
|
-
type: type,
|
|
4016
|
-
class: twuiClass(type),
|
|
4017
|
-
onclick: function () { return call(data.onClick, data); },
|
|
4018
|
-
disabled: data.disabled,
|
|
4019
|
-
}, data.text);
|
|
4020
|
-
}),
|
|
4021
|
-
};
|
|
4022
|
-
});
|
|
4023
|
-
|
|
4024
|
-
var CONTENT = 'content';
|
|
4025
|
-
component(CONTENT, function () {
|
|
4026
|
-
return {
|
|
4027
|
-
view: viewFn(function (data) { return mithril.fragment({}, [data.content]); }),
|
|
4028
|
-
};
|
|
4029
|
-
});
|
|
4030
|
-
|
|
4031
|
-
var TYPE = 'image';
|
|
4032
|
-
component('image', function (node) {
|
|
4033
|
-
var onClick = function () {
|
|
4034
|
-
use(node.attrs.data, function (data) { return call(data.onClick, data); });
|
|
4035
|
-
};
|
|
4036
|
-
function aspect(spec) {
|
|
4037
|
-
if (!spec) {
|
|
4038
|
-
return null;
|
|
4039
|
-
}
|
|
4040
|
-
var _a = (spec || '1x1').split('x').map(Number), x = _a[0], y = _a[1];
|
|
4041
|
-
var padding = ((y / x) || 1) * 100;
|
|
4042
|
-
return padding + "%";
|
|
4043
|
-
}
|
|
4044
|
-
function width(data) {
|
|
4045
|
-
if (isNumber(data.width)) {
|
|
4046
|
-
return data.width + "px";
|
|
4047
|
-
}
|
|
4048
|
-
if (isString(data.width)) {
|
|
4049
|
-
return data.width;
|
|
4050
|
-
}
|
|
4051
|
-
}
|
|
4052
|
-
return {
|
|
4053
|
-
view: viewFn(function (data) {
|
|
4054
|
-
return (Array.isArray(data.src) ? data.src : [data.src]).map(function (src) {
|
|
4055
|
-
var _a;
|
|
4056
|
-
return mithril('picture', {
|
|
4057
|
-
class: cssClass((_a = {},
|
|
4058
|
-
_a[twuiClass(TYPE)] = true,
|
|
4059
|
-
_a[twuiClass(TYPE, 'aspect')] = !!data.aspect,
|
|
4060
|
-
_a)),
|
|
4061
|
-
style: {
|
|
4062
|
-
'--twui-aspect': aspect(data.aspect),
|
|
4063
|
-
'--twui-fit': data.fit || 'fit',
|
|
4064
|
-
width: width(data),
|
|
4065
|
-
},
|
|
4066
|
-
}, mithril('img', {
|
|
4067
|
-
src: src,
|
|
4068
|
-
onclick: onClick,
|
|
4069
|
-
}));
|
|
4070
|
-
});
|
|
4071
|
-
}),
|
|
4072
|
-
};
|
|
4073
|
-
});
|
|
4074
|
-
|
|
4075
|
-
// tslint:disable: unified-signatures
|
|
4076
|
-
function assign(partial, overrides) {
|
|
4077
|
-
Object.keys(overrides).forEach(function (key) {
|
|
4078
|
-
partial[key] = overrides[key];
|
|
4079
|
-
});
|
|
4080
|
-
return partial;
|
|
4081
|
-
}
|
|
4082
|
-
function buildGroup() {
|
|
4083
|
-
var label = null;
|
|
4084
|
-
var opts = {};
|
|
4085
|
-
var cb;
|
|
4086
|
-
// tslint:disable-next-line: prefer-for-of
|
|
4087
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
4088
|
-
var arg = arguments[i];
|
|
4089
|
-
if (isString(arg)) {
|
|
4090
|
-
label = arg;
|
|
4091
|
-
}
|
|
4092
|
-
else if (isObject(arg)) {
|
|
4093
|
-
opts = arg;
|
|
4094
|
-
}
|
|
4095
|
-
else if (isFunction(arg)) {
|
|
4096
|
-
cb = arg;
|
|
4097
|
-
}
|
|
4098
|
-
}
|
|
4099
|
-
if (label) {
|
|
4100
|
-
opts.label = label;
|
|
4101
|
-
}
|
|
4102
|
-
if (cb) {
|
|
4103
|
-
var controls = this.controls;
|
|
4104
|
-
this.controls = [];
|
|
4105
|
-
cb(this);
|
|
4106
|
-
opts.children = this.controls;
|
|
4107
|
-
this.controls = controls;
|
|
4108
|
-
}
|
|
4109
|
-
return opts;
|
|
4110
|
-
}
|
|
4111
|
-
function buildControl() {
|
|
4112
|
-
var opts = {};
|
|
4113
|
-
if (arguments.length > 1) {
|
|
4114
|
-
opts = arguments[2] || opts;
|
|
4115
|
-
opts.target = arguments[0];
|
|
4116
|
-
opts.property = arguments[1];
|
|
4117
|
-
if (opts.label === undefined) {
|
|
4118
|
-
opts.label = String(opts.property || '');
|
|
4119
|
-
}
|
|
4120
|
-
}
|
|
4121
|
-
if (arguments.length === 1) {
|
|
4122
|
-
opts = arguments[0] || opts;
|
|
4123
|
-
}
|
|
4124
|
-
return opts;
|
|
4125
|
-
}
|
|
4126
|
-
/**
|
|
4127
|
-
*
|
|
4128
|
-
* @public
|
|
4129
|
-
*/
|
|
4130
|
-
var Builder = /** @class */ (function () {
|
|
4131
|
-
function Builder() {
|
|
4132
|
-
/**
|
|
4133
|
-
* Collection of created controls
|
|
4134
|
-
*/
|
|
4135
|
-
this.controls = [];
|
|
4136
|
-
}
|
|
4137
|
-
Builder.prototype.group = function () {
|
|
4138
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4139
|
-
return this.add(assign(opts, {
|
|
4140
|
-
type: 'group',
|
|
4141
|
-
children: opts.children,
|
|
4142
|
-
label: null,
|
|
4143
|
-
title: opts.label,
|
|
4144
|
-
}));
|
|
4145
|
-
};
|
|
4146
|
-
Builder.prototype.collapsible = function () {
|
|
4147
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4148
|
-
return this.add(assign(opts, {
|
|
4149
|
-
type: 'group',
|
|
4150
|
-
children: opts.children,
|
|
4151
|
-
collapsible: true,
|
|
4152
|
-
label: null,
|
|
4153
|
-
title: opts.label,
|
|
4154
|
-
}));
|
|
4155
|
-
};
|
|
4156
|
-
Builder.prototype.container = function () {
|
|
4157
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4158
|
-
return this.add(assign(opts, {
|
|
4159
|
-
type: 'container',
|
|
4160
|
-
children: opts.children,
|
|
4161
|
-
}));
|
|
4162
|
-
};
|
|
4163
|
-
Builder.prototype.tabs = function () {
|
|
4164
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4165
|
-
return this.add(assign(opts, {
|
|
4166
|
-
type: 'tabs',
|
|
4167
|
-
active: opts.active || 0,
|
|
4168
|
-
children: opts.children,
|
|
4169
|
-
}));
|
|
4170
|
-
};
|
|
4171
|
-
Builder.prototype.accordion = function () {
|
|
4172
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4173
|
-
return this.add(assign(opts, {
|
|
4174
|
-
type: 'accordion',
|
|
4175
|
-
children: opts.children,
|
|
4176
|
-
}));
|
|
4177
|
-
};
|
|
4178
|
-
Builder.prototype.checkbox = function () {
|
|
4179
|
-
var opts = buildControl.apply(this, arguments);
|
|
4180
|
-
return this.add(assign(opts, { type: 'checkbox' }));
|
|
4181
|
-
};
|
|
4182
|
-
Builder.prototype.text = function () {
|
|
4183
|
-
var opts = buildControl.apply(this, arguments);
|
|
4184
|
-
return this.add(assign(opts, { type: 'text' }));
|
|
4185
|
-
};
|
|
4186
|
-
Builder.prototype.number = function () {
|
|
4187
|
-
var opts = buildControl.apply(this, arguments);
|
|
4188
|
-
return this.add(assign(opts, { type: 'number' }));
|
|
4189
|
-
};
|
|
4190
|
-
Builder.prototype.slider = function () {
|
|
4191
|
-
var opts = buildControl.apply(this, arguments);
|
|
4192
|
-
return this.add(assign(opts, { type: 'slider' }));
|
|
4193
|
-
};
|
|
4194
|
-
Builder.prototype.position = function () {
|
|
4195
|
-
var opts = buildControl.apply(this, arguments);
|
|
4196
|
-
return this.add(assign(opts, { type: 'position' }));
|
|
4197
|
-
};
|
|
4198
|
-
Builder.prototype.select = function () {
|
|
4199
|
-
var opts = buildControl.apply(this, arguments);
|
|
4200
|
-
return this.add(assign(opts, { type: 'select' }));
|
|
4201
|
-
};
|
|
4202
|
-
Builder.prototype.color = function () {
|
|
4203
|
-
var opts = buildControl.apply(this, arguments);
|
|
4204
|
-
return this.add(assign(opts, { type: 'color' }));
|
|
4205
|
-
};
|
|
4206
|
-
Builder.prototype.colorPicker = function () {
|
|
4207
|
-
var opts = buildControl.apply(this, arguments);
|
|
4208
|
-
return this.add(assign(opts, { type: 'color-picker' }));
|
|
4209
|
-
};
|
|
4210
|
-
Builder.prototype.point = function () {
|
|
4211
|
-
var opts = buildControl.apply(this, arguments);
|
|
4212
|
-
return this.add(assign(opts, { type: 'point' }));
|
|
4213
|
-
};
|
|
4214
|
-
Builder.prototype.spherical = function () {
|
|
4215
|
-
var opts = buildControl.apply(this, arguments);
|
|
4216
|
-
return this.add(assign(opts, { type: 'spherical' }));
|
|
4217
|
-
};
|
|
4218
|
-
Builder.prototype.angle = function () {
|
|
4219
|
-
var opts = buildControl.apply(this, arguments);
|
|
4220
|
-
return this.add(assign(opts, { type: 'angle' }));
|
|
4221
|
-
};
|
|
4222
|
-
/**
|
|
4223
|
-
* Adds a button control
|
|
4224
|
-
*
|
|
4225
|
-
* @param text - The button text
|
|
4226
|
-
* @param opts - Additional options for the control
|
|
4227
|
-
*/
|
|
4228
|
-
Builder.prototype.button = function (text, opts) {
|
|
4229
|
-
if (opts === void 0) { opts = {}; }
|
|
4230
|
-
return this.add(assign(opts, {
|
|
4231
|
-
type: 'button',
|
|
4232
|
-
text: text,
|
|
4233
|
-
}));
|
|
4234
|
-
};
|
|
4235
|
-
Builder.prototype.image = function () {
|
|
4236
|
-
var opts = buildGroup.apply(this, arguments);
|
|
4237
|
-
return this.add(assign(opts, {
|
|
4238
|
-
type: 'image',
|
|
4239
|
-
}));
|
|
4240
|
-
};
|
|
4241
|
-
/**
|
|
4242
|
-
* Adds a description text
|
|
4243
|
-
*
|
|
4244
|
-
* @param label - The control label
|
|
4245
|
-
* @param text - The text message
|
|
4246
|
-
* @param opts - Additional options for the control
|
|
4247
|
-
*/
|
|
4248
|
-
Builder.prototype.content = function (label, content, opts) {
|
|
4249
|
-
if (opts === void 0) { opts = {}; }
|
|
4250
|
-
return this.add(assign(opts, {
|
|
4251
|
-
type: 'content',
|
|
4252
|
-
label: label,
|
|
4253
|
-
content: content,
|
|
4254
|
-
}));
|
|
4255
|
-
};
|
|
4256
|
-
/**
|
|
4257
|
-
* Adds a control
|
|
4258
|
-
*
|
|
4259
|
-
* @param def - The control definition
|
|
4260
|
-
*/
|
|
4261
|
-
Builder.prototype.add = function (def) {
|
|
4262
|
-
var _this = this;
|
|
4263
|
-
this.controls.push(assign(def, {
|
|
4264
|
-
remove: function () {
|
|
4265
|
-
var i = _this.controls.indexOf(def);
|
|
4266
|
-
if (i >= 0) {
|
|
4267
|
-
_this.controls.splice(i, 1);
|
|
4268
|
-
}
|
|
4269
|
-
},
|
|
4270
|
-
}));
|
|
4271
|
-
return def;
|
|
4272
|
-
};
|
|
4273
|
-
return Builder;
|
|
4274
|
-
}());
|
|
4275
|
-
|
|
4276
|
-
/**
|
|
4277
|
-
* Mithril's hyperscript function.
|
|
4278
|
-
*
|
|
4279
|
-
* @public
|
|
4280
|
-
* @remarks
|
|
4281
|
-
* Useful to create custom components
|
|
4282
|
-
*/
|
|
4283
|
-
var h = mithril;
|
|
4284
|
-
/**
|
|
4285
|
-
* Runs the function through a builder system and returns the created controls
|
|
4286
|
-
*
|
|
4287
|
-
* @param fn - The builder function
|
|
4288
|
-
* @returns
|
|
4289
|
-
*/
|
|
4290
|
-
function build(fn) {
|
|
4291
|
-
var builder = new Builder();
|
|
4292
|
-
fn(builder);
|
|
4293
|
-
return builder.controls;
|
|
4294
|
-
}
|
|
4295
|
-
/**
|
|
4296
|
-
* Mounts a ui to the given element
|
|
4297
|
-
*
|
|
4298
|
-
* @public
|
|
4299
|
-
* @param el - The ui host element
|
|
4300
|
-
* @param data - The ui definition object
|
|
4301
|
-
*/
|
|
4302
|
-
function mount(el, data) {
|
|
4303
|
-
el = typeof el === 'string' ? document.querySelector(el) : el;
|
|
4304
|
-
el.classList.add('twui-root');
|
|
4305
|
-
if (!data) {
|
|
4306
|
-
mithril.mount(el, null);
|
|
4307
|
-
}
|
|
4308
|
-
else if (Array.isArray(data)) {
|
|
4309
|
-
mithril.mount(el, {
|
|
4310
|
-
view: function () {
|
|
4311
|
-
return renderModel({
|
|
4312
|
-
type: 'group',
|
|
4313
|
-
children: data,
|
|
4314
|
-
});
|
|
4315
|
-
},
|
|
4316
|
-
});
|
|
4317
|
-
}
|
|
4318
|
-
else if (isFunction(data)) {
|
|
4319
|
-
var builder_1 = new Builder();
|
|
4320
|
-
data(builder_1);
|
|
4321
|
-
mithril.mount(el, {
|
|
4322
|
-
view: function () {
|
|
4323
|
-
return renderModel({
|
|
4324
|
-
type: 'group',
|
|
4325
|
-
children: builder_1.controls,
|
|
4326
|
-
});
|
|
4327
|
-
},
|
|
4328
|
-
});
|
|
4329
|
-
}
|
|
4330
|
-
else {
|
|
4331
|
-
mithril.mount(el, {
|
|
4332
|
-
view: function () { return renderModel(data); },
|
|
4333
|
-
});
|
|
4334
|
-
}
|
|
4335
|
-
}
|
|
4336
|
-
/**
|
|
4337
|
-
* Unmounts the ui from given host element
|
|
4338
|
-
*
|
|
4339
|
-
* @public
|
|
4340
|
-
* @param el - The ui host element
|
|
4341
|
-
*/
|
|
4342
|
-
function unmount(el) {
|
|
4343
|
-
el = typeof el === 'string' ? document.querySelector(el) : el;
|
|
4344
|
-
mithril.mount(el, null);
|
|
4345
|
-
}
|
|
4346
|
-
/**
|
|
4347
|
-
* Redraws the ui
|
|
4348
|
-
*
|
|
4349
|
-
* @public
|
|
4350
|
-
* @remarks
|
|
4351
|
-
* When changing the ui description object qui callbacks (e.g. `onInput` or `onChange`)
|
|
4352
|
-
* the ui will redraw automatically.
|
|
4353
|
-
*
|
|
4354
|
-
* However if the ui description object is changed from outside the qui callback
|
|
4355
|
-
* then this method must be called in order to update the visual state.
|
|
4356
|
-
*/
|
|
4357
|
-
function redraw() {
|
|
4358
|
-
mithril.redraw();
|
|
4359
|
-
}
|
|
4360
|
-
|
|
4361
|
-
/**
|
|
4362
|
-
* Tweak UI is a lightweight js library for building input controls with data binding
|
|
4363
|
-
*
|
|
4364
|
-
* @remarks
|
|
4365
|
-
* The library provides a set of common ui components built with mithriljs. The main objective
|
|
4366
|
-
* is to allow a developer to rapidly scaffold input interfaces for manipulating javascript objects
|
|
4367
|
-
* at runtime.
|
|
4368
|
-
*
|
|
4369
|
-
* Similar projects are:
|
|
4370
|
-
* {@link https://github.com/dataarts/dat.gui | dat.GUI}
|
|
4371
|
-
* {@link https://github.com/automat/controlkit.js | controlkit}
|
|
4372
|
-
* {@link https://github.com/colejd/guify | guify}
|
|
4373
|
-
*
|
|
4374
|
-
* @packageDocumentation
|
|
4375
|
-
*/
|
|
4376
|
-
/**
|
|
4377
|
-
* The version string
|
|
4378
|
-
*
|
|
4379
|
-
* @public
|
|
4380
|
-
*/
|
|
4381
|
-
var VERSION = "0.4.2";
|
|
4382
|
-
|
|
4383
|
-
exports.Builder = Builder;
|
|
4384
|
-
exports.VERSION = VERSION;
|
|
4385
|
-
exports.angleCodec = angleCodec;
|
|
4386
|
-
exports.build = build;
|
|
4387
|
-
exports.component = component;
|
|
4388
|
-
exports.getColorFormatter = getColorFormatter;
|
|
4389
|
-
exports.getComponent = getComponent;
|
|
4390
|
-
exports.getValue = getValue;
|
|
4391
|
-
exports.h = h;
|
|
4392
|
-
exports.hsv2rgb = hsv2rgb;
|
|
4393
|
-
exports.mount = mount;
|
|
4394
|
-
exports.redraw = redraw;
|
|
4395
|
-
exports.renderModel = renderModel;
|
|
4396
|
-
exports.rgb2hsv = rgb2hsv;
|
|
4397
|
-
exports.setValue = setValue;
|
|
4398
|
-
exports.sphericalCodec = sphericalCodec;
|
|
4399
|
-
exports.unmount = unmount;
|
|
4400
|
-
|
|
4401
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4402
|
-
|
|
4403
|
-
})));
|
|
1
|
+
(function(X,Re){typeof exports=="object"&&typeof module<"u"?Re(exports):typeof define=="function"&&define.amd?define(["exports"],Re):(X=typeof globalThis<"u"?globalThis:X||self,Re(X.TweakUI={}))})(this,function(X){"use strict";function Re(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ze,Rt;function me(){if(Rt)return ze;Rt=1;function t(e,n,u,a,c,f){return{tag:e,key:n,attrs:u,children:a,text:c,dom:f,is:void 0,domSize:void 0,state:void 0,events:void 0,instance:void 0}}return t.normalize=function(e){return Array.isArray(e)?t("[",void 0,void 0,t.normalizeChildren(e),void 0,void 0):e==null||typeof e=="boolean"?null:typeof e=="object"?e:t("#",void 0,void 0,String(e),void 0,void 0)},t.normalizeChildren=function(e){var n=[];if(e.length){for(var u=e[0]!=null&&e[0].key!=null,a=1;a<e.length;a++)if((e[a]!=null&&e[a].key!=null)!==u)throw new TypeError(u&&(e[a]!=null||typeof e[a]=="boolean")?"In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole.":"In fragments, vnodes must either all have keys or none have keys.");for(var a=0;a<e.length;a++)n[a]=t.normalize(e[a])}return n},ze=t,ze}var Le,Et;function Mt(){if(Et)return Le;Et=1;var t=me();return Le=function(){var e=arguments[this],n=this+1,u;if(e==null?e={}:(typeof e!="object"||e.tag!=null||Array.isArray(e))&&(e={},n=this),arguments.length===n+1)u=arguments[n],Array.isArray(u)||(u=[u]);else for(u=[];n<arguments.length;)u.push(arguments[n++]);return t("",e.key,e,u)},Le}var Ne,Pt;function je(){return Pt||(Pt=1,Ne={}.hasOwnProperty),Ne}var Se,Tt;function qt(){if(Tt)return Se;Tt=1;var t=me(),e=Mt(),n=je(),u=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,a=Object.create(null);function c(g){for(var h in g)if(n.call(g,h))return!1;return!0}function f(g){for(var h,d="div",v=[],q={};h=u.exec(g);){var $=h[1],y=h[2];if($===""&&y!=="")d=y;else if($==="#")q.id=y;else if($===".")v.push(y);else if(h[3][0]==="["){var M=h[6];M&&(M=M.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),h[4]==="class"?v.push(M):q[h[4]]=M===""?M:M||!0}}return v.length>0&&(q.className=v.join(" ")),c(q)&&(q=null),a[g]={tag:d,attrs:q}}function s(g,h){var d=h.attrs,v=n.call(d,"class"),q=v?d.class:d.className;return h.tag=g.tag,g.attrs!=null?(d=Object.assign({},g.attrs,d),(q!=null||g.attrs.className!=null)&&(d.className=q!=null?g.attrs.className!=null?String(g.attrs.className)+" "+String(q):q:g.attrs.className!=null?g.attrs.className:null)):q!=null&&(d.className=q),v&&(d.class=null),g.tag==="input"&&n.call(d,"type")&&(d=Object.assign({type:d.type},d)),h.is=d.is,h.attrs=d,h}function l(g){if(g==null||typeof g!="string"&&typeof g!="function"&&typeof g.view!="function")throw Error("The selector must be either a string or a component.");var h=e.apply(1,arguments);return typeof g=="string"&&(h.children=t.normalizeChildren(h.children),g!=="[")?s(a[g]||f(g),h):(h.tag=g,h)}return Se=l,Se}var Fe,$t;function wn(){if($t)return Fe;$t=1;var t=me();return Fe=function(e){return e==null&&(e=""),t("<",void 0,void 0,e,void 0,void 0)},Fe}var De,Ot;function vn(){if(Ot)return De;Ot=1;var t=me(),e=Mt();return De=function(){var n=e.apply(0,arguments);return n.tag="[",n.children=t.normalizeChildren(n.children),n},De}var He,At;function xn(){if(At)return He;At=1;var t=qt();return t.trust=wn(),t.fragment=vn(),He=t,He}var Ve,It;function zt(){if(It)return Ve;It=1;var t=new WeakMap;function*e(n){var u=n.dom,a=n.domSize,c=t.get(u);if(u!=null)do{var f=u.nextSibling;t.get(u)===c&&(yield u,a--),u=f}while(a)}return Ve={delayedRemoval:t,domFor:e},Ve}var _e,Lt;function Cn(){if(Lt)return _e;Lt=1;var t=me(),e=zt(),n=e.delayedRemoval,u=e.domFor;return _e=function(){var a={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},c,f;function s(i){return i.ownerDocument}function l(i){return i.attrs&&i.attrs.xmlns||a[i.tag]}function g(i,r){if(i.state!==r)throw new Error("'vnode.state' must not be modified.")}function h(i){var r=i.state;try{return this.apply(r,arguments)}finally{g(i,r)}}function d(i){try{return s(i).activeElement}catch{return null}}function v(i,r,o,p,m,k,L){for(var F=o;F<p;F++){var T=r[F];T!=null&&q(i,T,m,L,k)}}function q(i,r,o,p,m){var k=r.tag;if(typeof k=="string")switch(r.state={},r.attrs!=null&&dt(r.attrs,r,o),k){case"#":$(i,r,m);break;case"<":M(i,r,p,m);break;case"[":O(i,r,o,p,m);break;default:z(i,r,o,p,m)}else ee(i,r,o,p,m)}function $(i,r,o){r.dom=s(i).createTextNode(r.children),E(i,r.dom,o)}var y={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};function M(i,r,o,p){var m=r.children.match(/^\s*?<(\w+)/im)||[],k=s(i).createElement(y[m[1]]||"div");o==="http://www.w3.org/2000/svg"?(k.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+r.children+"</svg>",k=k.firstChild):k.innerHTML=r.children,r.dom=k.firstChild,r.domSize=k.childNodes.length;for(var L=s(i).createDocumentFragment(),F;F=k.firstChild;)L.appendChild(F);E(i,L,p)}function O(i,r,o,p,m){var k=s(i).createDocumentFragment();if(r.children!=null){var L=r.children;v(k,L,0,L.length,o,null,p)}r.dom=k.firstChild,r.domSize=k.childNodes.length,E(i,k,m)}function z(i,r,o,p,m){var k=r.tag,L=r.attrs,F=r.is;p=l(r)||p;var T=p?F?s(i).createElementNS(p,k,{is:F}):s(i).createElementNS(p,k):F?s(i).createElement(k,{is:F}):s(i).createElement(k);if(r.dom=T,L!=null&&ar(r,L,p),E(i,T,m),!S(r)&&r.children!=null){var D=r.children;v(T,D,0,D.length,o,null,p),r.tag==="select"&&L!=null&&ur(r,L)}}function H(i,r){var o;if(typeof i.tag.view=="function"){if(i.state=Object.create(i.tag),o=i.state.view,o.$$reentrantLock$$!=null)return;o.$$reentrantLock$$=!0}else{if(i.state=void 0,o=i.tag,o.$$reentrantLock$$!=null)return;o.$$reentrantLock$$=!0,i.state=i.tag.prototype!=null&&typeof i.tag.prototype.view=="function"?new i.tag(i):i.tag(i)}if(dt(i.state,i,r),i.attrs!=null&&dt(i.attrs,i,r),i.instance=t.normalize(h.call(i.state.view,i)),i.instance===i)throw Error("A view cannot return the vnode it received as argument");o.$$reentrantLock$$=null}function ee(i,r,o,p,m){H(r,o),r.instance!=null?(q(i,r.instance,o,p,m),r.dom=r.instance.dom,r.domSize=r.dom!=null?r.instance.domSize:0):r.domSize=0}function V(i,r,o,p,m,k){if(!(r===o||r==null&&o==null))if(r==null||r.length===0)v(i,o,0,o.length,p,m,k);else if(o==null||o.length===0)pe(i,r,0,r.length);else{var L=r[0]!=null&&r[0].key!=null,F=o[0]!=null&&o[0].key!=null,T=0,D=0;if(!L)for(;D<r.length&&r[D]==null;)D++;if(!F)for(;T<o.length&&o[T]==null;)T++;if(L!==F)pe(i,r,D,r.length),v(i,o,T,o.length,p,m,k);else if(F){for(var ie=r.length-1,J=o.length-1,Ie,ae,G,ne,Y,wt;ie>=D&&J>=T&&(ne=r[ie],Y=o[J],ne.key===Y.key);)ne!==Y&&R(i,ne,Y,p,m,k),Y.dom!=null&&(m=Y.dom),ie--,J--;for(;ie>=D&&J>=T&&(ae=r[D],G=o[T],ae.key===G.key);)D++,T++,ae!==G&&R(i,ae,G,p,_(r,D,m),k);for(;ie>=D&&J>=T&&!(T===J||ae.key!==Y.key||ne.key!==G.key);)wt=_(r,D,m),w(i,ne,wt),ne!==G&&R(i,ne,G,p,wt,k),++T<=--J&&w(i,ae,m),ae!==Y&&R(i,ae,Y,p,m,k),Y.dom!=null&&(m=Y.dom),D++,ie--,ne=r[ie],Y=o[J],ae=r[D],G=o[T];for(;ie>=D&&J>=T&&ne.key===Y.key;)ne!==Y&&R(i,ne,Y,p,m,k),Y.dom!=null&&(m=Y.dom),ie--,J--,ne=r[ie],Y=o[J];if(T>J)pe(i,r,D,ie+1);else if(D>ie)v(i,o,T,J+1,p,m,k);else{var fr=m,bn=J-T+1,Pe=new Array(bn),vt=0,K=0,xt=2147483647,Ct=0,Ie,kt;for(K=0;K<bn;K++)Pe[K]=-1;for(K=J;K>=T;K--){Ie==null&&(Ie=P(r,D,ie+1)),Y=o[K];var ke=Ie[Y.key];ke!=null&&(xt=ke<xt?ke:-1,Pe[K-T]=ke,ne=r[ke],r[ke]=null,ne!==Y&&R(i,ne,Y,p,m,k),Y.dom!=null&&(m=Y.dom),Ct++)}if(m=fr,Ct!==ie-D+1&&pe(i,r,D,ie+1),Ct===0)v(i,o,T,J+1,p,m,k);else if(xt===-1)for(kt=N(Pe),vt=kt.length-1,K=J;K>=T;K--)G=o[K],Pe[K-T]===-1?q(i,G,p,k,m):kt[vt]===K-T?vt--:w(i,G,m),G.dom!=null&&(m=o[K].dom);else for(K=J;K>=T;K--)G=o[K],Pe[K-T]===-1&&q(i,G,p,k,m),G.dom!=null&&(m=o[K].dom)}}else{var bt=r.length<o.length?r.length:o.length;for(T=T<D?T:D;T<bt;T++)ae=r[T],G=o[T],!(ae===G||ae==null&&G==null)&&(ae==null?q(i,G,p,k,_(r,T+1,m)):G==null?te(i,ae):R(i,ae,G,p,_(r,T+1,m),k));r.length>bt&&pe(i,r,T,r.length),o.length>bt&&v(i,o,T,o.length,p,m,k)}}}function R(i,r,o,p,m,k){var L=r.tag,F=o.tag;if(L===F&&r.is===o.is){if(o.state=r.state,o.events=r.events,lr(o,r))return;if(typeof L=="string")switch(o.attrs!=null&&yt(o.attrs,o,p),L){case"#":x(r,o);break;case"<":C(i,r,o,k,m);break;case"[":j(i,r,o,p,m,k);break;default:U(r,o,p,k)}else A(i,r,o,p,m,k)}else te(i,r),q(i,o,p,k,m)}function x(i,r){i.children.toString()!==r.children.toString()&&(i.dom.nodeValue=r.children),r.dom=i.dom}function C(i,r,o,p,m){r.children!==o.children?(Ce(i,r),M(i,o,p,m)):(o.dom=r.dom,o.domSize=r.domSize)}function j(i,r,o,p,m,k){V(i,r.children,o.children,p,m,k);var L=0,F=o.children;if(o.dom=null,F!=null){for(var T=0;T<F.length;T++){var D=F[T];D!=null&&D.dom!=null&&(o.dom==null&&(o.dom=D.dom),L+=D.domSize||1)}L!==1&&(o.domSize=L)}}function U(i,r,o,p){var m=r.dom=i.dom;p=l(r)||p,cr(r,i.attrs,r.attrs,p),S(r)||V(m,i.children,r.children,o,null,p)}function A(i,r,o,p,m,k){if(o.instance=t.normalize(h.call(o.state.view,o)),o.instance===o)throw Error("A view cannot return the vnode it received as argument");yt(o.state,o,p),o.attrs!=null&&yt(o.attrs,o,p),o.instance!=null?(r.instance==null?q(i,o.instance,p,k,m):R(i,r.instance,o.instance,p,m,k),o.dom=o.instance.dom,o.domSize=o.instance.domSize):r.instance!=null?(te(i,r.instance),o.dom=void 0,o.domSize=0):(o.dom=r.dom,o.domSize=r.domSize)}function P(i,r,o){for(var p=Object.create(null);r<o;r++){var m=i[r];if(m!=null){var k=m.key;k!=null&&(p[k]=r)}}return p}var I=[];function N(i){for(var r=[0],o=0,p=0,m=0,k=I.length=i.length,m=0;m<k;m++)I[m]=i[m];for(var m=0;m<k;++m)if(i[m]!==-1){var L=r[r.length-1];if(i[L]<i[m]){I[m]=L,r.push(m);continue}for(o=0,p=r.length-1;o<p;){var F=(o>>>1)+(p>>>1)+(o&p&1);i[r[F]]<i[m]?o=F+1:p=F}i[m]<i[r[o]]&&(o>0&&(I[m]=r[o-1]),r[o]=m)}for(o=r.length,p=r[o-1];o-- >0;)r[o]=p,p=I[p];return I.length=0,r}function _(i,r,o){for(;r<i.length;r++)if(i[r]!=null&&i[r].dom!=null)return i[r].dom;return o}function w(i,r,o){if(r.dom!=null){var p;if(r.domSize==null)p=r.dom;else{p=s(i).createDocumentFragment();for(var m of u(r))p.appendChild(m)}E(i,p,o)}}function E(i,r,o){o!=null?i.insertBefore(r,o):i.appendChild(r)}function S(i){if(i.attrs==null||i.attrs.contenteditable==null&&i.attrs.contentEditable==null)return!1;var r=i.children;if(r!=null&&r.length===1&&r[0].tag==="<"){var o=r[0].children;i.dom.innerHTML!==o&&(i.dom.innerHTML=o)}else if(r!=null&&r.length!==0)throw new Error("Child node of a contenteditable must be trusted.");return!0}function pe(i,r,o,p){for(var m=o;m<p;m++){var k=r[m];k!=null&&te(i,k)}}function xe(i,r,o,p){var m=r.state,k=h.call(o.onbeforeremove,r);if(k!=null){var L=f;for(var F of u(r))n.set(F,L);p.v++,Promise.resolve(k).finally(function(){g(r,m),he(i,r,p)})}}function he(i,r,o){--o.v===0&&(ht(r),Ce(i,r))}function te(i,r){var o={v:1};typeof r.tag!="string"&&typeof r.state.onbeforeremove=="function"&&xe(i,r,r.state,o),r.attrs&&typeof r.attrs.onbeforeremove=="function"&&xe(i,r,r.attrs,o),he(i,r,o)}function Ce(i,r){if(r.dom!=null)if(r.domSize==null)i.removeChild(r.dom);else for(var o of u(r))i.removeChild(o)}function ht(i){if(typeof i.tag!="string"&&typeof i.state.onremove=="function"&&h.call(i.state.onremove,i),i.attrs&&typeof i.attrs.onremove=="function"&&h.call(i.attrs.onremove,i),typeof i.tag!="string")i.instance!=null&&ht(i.instance);else{i.events!=null&&(i.events._=null);var r=i.children;if(Array.isArray(r))for(var o=0;o<r.length;o++){var p=r[o];p!=null&&ht(p)}}}function ar(i,r,o){for(var p in r)mt(i,p,null,r[p],o)}function mt(i,r,o,p,m){if(!(r==="key"||p==null||mn(r)||o===p&&!sr(i,r)&&typeof p!="object")){if(r[0]==="o"&&r[1]==="n")return yn(i,r,p);if(r.slice(0,6)==="xlink:")i.dom.setAttributeNS("http://www.w3.org/1999/xlink",r.slice(6),p);else if(r==="style")dn(i.dom,o,p);else if(gn(i,r,m)){if(r==="value"){if((i.tag==="input"||i.tag==="textarea")&&i.dom.value===""+p||i.tag==="select"&&o!==null&&i.dom.value===""+p||i.tag==="option"&&o!==null&&i.dom.value===""+p)return;if(i.tag==="input"&&i.attrs.type==="file"&&""+p!=""){console.error("`value` is read-only on file inputs!");return}}i.tag==="input"&&r==="type"?i.dom.setAttribute(r,p):i.dom[r]=p}else typeof p=="boolean"?p?i.dom.setAttribute(r,""):i.dom.removeAttribute(r):i.dom.setAttribute(r==="className"?"class":r,p)}}function or(i,r,o,p){if(!(r==="key"||o==null||mn(r)))if(r[0]==="o"&&r[1]==="n")yn(i,r,void 0);else if(r==="style")dn(i.dom,o,null);else if(gn(i,r,p)&&r!=="className"&&r!=="title"&&!(r==="value"&&(i.tag==="option"||i.tag==="select"&&i.dom.selectedIndex===-1&&i.dom===d(i.dom)))&&!(i.tag==="input"&&r==="type"))i.dom[r]=null;else{var m=r.indexOf(":");m!==-1&&(r=r.slice(m+1)),o!==!1&&i.dom.removeAttribute(r==="className"?"class":r)}}function ur(i,r){if("value"in r)if(r.value===null)i.dom.selectedIndex!==-1&&(i.dom.value=null);else{var o=""+r.value;(i.dom.value!==o||i.dom.selectedIndex===-1)&&(i.dom.value=o)}"selectedIndex"in r&&mt(i,"selectedIndex",null,r.selectedIndex,void 0)}function cr(i,r,o,p){var m;if(r!=null){r===o&&console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major");for(var k in r)(m=r[k])!=null&&(o==null||o[k]==null)&&or(i,k,m,p)}if(o!=null)for(var k in o)mt(i,k,r&&r[k],o[k],p)}function sr(i,r){return r==="value"||r==="checked"||r==="selectedIndex"||r==="selected"&&(i.dom===d(i.dom)||i.tag==="option"&&i.dom.parentNode===d(i.dom))}function mn(i){return i==="oninit"||i==="oncreate"||i==="onupdate"||i==="onremove"||i==="onbeforeremove"||i==="onbeforeupdate"}function gn(i,r,o){return o===void 0&&(i.tag.indexOf("-")>-1||i.is||r!=="href"&&r!=="list"&&r!=="form"&&r!=="width"&&r!=="height")&&r in i.dom}function dn(i,r,o){if(r!==o)if(o==null)i.style="";else if(typeof o!="object")i.style=o;else if(r==null||typeof r!="object"){i.style="";for(var p in o){var m=o[p];m!=null&&(p.includes("-")?i.style.setProperty(p,String(m)):i.style[p]=String(m))}}else{for(var p in r)r[p]!=null&&o[p]==null&&(p.includes("-")?i.style.removeProperty(p):i.style[p]="");for(var p in o){var m=o[p];m!=null&&(m=String(m))!==String(r[p])&&(p.includes("-")?i.style.setProperty(p,m):i.style[p]=m)}}}function gt(){this._=c}gt.prototype=Object.create(null),gt.prototype.handleEvent=function(i){var r=this["on"+i.type],o;typeof r=="function"?o=r.call(i.currentTarget,i):typeof r.handleEvent=="function"&&r.handleEvent(i);var p=this;p._!=null&&(i.redraw!==!1&&(0,p._)(),o!=null&&typeof o.then=="function"&&Promise.resolve(o).then(function(){p._!=null&&i.redraw!==!1&&(0,p._)()})),o===!1&&(i.preventDefault(),i.stopPropagation())};function yn(i,r,o){if(i.events!=null){if(i.events._=c,i.events[r]===o)return;o!=null&&(typeof o=="function"||typeof o=="object")?(i.events[r]==null&&i.dom.addEventListener(r.slice(2),i.events,!1),i.events[r]=o):(i.events[r]!=null&&i.dom.removeEventListener(r.slice(2),i.events,!1),i.events[r]=void 0)}else o!=null&&(typeof o=="function"||typeof o=="object")&&(i.events=new gt,i.dom.addEventListener(r.slice(2),i.events,!1),i.events[r]=o)}function dt(i,r,o){typeof i.oninit=="function"&&h.call(i.oninit,r),typeof i.oncreate=="function"&&o.push(h.bind(i.oncreate,r))}function yt(i,r,o){typeof i.onupdate=="function"&&o.push(h.bind(i.onupdate,r))}function lr(i,r){do{if(i.attrs!=null&&typeof i.attrs.onbeforeupdate=="function"){var o=h.call(i.attrs.onbeforeupdate,i,r);if(o!==void 0&&!o)break}if(typeof i.tag!="string"&&typeof i.state.onbeforeupdate=="function"){var o=h.call(i.state.onbeforeupdate,i,r);if(o!==void 0&&!o)break}return!1}while(!1);return i.dom=r.dom,i.domSize=r.domSize,i.instance=r.instance,i.attrs=r.attrs,i.children=r.children,i.text=r.text,!0}var Me;return function(i,r,o){if(!i)throw new TypeError("DOM element being rendered to does not exist.");if(Me!=null&&i.contains(Me))throw new TypeError("Node is currently being rendered to and thus is locked.");var p=c,m=Me,k=[],L=d(i),F=i.namespaceURI;Me=i,c=typeof o=="function"?o:void 0,f={};try{i.vnodes==null&&(i.textContent=""),r=t.normalizeChildren(Array.isArray(r)?r:[r]),V(i,i.vnodes,r,k,null,F==="http://www.w3.org/1999/xhtml"?void 0:F),i.vnodes=r,L!=null&&d(i)!==L&&typeof L.focus=="function"&&L.focus();for(var T=0;T<k.length;T++)k[T]()}finally{c=p,Me=m}}},_e}var Ye,Nt;function jt(){return Nt||(Nt=1,Ye=Cn()(typeof window<"u"?window:null)),Ye}var Be,St;function kn(){if(St)return Be;St=1;var t=me();return Be=function(e,n,u){var a=[],c=!1,f=-1;function s(){for(f=0;f<a.length;f+=2)try{e(a[f],t(a[f+1]),l)}catch(h){u.error(h)}f=-1}function l(){c||(c=!0,n(function(){c=!1,s()}))}l.sync=s;function g(h,d){if(d!=null&&d.view==null&&typeof d!="function")throw new TypeError("m.mount expects a component, not a vnode.");var v=a.indexOf(h);v>=0&&(a.splice(v,2),v<=f&&(f-=2),e(h,[])),d!=null&&(a.push(h,d),e(h,t(d),l))}return{mount:g,redraw:l}},Be}var Ue,Ft;function Ke(){if(Ft)return Ue;Ft=1;var t=jt();return Ue=kn()(t,typeof requestAnimationFrame<"u"?requestAnimationFrame:null,typeof console<"u"?console:null),Ue}var Xe,Dt;function Ht(){return Dt||(Dt=1,Xe=function(t){if(Object.prototype.toString.call(t)!=="[object Object]")return"";var e=[];for(var n in t)u(n,t[n]);return e.join("&");function u(a,c){if(Array.isArray(c))for(var f=0;f<c.length;f++)u(a+"["+f+"]",c[f]);else if(Object.prototype.toString.call(c)==="[object Object]")for(var f in c)u(a+"["+f+"]",c[f]);else e.push(encodeURIComponent(a)+(c!=null&&c!==""?"="+encodeURIComponent(c):""))}}),Xe}var Ge,Vt;function Qe(){if(Vt)return Ge;Vt=1;var t=Ht();return Ge=function(e,n){if(/:([^\/\.-]+)(\.{3})?:/.test(e))throw new SyntaxError("Template parameter names must be separated by either a '/', '-', or '.'.");if(n==null)return e;var u=e.indexOf("?"),a=e.indexOf("#"),c=a<0?e.length:a,f=u<0?c:u,s=e.slice(0,f),l={};Object.assign(l,n);var g=s.replace(/:([^\/\.-]+)(\.{3})?/g,function(M,O,z){return delete l[O],n[O]==null?M:z?n[O]:encodeURIComponent(String(n[O]))}),h=g.indexOf("?"),d=g.indexOf("#"),v=d<0?g.length:d,q=h<0?v:h,$=g.slice(0,q);u>=0&&($+=e.slice(u,c)),h>=0&&($+=(u<0?"?":"&")+g.slice(h,v));var y=t(l);return y&&($+=(u<0&&h<0?"?":"&")+y),a>=0&&($+=e.slice(a)),d>=0&&($+=(a<0?"":"&")+g.slice(d)),$},Ge}var We,_t;function Rn(){if(_t)return We;_t=1;var t=Qe(),e=je();return We=function(n,u){function a(s){return new Promise(s)}function c(s,l){return new Promise(function(g,h){s=t(s,l.params);var d=l.method!=null?l.method.toUpperCase():"GET",v=l.body,q=(l.serialize==null||l.serialize===JSON.serialize)&&!(v instanceof n.FormData||v instanceof n.URLSearchParams),$=l.responseType||(typeof l.extract=="function"?"":"json"),y=new n.XMLHttpRequest,M=!1,O=!1,z=y,H,ee=y.abort;y.abort=function(){M=!0,ee.call(this)},y.open(d,s,l.async!==!1,typeof l.user=="string"?l.user:void 0,typeof l.password=="string"?l.password:void 0),q&&v!=null&&!f(l,"content-type")&&y.setRequestHeader("Content-Type","application/json; charset=utf-8"),typeof l.deserialize!="function"&&!f(l,"accept")&&y.setRequestHeader("Accept","application/json, text/*"),l.withCredentials&&(y.withCredentials=l.withCredentials),l.timeout&&(y.timeout=l.timeout),y.responseType=$;for(var V in l.headers)e.call(l.headers,V)&&y.setRequestHeader(V,l.headers[V]);y.onreadystatechange=function(R){if(!M&&R.target.readyState===4)try{var x=R.target.status>=200&&R.target.status<300||R.target.status===304||/^file:\/\//i.test(s),C=R.target.response,j;if($==="json"){if(!R.target.responseType&&typeof l.extract!="function")try{C=JSON.parse(R.target.responseText)}catch{C=null}}else(!$||$==="text")&&C==null&&(C=R.target.responseText);if(typeof l.extract=="function"?(C=l.extract(R.target,l),x=!0):typeof l.deserialize=="function"&&(C=l.deserialize(C)),x){if(typeof l.type=="function")if(Array.isArray(C))for(var U=0;U<C.length;U++)C[U]=new l.type(C[U]);else C=new l.type(C);g(C)}else{var A=function(){try{j=R.target.responseText}catch{j=C}var P=new Error(j);P.code=R.target.status,P.response=C,h(P)};y.status===0?setTimeout(function(){O||A()}):A()}}catch(P){h(P)}},y.ontimeout=function(R){O=!0;var x=new Error("Request timed out");x.code=R.target.status,h(x)},typeof l.config=="function"&&(y=l.config(y,l,s)||y,y!==z&&(H=y.abort,y.abort=function(){M=!0,H.call(this)})),v==null?y.send():typeof l.serialize=="function"?y.send(l.serialize(v)):v instanceof n.FormData||v instanceof n.URLSearchParams?y.send(v):y.send(JSON.stringify(v))})}a.prototype=Promise.prototype,a.__proto__=Promise;function f(s,l){for(var g in s.headers)if(e.call(s.headers,g)&&g.toLowerCase()===l)return!0;return!1}return{request:function(s,l){typeof s!="string"?(l=s,s=s.url):l==null&&(l={});var g=c(s,l);if(l.background===!0)return g;var h=0;function d(){--h===0&&typeof u=="function"&&u()}return v(g);function v(q){var $=q.then;return q.constructor=a,q.then=function(){h++;var y=$.apply(q,arguments);return y.then(d,function(M){if(d(),h===0)throw M}),v(y)},q}}}},We}var Je,Yt;function En(){if(Yt)return Je;Yt=1;var t=Ke();return Je=Rn()(typeof window<"u"?window:null,t.redraw),Je}var Ze,Bt;function Ut(){if(Bt)return Ze;Bt=1;function t(e){try{return decodeURIComponent(e)}catch{return e}}return Ze=function(e){if(e===""||e==null)return{};e.charAt(0)==="?"&&(e=e.slice(1));for(var n=e.split("&"),u={},a={},c=0;c<n.length;c++){var f=n[c].split("="),s=t(f[0]),l=f.length===2?t(f[1]):"";l==="true"?l=!0:l==="false"&&(l=!1);var g=s.split(/\]\[?|\[/),h=a;s.indexOf("[")>-1&&g.pop();for(var d=0;d<g.length;d++){var v=g[d],q=g[d+1],$=q==""||!isNaN(parseInt(q,10));if(v===""){var s=g.slice(0,d).join();u[s]==null&&(u[s]=Array.isArray(h)?h.length:0),v=u[s]++}else if(v==="__proto__")break;if(d===g.length-1)h[v]=l;else{var y=Object.getOwnPropertyDescriptor(h,v);y!=null&&(y=y.value),y==null&&(h[v]=y=$?[]:{}),h=y}}}return a},Ze}var et,Kt;function tt(){if(Kt)return et;Kt=1;var t=Ut();return et=function(e){var n=e.indexOf("?"),u=e.indexOf("#"),a=u<0?e.length:u,c=n<0?a:n,f=e.slice(0,c).replace(/\/{2,}/g,"/");return f?f[0]!=="/"&&(f="/"+f):f="/",{path:f,params:n<0?{}:t(e.slice(n+1,a))}},et}var nt,Xt;function Mn(){if(Xt)return nt;Xt=1;var t=tt();return nt=function(e){var n=t(e),u=Object.keys(n.params),a=[],c=new RegExp("^"+n.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,function(f,s,l){return s==null?"\\"+f:(a.push({k:s,r:l==="..."}),l==="..."?"(.*)":l==="."?"([^/]+)\\.":"([^/]+)"+(l||""))})+"\\/?$");return function(f){for(var s=0;s<u.length;s++)if(n.params[u[s]]!==f.params[u[s]])return!1;if(!a.length)return c.test(f.path);var l=c.exec(f.path);if(l==null)return!1;for(var s=0;s<a.length;s++)f.params[a[s].k]=a[s].r?l[s+1]:decodeURIComponent(l[s+1]);return!0}},nt}var rt,Gt;function Qt(){if(Gt)return rt;Gt=1;var t=je(),e=new RegExp("^(?:key|oninit|oncreate|onbeforeupdate|onupdate|onbeforeremove|onremove)$");return rt=function(n,u){var a={};if(u!=null)for(var c in n)t.call(n,c)&&!e.test(c)&&u.indexOf(c)<0&&(a[c]=n[c]);else for(var c in n)t.call(n,c)&&!e.test(c)&&(a[c]=n[c]);return a},rt}var it,Wt;function Pn(){if(Wt)return it;Wt=1;var t=me(),e=qt(),n=Qe(),u=tt(),a=Mn(),c=Qt(),f={};function s(l){try{return decodeURIComponent(l)}catch{return l}}return it=function(l,g){var h=l==null?null:typeof l.setImmediate=="function"?l.setImmediate:l.setTimeout,d=Promise.resolve(),v=!1,q=!1,$=0,y,M,O=f,z,H,ee,V,R={onbeforeupdate:function(){return $=$?2:1,!(!$||f===O)},onremove:function(){l.removeEventListener("popstate",j,!1),l.removeEventListener("hashchange",C,!1)},view:function(){if(!(!$||f===O)){var P=[t(z,H.key,H)];return O&&(P=O.render(P[0])),P}}},x=A.SKIP={};function C(){v=!1;var P=l.location.hash;A.prefix[0]!=="#"&&(P=l.location.search+P,A.prefix[0]!=="?"&&(P=l.location.pathname+P,P[0]!=="/"&&(P="/"+P)));var I=P.concat().replace(/(?:%[a-f89][a-f0-9])+/gim,s).slice(A.prefix.length),N=u(I);Object.assign(N.params,l.history.state);function _(E){console.error(E),U(M,null,{replace:!0})}w(0);function w(E){for(;E<y.length;E++)if(y[E].check(N)){var S=y[E].component,pe=y[E].route,xe=S,he=V=function(te){if(he===V){if(te===x)return w(E+1);z=te!=null&&(typeof te.view=="function"||typeof te=="function")?te:"div",H=N.params,ee=I,V=null,O=S.render?S:null,$===2?g.redraw():($=2,g.redraw.sync())}};S.view||typeof S=="function"?(S={},he(xe)):S.onmatch?d.then(function(){return S.onmatch(N.params,I,pe)}).then(he,I===M?null:_):he("div");return}if(I===M)throw new Error("Could not resolve default route "+M+".");U(M,null,{replace:!0})}}function j(){v||(v=!0,h(C))}function U(P,I,N){if(P=n(P,I),q){j();var _=N?N.state:null,w=N?N.title:null;N&&N.replace?l.history.replaceState(_,w,A.prefix+P):l.history.pushState(_,w,A.prefix+P)}else l.location.href=A.prefix+P}function A(P,I,N){if(!P)throw new TypeError("DOM element being rendered to does not exist.");if(y=Object.keys(N).map(function(w){if(w[0]!=="/")throw new SyntaxError("Routes must start with a '/'.");if(/:([^\/\.-]+)(\.{3})?:/.test(w))throw new SyntaxError("Route parameter names must be separated with either '/', '.', or '-'.");return{route:w,component:N[w],check:a(w)}}),M=I,I!=null){var _=u(I);if(!y.some(function(w){return w.check(_)}))throw new ReferenceError("Default route doesn't match any known routes.")}typeof l.history.pushState=="function"?l.addEventListener("popstate",j,!1):A.prefix[0]==="#"&&l.addEventListener("hashchange",C,!1),q=!0,g.mount(P,R),C()}return A.set=function(P,I,N){V!=null&&(N=N||{},N.replace=!0),V=null,U(P,I,N)},A.get=function(){return ee},A.prefix="#!",A.Link={view:function(P){var I=e(P.attrs.selector||"a",c(P.attrs,["options","params","selector","onclick"]),P.children),N,_,w;return(I.attrs.disabled=!!I.attrs.disabled)?(I.attrs.href=null,I.attrs["aria-disabled"]="true"):(N=P.attrs.options,_=P.attrs.onclick,w=n(I.attrs.href,P.attrs.params),I.attrs.href=A.prefix+w,I.attrs.onclick=function(E){var S;typeof _=="function"?S=_.call(E.currentTarget,E):_==null||typeof _!="object"||typeof _.handleEvent=="function"&&_.handleEvent(E),S!==!1&&!E.defaultPrevented&&(E.button===0||E.which===0||E.which===1)&&(!E.currentTarget.target||E.currentTarget.target==="_self")&&!E.ctrlKey&&!E.metaKey&&!E.shiftKey&&!E.altKey&&(E.preventDefault(),E.redraw=!1,A.set(w,null,N))}),I}},A.param=function(P){return H&&P!=null?H[P]:H},A},it}var at,Jt;function Tn(){if(Jt)return at;Jt=1;var t=Ke();return at=Pn()(typeof window<"u"?window:null,t),at}var ot,Zt;function qn(){if(Zt)return ot;Zt=1;var t=xn(),e=En(),n=Ke(),u=zt(),a=function(){return t.apply(this,arguments)};return a.m=t,a.trust=t.trust,a.fragment=t.fragment,a.Fragment="[",a.mount=n.mount,a.route=Tn(),a.render=jt(),a.redraw=n.redraw,a.request=e.request,a.parseQueryString=Ut(),a.buildQueryString=Ht(),a.parsePathname=tt(),a.buildPathname=Qe(),a.vnode=me(),a.censor=Qt(),a.domFor=u.domFor,ot=a,ot}var $n=qn();const b=Re($n),Te={};function en(t){if(Te[t])return Te[t];throw new Error(`Component of type '${t}' was not found`)}function W(t,e,n=!1){Te[t]&&!n?console.warn(`Component ignored. Name '${t}' is already registered.`):Te[t]=e}function re(t){return t.type?t.hidden?null:b(en(t.type),{data:t}):(console.error(new Error("Given data is missing the .type property. Component can resolve the component"),t),null)}function oe(t){return Ln(t,On(t))}function ce(t,e){const n=zn(t,e);return An(t,n),n}function On(t){if("target"in t&&t.target&&t.property!=null&&t.property in t.target)return t.target[t.property];if("value"in t)return t.value}function An(t,e){"target"in t&&t.target&&t.property!=null?t.target[t.property]=e:In(t,"value")&&(t.value=e)}function In(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!n||!!n.writable||!!n.set}function zn(t,e){return"codec"in t&&t.codec?t.codec.encode(e):e}function Ln(t,e){return"codec"in t&&t.codec?t.codec.decode(e):e}function ge(t){return typeof t=="string"}function qe(t){return typeof t=="number"}function $e(t){return typeof t=="function"}function ut(t){return Array.isArray(t)}function tn(t){return t!=null&&typeof t=="object"&&!ut(t)}function Z(t,...e){return $e(t)?t(...e):null}function Nn(t){return $e(t)?t():t}function de(t,e){return t==null?null:e(t)}function ue(t,e,n){if(t!=null){if(e!=null&&t<e)return e;if(n!=null&&t>n)return n}return t}function fe(t){return t?ge(t)?t:ut(t)?t.map(fe).join(" "):Object.keys(t).filter(e=>Nn(t[e])).filter(e=>ge(e)&&!!e).join(" "):null}function ct(t,e,n){for(;t.length<e;)t=`${n}${t}`;return t}function B(t,e){return`twui-${t}`+(e?`-${e}`:"")}function st(t){let e=0,n=0;return"touches"in t?(e=t.touches.item(0).pageX,n=t.touches.item(0).pageY):(e=t.pageX,n=t.pageY),[e,n]}function Ee(t,e,n){e=e||t.target;const u=e.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,c=window.pageYOffset||document.documentElement.scrollTop,f=e.clientWidth,s=e.clientHeight;let[l,g]=st(t);n&&(l+=n[0],g+=n[1]);const h=l-a-u.left,d=g-c-u.top;return{width:f,height:s,x:h,y:d,normalizedX:h/f,normalizedY:d/s}}function se(t){return e=>de(e.attrs.data,n=>t(n,e))}function Oe({onStart:t,onMove:e,onEnd:n}){const u={target:null,activate:a=>{u.deactivate(),u.target=a.target,t&&t(a),e&&(document.addEventListener("mousemove",e,{passive:!1}),document.addEventListener("touchmove",e,{passive:!1})),n&&(document.addEventListener("mouseup",n),document.addEventListener("touchend",n),document.addEventListener("touchcancel",n))},deactivate:()=>{u.target=null,e&&(document.removeEventListener("mousemove",e),document.removeEventListener("touchmove",e)),n&&(document.removeEventListener("mouseup",n),document.removeEventListener("touchend",n),document.removeEventListener("touchcancel",n))},onStart:t,onMove:e,onEnd:n};return u}const nn="angle";W(nn,t=>{let e=0,n=!1,u=[0,0];function a(y){return y*(180/Math.PI)}function c(y){return y*(Math.PI/180)}function f(y){return ue((y/2+.5)*100,0,100)}function s(y){const M=y.attrs.data;e=oe(M)??e,M.degree&&(e=c(e)),g()}function l(y){g();const M=t.attrs.data,O=M.degree?c(e):e,z=ce(M,O);Z(y==="input"?M.onInput:M.onChange,M,z)}function g(){u[0]=Math.cos(e),u[1]=Math.sin(e)}function h(y){n=!0,v.activate(y)}let d;const v=Oe({onStart:y=>{const M=Ee(y);d=[-(M.x-M.width/2),-(M.y-M.height/2)],v.onMove(y)},onMove:y=>{y.preventDefault();const M=Ee(y,v.target.parentElement,d),O=M.normalizedX-.5,z=M.normalizedY-.5;n&&(e=Math.atan2(O,z),e+=e<0?2*Math.PI:0),l("input"),b.redraw()},onEnd:y=>{v.deactivate(),n=!1,l("change"),b.redraw()}});function q(y,M){e=c(M),l("input")}function $(y,M){e=c(M),l("change")}return{onremove:()=>{v.deactivate()},oninit:y=>{s(y)},onupdate:y=>{s(y)},view:()=>b("div",{class:B(nn),style:{"--angle-value":`${a(-e)+90}deg`,"--angle-percent":`${a(e)/360*100}%`}},b("div.left-container",b("div.pane",{style:{position:"relative",width:"100%","padding-top":"100%"}},b("div.angle-pane",{class:fe({"is-dragging":n}),style:{position:"absolute",top:"0.5rem",left:"0.5rem",width:"calc(100% - 1rem)",height:"calc(100% - 1rem)"}},b("div.angle-knob",{onmousedown:h,ontouchstart:h,style:{position:"absolute",width:"15px",height:"15px",top:`calc(${f(u[0])}% - 7px)`,left:`calc(${f(u[1])}% - 7px)`}})))),b("div.right-container",b("label",b.trust("α")),re({type:"number",min:0,max:360,step:.1,value:a(e),onInput:q,onChange:$})))}});function jn({axes:t,length:e,result:n}={}){t=t||{x:"right",y:"up"};const u=Object.keys(t),a=()=>(typeof e=="function"?e():e)||1;return{decode:c=>{let f=0,s=0;for(const g of u)switch(t[g]){case"right":s=c[g];break;case"left":s=-c[g];break;case"up":case"front":f=-c[g];break;case"down":case"back":f=c[g]}const l=a();return f/=l,s/=l,Math.atan2(s,f)||0},encode:c=>{const f=a(),s=f*Math.cos(c),l=f*Math.sin(c),g=n()||{};for(const h of u)switch(t[h]){case"right":g[h]=l;break;case"left":g[h]=-l;break;case"up":case"front":g[h]=-s;break;case"down":case"back":g[h]=s;break}return g}}}const rn="checkbox";W(rn,t=>{function e(n){const u=t.attrs.data,a=n.target.checked,c=ce(u,a);Z(u.onChange,u,c)}return{view:se(n=>{const u=oe(n)===!0;return b("label",{class:fe({[B(rn)]:!0,checked:u,disabled:n.disabled})},b("input",{type:"checkbox",checked:u,onchange:e,disabled:n.disabled}),n.text)})}});function an(t){let e=t.h%360,n=ue(t.s,0,1),u=ue(t.v,0,1),a=u*n,c=a*(1-Math.abs(e/60%2-1)),f=u-a;const s={r:0,g:0,b:0};return e<60?(s.r=a,s.g=c,s.b=0):e<120?(s.r=c,s.g=a,s.b=0):e<180?(s.r=0,s.g=a,s.b=c):e<240?(s.r=0,s.g=c,s.b=a):e<300?(s.r=c,s.g=0,s.b=a):(s.r=a,s.g=0,s.b=c),s.r+=f,s.g+=f,s.b+=f,s}function lt(t){let e=t.r,n=t.g,u=t.b,a=Math.max(e,n,u),c=a-Math.min(e,n,u),f=0,s=0;return c!==0&&(f=c/a,a===e?(s=(n-u)/c+(n<u?6:0),s=s%6*60):a===n?(s=(u-e)/c+2,s=s*60):(s=(e-n)/c+4,s=s*60)),{h:s,s:f,v:a}}class Sn{constructor(e,n){this.components=e,this.normalized=n}parse(e){e=e||[];const n={r:0,g:0,b:0,a:1};return this.components.forEach((u,a)=>{n[u]=(e[a]||0)/(this.normalized?1:255)}),n}format(e){return this.components.map(n=>(this.normalized?e[n]:Math.round(e[n]*255))||0)}}class Fn{constructor(e){this.components=e}parse(e){e=e||"rgba(0, 0, 0)";const n={r:0,g:0,b:0,a:1},u=e.replace(/[rgba\(\)]/gi,"").split(/,\s*?/gi).map(Number);return this.components.forEach((a,c)=>{n[a]=(u[c]||0)/(a==="a"?1:255)}),n}format(e){return this.components.join("")+"("+this.components.map(n=>n==="a"?e[n]:Math.round(e[n]*255)).join(", ")+")"}}class Dn{constructor(e){this.components=e}parse(e){e=e||"#000";const n={r:0,g:0,b:0,a:1};let u=e.match(/[0-9a-f]+/i)[0];return u.length===this.components.length&&(u=u.split("").map(a=>`${a}${a}`).join("")),this.components.forEach((a,c)=>{n[a]=parseInt(u.substr(c*2,2),16)/255}),n}format(e){return"#"+this.components.map(n=>ct(Math.round(e[n]*255).toString(16),2,"0")).join("")}}class Hn{constructor(e){this.components=e,this.componentsRev=e.slice().reverse()}parse(e){e=e||0;const n={r:0,g:0,b:0,a:1};return this.components.forEach((u,a)=>{n[u]=(e>>a*8&255)/255}),n}format(e){const n=this.componentsRev.map(u=>ct(Math.round(e[u]*255||0).toString(16),2,"0")).join("");return parseInt("0x"+n,16)}}class Vn{constructor(e,n){this.components=e,this.normalized=n}parse(e){e=e||{};const n={r:0,g:0,b:0,a:1};return this.components.forEach((u,a)=>{n[u]=(e[u]||0)/(this.normalized?1:255)}),n}format(e){const n={};return this.components.forEach((u,a)=>{n[u]=(this.normalized?e[u]:Math.round(e[u]*255))||0}),n}}const ye={};function be(t="rgb"){if(t in ye)return ye[t];const e=(t.match(/[rgba]+/)[0]||"").split("");return/(\[n?\])/.test(t)?ye[t]=new Sn(e,/\[n\]/.test(t)):/(\{n?\})/.test(t)?ye[t]=new Vn(e,/\{n\}/.test(t)):/0x/.test(t)?ye[t]=new Hn(e):/(\(\))/.test(t)?ye[t]=new Fn(e):ye[t]=new Dn(e),ye[t]}W("color-picker",t=>{let e=0,n=0,u=0,a=0;function c(w=n,E=u){return{h:e*360,s:w,v:E,a}}function f(w=n,E=u){return an(c(w,E))}function s(w=n,E=u,S=a){return{...f(w,E),a:S}}function l(w){e=w.h/360,n=w.s,u=w.v}function g(w){l(w),a=w.a}function h(w,E){return be("#rgb").format(s(w,E))}function d(w,E){return be("#rgba").format(s(w,E))}function v(w=n,E=u,S=a){return be("rgba()").format(s(w,E,S))}function q(w,E){const S=be(E||"rgb").parse(w);g({...lt(S),a:S.a})}function $(w){return be(w).format(s())}function y(){de(t.attrs.data,w=>{const E=$(w.format),S=ce(w,E);Z(w.onInput,w,S)})}function M(){de(t.attrs.data,w=>{const E=$(w.format),S=ce(w,E);Z(w.onChange,w,S)})}function O(){return de(t.attrs.data,w=>w.format&&w.format.match(/a/i))}function z(w){V(w,"r")}function H(w){V(w,"g")}function ee(w){V(w,"b")}function V(w,E){const S=s();S[E]=parseInt(w.target.value,10)/255,l(lt(S)),y(),M()}function R(w){q(w.target.value,O()?"rgba":"rgb"),y(),M()}let x,C;function j(w){C="sv",P(w.target),N(w)}function U(w){C="h",P(w.target),N(w)}function A(w){C="a",P(w.target),N(w)}function P(w){I(),x=w;const E={passive:!1};document.addEventListener("mousemove",N,E),document.addEventListener("mouseup",_,E),document.addEventListener("touchmove",N,E),document.addEventListener("touchend",_,E),document.addEventListener("touchcancel",_,E)}function I(){document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",_),document.removeEventListener("touchmove",N),document.removeEventListener("touchend",_),document.removeEventListener("touchcancel",_)}function N(w){if(!x)return;w.preventDefault();const E=x.getBoundingClientRect(),S=window.pageXOffset||document.documentElement.scrollLeft,pe=window.pageYOffset||document.documentElement.scrollTop,xe=x.clientWidth,he=x.clientHeight;let[te,Ce]=st(w);te=ue((te-S-E.left)/xe,0,1),Ce=ue((Ce-pe-E.top)/he,0,1),C==="sv"&&(n=te,u=1-Ce),C==="h"&&(e=1-te),C==="a"&&(a=te),y(),b.redraw()}function _(){x!=null&&(x=null,I(),M())}return{onremove:()=>{I()},oninit:()=>{de(t.attrs.data,w=>{q(oe(w),w.format)})},view:()=>de(t.attrs.data,w=>{const E=s();return b("div",{class:B(w.type)},b(".color-picker-inputs",b("input.input-hex[type='text']",{value:O()?d():h(),onchange:R}),b("input.input-r[type='number']",{min:0,max:255,step:1,value:Math.round(E.r*255),onchange:z}),b("input.input-g[type='number']",{min:0,max:255,step:1,value:Math.round(E.g*255),onchange:H}),b("input.input-b[type='number']",{min:0,max:255,step:1,value:Math.round(E.b*255),onchange:ee})),b(".color-picker-panel",b(".color-picker-sv",{tabindex:0,onmousedown:j,ontouchstart:j,style:{"background-color":`${v(1,1,1)}`,"user-select":"none"}},b(".color-picker-sv-bg",{style:{background:"linear-gradient(to right,rgba(255,255,255,1),rgba(255,255,255,0))","user-select":"none","pointer-events":"none"}}),b(".color-picker-sv-bg",{style:{background:"linear-gradient(to top,rgba(0,0,0,1),rgba(0,0,0,0))","user-select":"none","pointer-events":"none"}}),b(".color-picker-sv-cursor",{style:{"user-select":"none","pointer-events":"none","background-color":`${v(e,n,1)}`,left:`${n*100}%`,top:`${(1-u)*100}%`}})),b(".color-picker-h",{tabindex:0,onmousedown:U,ontouchstart:U,style:{"user-select":"none",background:"linear-gradient(to right, #f00 0, #f0f 17% , #00f 33% , #0ff 50% , #0f0 67% , #ff0 83% , #f00 100%)"}},b(".color-picker-h-cursor",{style:{"user-select":"none","pointer-events":"none","background-color":`${v(1,1,1)}`,position:"absolute",left:`${(1-e)*100}%`}})),O()?b(".color-picker-a",{tabindex:0,onmousedown:A,ontouchstart:A,style:{"user-select":"none"}},b(".color-picker-a-bg",{style:{background:`linear-gradient(to right, ${v(n,u,0)}, ${v(n,u,1)})`}}),b(".color-picker-a-cursor",{style:{"user-select":"none","pointer-events":"none",position:"absolute",left:`${a*100}%`}})):null))})}}),W("color",()=>{let t,e=!1,n,u;const a=be("rgba()");function c(h){t=h.attrs.data,n=oe(t),u=a.format(be(t.format).parse(n))}function f(){e=!e}function s(h,d){const v=ce(t,d);Z(t.onInput,t,v)}function l(h,d){const v=ce(t,d);Z(t.onChange,t,v)}function g(){return ge(n)?n:qe(n)?"0x"+ct(n.toString(16),8,"0"):ut(n)?n.map(h=>h<1&&h>0?h.toFixed(2):h).join(" , "):tn(n)?Object.keys(n).map(h=>{const d=n[h];return`${h}: ${d<1&&d>0?d.toFixed(2):d}`}).join(" "):n==null?"null":"?"}return{oninit:h=>{c(h)},onupdate:h=>{c(h)},view:()=>b("div",{class:fe({[B(t.type)]:!0,[B(t.type+"-open")]:e})},b("button[type='button']",{style:{"background-color":u},onclick:f},g()||"?"),re({type:"color-picker",value:n,format:t.format,onInput:s,onChange:l,hidden:!e}))}});const on=()=>{let t,e,n,u,a,c,f,s,l,g;function h(R){g=R;const x=R.attrs.data;t=x.type,f=x.type==="slider",e=f&&x.min==null?0:x.min,n=f&&x.max==null?1:x.max,u=x.step,s=oe(x),a=x.disabled,l=f?(s-e)/(n-e)*100:0}function d(R,x){x=s=ue(isNaN(x)?null:x,e,n);const C=g.attrs.data,j=ce(C,x);Z(R==="input"?C.onInput:C.onChange,C,j),b.redraw()}function v(R){const x=R.target;d("input",parseFloat(x.value))}function q(R){const x=R.target;d("change",parseFloat(x.value))}function $(R){return R=ue(R,e,n),u!=null&&(R=Math.round(R/u)*u),parseFloat(R.toFixed(5))}let y=Oe({onStart:R=>{y.onMove(R)},onMove:R=>{R.preventDefault();const x=Ee(R,y.target).normalizedX;d("input",$(e+x*(n-e)))},onEnd:()=>{d("change",s),y.deactivate()}});function M(R){a||y.activate(R)}function O(R){const x=R.key||R.keyCode,j=(u||1)*(x==="ArrowLeft"?-1:x==="ArrowRight"?1:0);j&&d("change",$((s||0)+j))}function z(R){R.preventDefault();const x=(R.ctrlKey?.5:1)*ue(R.deltaY,-1,1),C=(u||.2)*x;C&&d("change",$((s||0)-C))}function H(){}function ee(){}function V(){return b(".twui-progress",{style:"user-select: none;",class:fe({disabled:!!a}),...a?{}:{tabindex:0,onmousedown:M,ontouchstart:M,onkeydown:O,onwheel:z}},b(".twui-progress-bar",{style:{width:`${l}%`,"pointer-events":"none","user-select":"none"}}))}return{onremove:()=>{y.deactivate()},oninit:R=>{h(R)},onupdate:R=>{h(R)},view:()=>b("div",{class:B(t)},f?V():null,b("input[type='number']",{min:e,max:n,step:u,value:s,oninput:v,onchange:q,onwheel:z,onfocus:H,onblur:ee,placeholder:c,disabled:a}))}};W("number",on),W("slider",on);const un="point",cn=[0,1],_n=["x","y"];W(un,t=>{let e,n,u=cn,a=cn,c=0,f=0,s=0,l=0,g,h,d;function v(O){const z=O.attrs.data,H=z.keys||_n;e=H[0],n=H[1];const ee=oe(z)??{[e]:c,[n]:f};d=z.snap,c=ee[e]||0,f=ee[n]||0,u=z.xRange||u,a=z.yRange||a,s=(c-u[0])/(u[1]-u[0]),l=(f-a[0])/(a[1]-a[0]);const V=z.reset;V&&(g=(V[0]-u[0])/(u[1]-u[0]),h=(V[1]-a[0])/(a[1]-a[0]))}function q(){c=u[0]+(u[1]-u[0])*s,f=a[0]+(a[1]-a[0])*l,d>0&&(c=Math.floor(c/d)*d,f=Math.floor(f/d)*d,s=(c-u[0])/(u[1]-u[0]),l=(f-a[0])/(a[1]-a[0]))}function $(O){q();const z=t.attrs.data,H=oe(z)??{[e]:c,[n]:f};H[e]=c,H[n]=f,Z(O==="input"?z.onInput:z.onChange,z,H)}function y(O){M.activate(O)}const M=Oe({onMove:O=>{O.preventDefault();const z=M.target,H=z.getBoundingClientRect(),ee=window.pageXOffset||document.documentElement.scrollLeft,V=window.pageYOffset||document.documentElement.scrollTop,R=z.clientWidth,x=z.clientHeight;let[C,j]=st(O);s=ue((C-ee-H.left)/R,0,1),l=ue((j-V-H.top)/x,0,1),$("input"),b.redraw()},onEnd:()=>{M.deactivate(),g!=null&&h!=null&&(s=g,l=h,$("input")),$("change"),b.redraw()}});return{onremove:M.deactivate,oninit:v,onupdate:v,view:()=>b("div",{class:B(un),tabindex:0,onmousedown:y,ontouchstart:y},b(".point-x-axis",{style:{"pointer-events":"none",position:"absolute",left:0,right:0,top:`${l*100}%`,height:"1px"}}),b(".point-y-axis",{style:{"pointer-events":"none",position:"absolute",left:`${s*100}%`,top:0,bottom:0,width:"1px"}}),b(".point-cursor",{style:{"pointer-events":"none",left:`${s*100}%`,top:`${l*100}%`,position:"absolute",width:"11px",height:"11px","margin-top":"-5px","margin-left":"-5px",border:"1px solid white","border-radius":"5px","box-shadow":"0px 0px 2px 1px rgba(0, 0, 0, 0.75)"}}))}});const sn="position",Yn=["x","y","z"];W(sn,t=>{function e(n,u,a){const c=t.attrs.data,f=oe(c)||{};f[u]=isNaN(a)?null:a;const s=ce(c,f);Z(n==="input"?c.onInput:c.onChange,c,s,u)}return{view:se(n=>{const u=n.keys||Yn,a=oe(n);return b("div",{class:B(sn)},u.map(c=>re({type:"number",min:n.min,max:n.max,step:n.step,value:a==null?void 0:a[c],disabled:n.disabled,onInput:(f,s)=>e("input",c,s),onChange:(f,s)=>e("change",c,s),placeholder:c})))})}});const Bn=[];function Un(t){const e=[];for(const n of t){if(ge(n)||qe(n)){e.push({value:n,label:String(n)});continue}if("value"in n){e.push(n);continue}}return e}function Kn(t){const e=[];for(const n of t)ge(n)||qe(n)||n==null?e.push({value:n,label:String(n)}):"value"in n?e.push(n):"options"in n&&e.push({label:n.label,disabled:n.disabled,options:Array.isArray(n.options)?Un(n.options):ln(n.options)});return e}function ln(t){return Object.keys(t).sort().map(e=>({value:t[e],label:e}))}function Xn(t){const e=t.attrs.data.options;return e?Array.isArray(e)?Kn(e):ln(e):Bn}W("select",t=>{let e;function n(){const c=t.attrs.data,f=oe(c);let s=0;for(const l of e)if("options"in l)for(const g of l.options){if(g.value===f)return s;s++}else{if(l.value===f)return s;s++}}function u(c){let f=0;for(const s of e)if("options"in s)for(const l of s.options){if(f===c)return l.value;f+=1}else{if(f===c)return s.value;f+=1}return null}function a(c){const f=c.target,s=t.attrs.data,l=u(f.selectedIndex),g=ce(s,l);Z(s.onChange,s,g)}return{view:se(c=>(e=Xn(t),b("select",{class:B(c.type),selectedIndex:n(),onchange:a,disabled:c.disabled},e.map(f=>"options"in f?b("optgroup",{disabled:!!f.disabled,label:f.label||""},f.options.map(fn)):fn(f)))))}});function fn(t){return b("option",{value:t.value,label:t.label,disabled:!!t.disabled},t.label||"")}const pn="spherical",Gn=["phi","theta"];W(pn,t=>{let e=0,n=0,u=!1,a=[0,0],c=[0,0],f;function s(x){return x*(180/Math.PI)}function l(x){return x*(Math.PI/180)}function g(x){return ue((x/2+.5)*100,0,100)}function h(x){const C=x.attrs.data,j=oe(C)||{phi:C.degree?s(e):e,theta:C.degree?s(n):n},[U,A]=C.keys||Gn;return{data:C,value:j,kPhi:U,kTheta:A}}function d(x){const{data:C,value:j,kPhi:U,kTheta:A}=h(x);for(e=j[U]||0,n=j[A]||0,C.degree&&(e=l(e),n=l(n));n<0;)n+=Math.PI;for(;n>Math.PI;)n-=Math.PI;u=n>Math.PI/2,q()}function v(x){q();const{data:C,value:j,kPhi:U,kTheta:A}=h(t);j[U]=C.degree?s(e):e,j[A]=C.degree?s(n):n;const P=ce(C,j);Z(x==="input"?C.onInput:C.onChange,C,P)}function q(){a[0]=Math.cos(e),a[1]=Math.sin(e),c[0]=Math.sin(n)*Math.cos(e),c[1]=Math.sin(n)*Math.sin(e)}function $(x){f="phi",O.activate(x)}function y(x){f="theta",O.activate(x)}let M;const O=Oe({onStart:x=>{const C=Ee(x);M=[-(C.x-C.width/2),-(C.y-C.height/2)],O.onMove(x)},onMove:x=>{x.preventDefault();const C=Ee(x,O.target.parentElement,M),j=C.normalizedX-.5,U=C.normalizedY-.5;if(f==="phi")e=Math.atan2(j,U),e+=e<0?2*Math.PI:0;else if(f==="theta"){const A=a,P=[U,j],I=(A[0]*P[0]+A[1]*P[1])/Math.sqrt(A[0]*A[0]+A[1]*A[1]);n=Math.PI*ue(I,0,.5),u&&(n=Math.PI-n)}v("input"),b.redraw()},onEnd:x=>{O.deactivate(),f=null,v("change"),b.redraw()}});function z(x,C){e=l(C),v("input")}function H(x,C){e=l(C),v("change")}function ee(x,C){n=l(C),v("input")}function V(x,C){n=l(C),v("change")}function R(x,C){u=C,n=Math.PI-n,v("change"),setTimeout(()=>b.redraw())}return{onremove:()=>{O.deactivate()},oninit:x=>{d(x)},onupdate:x=>{d(x)},view:()=>b("div",{class:B(pn),style:{"--spherical-phi":`${s(-e)+90}deg`}},b("div.left-container",b("div.pane",{style:{position:"relative",width:"100%","padding-top":"100%"}},b("div.phi-pane",{class:fe({"is-dragging":f==="phi"}),style:{position:"absolute",top:"0.5rem",left:"0.5rem",width:"calc(100% - 1rem)",height:"calc(100% - 1rem)"}},b("div.phi-knob",{onmousedown:$,ontouchstart:$,style:{position:"absolute",width:"15px",height:"15px",top:`calc(${g(a[0])}% - 7px)`,left:`calc(${g(a[1])}% - 7px)`}})),b("div.theta-pane",{class:fe({"is-dragging":f==="theta"}),style:{position:"absolute",top:"1.5rem",left:"1.5rem",width:"calc(100% - 3rem)",height:"calc(100% - 3rem)"}},b("div.theta-knob",{onmousedown:y,ontouchstart:y,style:{position:"absolute",width:"15px",height:"15px",top:`calc(${g(c[0])}% - 7px)`,left:`calc(${g(c[1])}% - 7px)`}})))),b("div.right-container",b("label",b.trust("φ")),re({type:"number",min:0,max:360,step:.1,value:s(e),onInput:z,onChange:H}),b("label",b.trust("θ")),re({type:"number",min:0,max:180,step:.1,value:s(n),onInput:ee,onChange:V}),re({type:"checkbox",value:u,text:"Backface",onChange:R})))}});function Qn({axes:t,length:e,result:n}={}){t=t||{x:"right",y:"up",z:"back"};const u=Object.keys(t),a=()=>(typeof e=="function"?e():e)||1;return{decode:c=>{let f=0,s=0,l=0;for(const h of u)switch(t[h]){case"right":s=c[h];break;case"left":s=-c[h];break;case"back":f=c[h];break;case"front":f=-c[h];break;case"up":l=c[h];break;case"down":l=-c[h];break}const g=a();return f/=g,s/=g,l/=g,{phi:Math.atan2(s,f)||0,theta:Math.atan(Math.sqrt(f*f+s*s)/l)||0}},encode:({phi:c,theta:f})=>{const s=a(),l=s*Math.sin(f)*Math.cos(c),g=s*Math.sin(f)*Math.sin(c),h=s*Math.cos(f),d=(n==null?void 0:n())||{};for(const v of u)switch(t[v]){case"right":d[v]=g;break;case"left":d[v]=-g;break;case"back":d[v]=l;break;case"front":d[v]=-l;break;case"up":d[v]=h;break;case"down":d[v]=-h;break}return d}}}W("text",t=>{function e(n){const u=n.target,a=t.attrs.data,c=ce(a,u.value);Z(n.type==="input"?a.onInput:a.onChange,a,c)}return{view:se(n=>b("input[type='text']",{class:B(n.type),value:oe(n),oninput:e,onchange:e,placeholder:n.placeholder,disabled:n.disabled}))}});const Wn="accordion",Jn=[];W(Wn,()=>({view:se(t=>{const e=t.children||Jn;return t.expand=Zn(t.expand,e),b.fragment({},e.map((n,u)=>(n.type="group",n.collapsible=!0,n.collapsed=u!==t.expand,re(n))))})}));function Zn(t,e){let n=null;for(let u=0;u<e.length;u++)if(!e[u].collapsed){if(u!==t)return u;n==null&&(n=u)}return n}const ft="container";W(ft,()=>({view:se(t=>{var e;return b("div",{class:fe({[B(ft)]:!0,[B(ft,"horizontal")]:t.horizontal}),style:t.style},b.fragment({},(e=t.children)==null?void 0:e.map(re)))})}));const we="group";W(we,t=>{function e(a){de(t.attrs.data,c=>{c.collapsed=!c.collapsed,Z(c.onToggle,c),c.collapsed?Z(c.onCollapse,c):Z(c.onExpand,c)})}function n(a){return!a.title&&!a.collapsible?null:b("div",{class:B(we,"title"),onclick:a.collapsible?e:null},a.title)}function u(a){var c;return a.collapsed||!a.children?[]:(c=a.children)==null?void 0:c.map(f=>ge(f.label)?b("div",{class:B(we,"control")},b("label",f.label),b("section",re(f))):re(f))}return{view:se(a=>b("div",{class:fe({[B(we)]:!0,[B(we,"collapsible")]:a.collapsible,[B(we,"collapsed")]:a.collapsed}),style:a.style},b.fragment({},[n(a)]),b.fragment({},[u(a)])))}}),W("tabs",()=>({view:se(t=>{const e=t.children||[],n=ue(t.active||0,0,e.length-1),u=e[n];return b("div",{class:B(t.type)},b("div",{key:`${t.type}-list`,class:B(`${t.type}-list`)},e.map((a,c)=>b("button[type='button']",{key:`${t.type}-${c}`,onclick:()=>t.active=c,class:n===c?"is-active":""},a.label||a.title))),b.fragment({key:`panel-${t.active}`},[re({type:"group",children:u.children,style:u.style})]))})}));const Ae="button";W(Ae,t=>({view:se(e=>b(Ae,{type:Ae,class:B(Ae),onclick:()=>Z(e.onClick,e),disabled:e.disabled},e.text))})),W("content",()=>({view:se(t=>b.fragment({},[t.content]))}));const hn="image";W("image",t=>{const e=()=>{de(t.attrs.data,a=>Z(a.onClick,a))};function n(a){if(!a)return null;const[c,f]=(a||"1x1").split("x").map(Number);return`${(f/c||1)*100}%`}function u(a){if(qe(a.width))return`${a.width}px`;if(ge(a.width))return a.width}return{view:se(a=>(Array.isArray(a.src)?a.src:[a.src]).map(c=>b("picture",{class:fe({[B(hn)]:!0,[B(hn,"aspect")]:!!a.aspect}),style:{"--twui-aspect":n(a.aspect),"--twui-fit":a.fit||"fit",width:u(a)}},b("img",{src:c,onclick:e}))))}});function Q(t,e){return Object.keys(e).forEach(n=>{t[n]=e[n]}),t}function ve(){let t=null,e={},n;for(let u=0;u<arguments.length;u++){const a=arguments[u];ge(a)?t=a:tn(a)?e=a:$e(a)&&(n=a)}if(t&&(e.label=t),n){const u=this.controls;this.controls=[],n(this),e.children=this.controls,this.controls=u}return e}function le(){let t={};return arguments.length>1&&(t=arguments[2]||t,t.target=arguments[0],t.property=arguments[1],t.label===void 0&&(t.label=String(t.property||""))),arguments.length===1&&(t=arguments[0]||t),t}class pt{constructor(){this.controls=[]}group(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"group",children:e.children,label:null,title:e.label}))}collapsible(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"group",children:e.children,collapsible:!0,label:null,title:e.label}))}container(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"container",children:e.children}))}tabs(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"tabs",active:e.active||0,children:e.children}))}accordion(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"accordion",children:e.children}))}checkbox(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"checkbox"}))}text(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"text"}))}number(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"number"}))}slider(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"slider"}))}position(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"position"}))}select(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"select"}))}color(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"color"}))}colorPicker(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"color-picker"}))}point(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"point"}))}spherical(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"spherical"}))}angle(){const e=le.apply(this,arguments);return this.add(Q(e,{type:"angle"}))}object(e,n,u={}){return this.group(e,a=>{for(const c in n){if(!u[c]){switch(typeof n[c]){case"number":a.number(n,c);break;case"string":a.text(n,c);break;case"boolean":a.checkbox(n,c);break}continue}switch(u[c].type){case"text":a.text(n,c,u[c]);break;case"number":a.number(n,c,u[c]);break;case"checkbox":a.checkbox(n,c,u[c]);break;case"select":a.select(n,c,u[c]);break;case"color":a.color(n,c,u[c]);break;case"color-picker":a.colorPicker(n,c,u[c]);break;case"point":a.point(n,c,u[c]);break;case"spherical":a.spherical(n,c,u[c]);break;case"angle":a.angle(n,c,u[c]);break}}})}button(e,n={}){return this.add(Q(n,{type:"button",text:e}))}image(){const e=ve.apply(this,arguments);return this.add(Q(e,{type:"image"}))}content(e,n,u={}){return this.add(Q(u,{type:"content",label:e,content:n}))}add(e){return this.controls.push(Q(e,{remove:()=>{const n=this.controls.indexOf(e);n>=0&&this.controls.splice(n,1)}})),e}}const er=b;function tr(t){const e=new pt;return t(e),e.controls}function nr(t,e){if(t=typeof t=="string"?document.querySelector(t):t,t.classList.add("twui-root"),!e)b.mount(t,null);else if(Array.isArray(e))b.mount(t,{view:()=>re({type:"group",children:e})});else if($e(e)){const n=new pt;e(n),b.mount(t,{view:()=>re({type:"group",children:n.controls})})}else b.mount(t,{view:()=>re(e)})}function rr(t){t=typeof t=="string"?document.querySelector(t):t,b.mount(t,null)}function ir(){b.redraw()}X.Builder=pt,X.angleCodec=jn,X.build=tr,X.component=W,X.getColorFormatter=be,X.getComponent=en,X.getValue=oe,X.h=er,X.hsv2rgb=an,X.mount=nr,X.redraw=ir,X.renderModel=re,X.rgb2hsv=lt,X.setValue=ce,X.sphericalCodec=Qn,X.unmount=rr,Object.defineProperty(X,Symbol.toStringTag,{value:"Module"})});
|
|
4404
2
|
//# sourceMappingURL=tweak-ui.umd.js.map
|