tweak-ui 0.4.3 → 0.8.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.
Files changed (200) hide show
  1. package/LICENSE +7 -7
  2. package/README.md +32 -32
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/lib/builder.d.ts +102 -162
  6. package/dist/lib/builder.d.ts.map +1 -1
  7. package/dist/lib/color/adapter.d.ts +7 -0
  8. package/dist/lib/color/adapter.d.ts.map +1 -0
  9. package/dist/lib/color/array-format.d.ts +9 -0
  10. package/dist/lib/color/array-format.d.ts.map +1 -0
  11. package/dist/lib/{color-formats → color}/converter.d.ts +18 -18
  12. package/dist/lib/color/converter.d.ts.map +1 -0
  13. package/dist/lib/color/css-string-format.d.ts +8 -0
  14. package/dist/lib/color/css-string-format.d.ts.map +1 -0
  15. package/dist/lib/color/formatter.d.ts +9 -0
  16. package/dist/lib/color/formatter.d.ts.map +1 -0
  17. package/dist/lib/color/hex-string-format.d.ts +9 -0
  18. package/dist/lib/color/hex-string-format.d.ts.map +1 -0
  19. package/dist/lib/{color-formats → color}/index.d.ts +3 -3
  20. package/dist/lib/color/index.d.ts.map +1 -0
  21. package/dist/lib/color/number-format.d.ts +9 -0
  22. package/dist/lib/color/number-format.d.ts.map +1 -0
  23. package/dist/lib/{color-formats → color}/object-format.d.ts +14 -14
  24. package/dist/lib/color/object-format.d.ts.map +1 -0
  25. package/dist/lib/{color-formats → color}/types.d.ts +107 -101
  26. package/dist/lib/color/types.d.ts.map +1 -0
  27. package/dist/lib/components/container/bar.d.ts +28 -0
  28. package/dist/lib/components/container/bar.d.ts.map +1 -0
  29. package/dist/lib/components/container/dialog.d.ts +14 -0
  30. package/dist/lib/components/container/dialog.d.ts.map +1 -0
  31. package/dist/lib/components/container/grid.d.ts +22 -0
  32. package/dist/lib/components/container/grid.d.ts.map +1 -0
  33. package/dist/lib/components/container/group.d.ts +55 -0
  34. package/dist/lib/components/container/group.d.ts.map +1 -0
  35. package/dist/lib/components/container/index.d.ts +10 -0
  36. package/dist/lib/components/container/index.d.ts.map +1 -0
  37. package/dist/lib/components/container/list.d.ts +25 -0
  38. package/dist/lib/components/container/list.d.ts.map +1 -0
  39. package/dist/lib/components/container/section.d.ts +28 -0
  40. package/dist/lib/components/container/section.d.ts.map +1 -0
  41. package/dist/lib/components/container/split.d.ts +40 -0
  42. package/dist/lib/components/container/split.d.ts.map +1 -0
  43. package/dist/lib/components/container/tabs.d.ts +23 -0
  44. package/dist/lib/components/container/tabs.d.ts.map +1 -0
  45. package/dist/lib/components/container/tree.d.ts +25 -0
  46. package/dist/lib/components/container/tree.d.ts.map +1 -0
  47. package/dist/lib/components/controls/angle.d.ts +47 -51
  48. package/dist/lib/components/controls/angle.d.ts.map +1 -1
  49. package/dist/lib/components/controls/bitmask.d.ts +41 -0
  50. package/dist/lib/components/controls/bitmask.d.ts.map +1 -0
  51. package/dist/lib/components/controls/bool.d.ts +52 -0
  52. package/dist/lib/components/controls/bool.d.ts.map +1 -0
  53. package/dist/lib/components/controls/color-picker.d.ts +41 -56
  54. package/dist/lib/components/controls/color-picker.d.ts.map +1 -1
  55. package/dist/lib/components/controls/color.d.ts +37 -51
  56. package/dist/lib/components/controls/color.d.ts.map +1 -1
  57. package/dist/lib/components/controls/index.d.ts +14 -10
  58. package/dist/lib/components/controls/index.d.ts.map +1 -1
  59. package/dist/lib/components/controls/input.d.ts +44 -0
  60. package/dist/lib/components/controls/input.d.ts.map +1 -0
  61. package/dist/lib/components/controls/matrix.d.ts +58 -0
  62. package/dist/lib/components/controls/matrix.d.ts.map +1 -0
  63. package/dist/lib/components/controls/point.d.ts +41 -47
  64. package/dist/lib/components/controls/point.d.ts.map +1 -1
  65. package/dist/lib/components/controls/poll.d.ts +12 -0
  66. package/dist/lib/components/controls/poll.d.ts.map +1 -0
  67. package/dist/lib/components/controls/scalar.d.ts +67 -0
  68. package/dist/lib/components/controls/scalar.d.ts.map +1 -0
  69. package/dist/lib/components/controls/select.d.ts +53 -59
  70. package/dist/lib/components/controls/select.d.ts.map +1 -1
  71. package/dist/lib/components/controls/spherical.d.ts +37 -74
  72. package/dist/lib/components/controls/spherical.d.ts.map +1 -1
  73. package/dist/lib/components/controls/string.d.ts +46 -0
  74. package/dist/lib/components/controls/string.d.ts.map +1 -0
  75. package/dist/lib/components/controls/vector.d.ts +54 -0
  76. package/dist/lib/components/controls/vector.d.ts.map +1 -0
  77. package/dist/lib/components/elements/button.d.ts +36 -0
  78. package/dist/lib/components/elements/button.d.ts.map +1 -0
  79. package/dist/lib/components/elements/divider.d.ts +4 -0
  80. package/dist/lib/components/elements/divider.d.ts.map +1 -0
  81. package/dist/lib/components/elements/graph.d.ts +8 -0
  82. package/dist/lib/components/elements/graph.d.ts.map +1 -0
  83. package/dist/lib/components/elements/image.d.ts +33 -0
  84. package/dist/lib/components/elements/image.d.ts.map +1 -0
  85. package/dist/lib/components/elements/index.d.ts +6 -0
  86. package/dist/lib/components/elements/index.d.ts.map +1 -0
  87. package/dist/lib/components/elements/widget.d.ts +27 -0
  88. package/dist/lib/components/elements/widget.d.ts.map +1 -0
  89. package/dist/lib/components/index.d.ts +3 -5
  90. package/dist/lib/components/index.d.ts.map +1 -1
  91. package/dist/lib/core/control.d.ts +20 -0
  92. package/dist/lib/core/control.d.ts.map +1 -0
  93. package/dist/lib/core/index.d.ts +3 -4
  94. package/dist/lib/core/index.d.ts.map +1 -1
  95. package/dist/lib/core/render.d.ts +7 -9
  96. package/dist/lib/core/render.d.ts.map +1 -1
  97. package/dist/lib/core/types.d.ts +73 -87
  98. package/dist/lib/core/types.d.ts.map +1 -1
  99. package/dist/lib/core/utils.d.ts +78 -93
  100. package/dist/lib/core/utils.d.ts.map +1 -1
  101. package/dist/lib/index.d.ts +21 -27
  102. package/dist/lib/index.d.ts.map +1 -1
  103. package/dist/lib/mount.d.ts +35 -45
  104. package/dist/lib/mount.d.ts.map +1 -1
  105. package/dist/lib/stats/index.d.ts +2 -0
  106. package/dist/lib/stats/index.d.ts.map +1 -0
  107. package/dist/lib/stats/sampler.d.ts +66 -0
  108. package/dist/lib/stats/sampler.d.ts.map +1 -0
  109. package/dist/lib/stats/stats-renderer.d.ts +16 -0
  110. package/dist/lib/stats/stats-renderer.d.ts.map +1 -0
  111. package/dist/style.css +1 -0
  112. package/dist/style.d.ts +4 -0
  113. package/dist/tweak-ui.module.js +2938 -2393
  114. package/dist/tweak-ui.module.js.map +1 -1
  115. package/dist/tweak-ui.umd.js +33 -4420
  116. package/dist/tweak-ui.umd.js.map +1 -1
  117. package/package.json +37 -51
  118. package/dist/index.html +0 -1063
  119. package/dist/lib/color-formats/array-format.d.ts +0 -9
  120. package/dist/lib/color-formats/array-format.d.ts.map +0 -1
  121. package/dist/lib/color-formats/array-format.spec.d.ts +0 -2
  122. package/dist/lib/color-formats/array-format.spec.d.ts.map +0 -1
  123. package/dist/lib/color-formats/converter.d.ts.map +0 -1
  124. package/dist/lib/color-formats/converter.spec.d.ts +0 -2
  125. package/dist/lib/color-formats/converter.spec.d.ts.map +0 -1
  126. package/dist/lib/color-formats/css-string-format.d.ts +0 -8
  127. package/dist/lib/color-formats/css-string-format.d.ts.map +0 -1
  128. package/dist/lib/color-formats/css-string-format.spec.d.ts +0 -2
  129. package/dist/lib/color-formats/css-string-format.spec.d.ts.map +0 -1
  130. package/dist/lib/color-formats/formatter.d.ts +0 -9
  131. package/dist/lib/color-formats/formatter.d.ts.map +0 -1
  132. package/dist/lib/color-formats/formatter.spec.d.ts +0 -2
  133. package/dist/lib/color-formats/formatter.spec.d.ts.map +0 -1
  134. package/dist/lib/color-formats/hex-string-format.d.ts +0 -8
  135. package/dist/lib/color-formats/hex-string-format.d.ts.map +0 -1
  136. package/dist/lib/color-formats/hex-string-format.spec.d.ts +0 -2
  137. package/dist/lib/color-formats/hex-string-format.spec.d.ts.map +0 -1
  138. package/dist/lib/color-formats/index.d.ts.map +0 -1
  139. package/dist/lib/color-formats/number-format.d.ts +0 -9
  140. package/dist/lib/color-formats/number-format.d.ts.map +0 -1
  141. package/dist/lib/color-formats/number-format.spec.d.ts +0 -2
  142. package/dist/lib/color-formats/number-format.spec.d.ts.map +0 -1
  143. package/dist/lib/color-formats/object-format.d.ts.map +0 -1
  144. package/dist/lib/color-formats/object-format.spec.d.ts +0 -2
  145. package/dist/lib/color-formats/object-format.spec.d.ts.map +0 -1
  146. package/dist/lib/color-formats/types.d.ts.map +0 -1
  147. package/dist/lib/components/button.d.ts +0 -29
  148. package/dist/lib/components/button.d.ts.map +0 -1
  149. package/dist/lib/components/content.d.ts +0 -22
  150. package/dist/lib/components/content.d.ts.map +0 -1
  151. package/dist/lib/components/controls/checkbox.d.ts +0 -29
  152. package/dist/lib/components/controls/checkbox.d.ts.map +0 -1
  153. package/dist/lib/components/controls/number.d.ts +0 -48
  154. package/dist/lib/components/controls/number.d.ts.map +0 -1
  155. package/dist/lib/components/controls/position.d.ts +0 -56
  156. package/dist/lib/components/controls/position.d.ts.map +0 -1
  157. package/dist/lib/components/controls/text.d.ts +0 -36
  158. package/dist/lib/components/controls/text.d.ts.map +0 -1
  159. package/dist/lib/components/groups/accordion.d.ts +0 -22
  160. package/dist/lib/components/groups/accordion.d.ts.map +0 -1
  161. package/dist/lib/components/groups/container.d.ts +0 -25
  162. package/dist/lib/components/groups/container.d.ts.map +0 -1
  163. package/dist/lib/components/groups/group.d.ts +0 -49
  164. package/dist/lib/components/groups/group.d.ts.map +0 -1
  165. package/dist/lib/components/groups/index.d.ts +0 -5
  166. package/dist/lib/components/groups/index.d.ts.map +0 -1
  167. package/dist/lib/components/groups/tabs.d.ts +0 -22
  168. package/dist/lib/components/groups/tabs.d.ts.map +0 -1
  169. package/dist/lib/components/image.d.ts +0 -37
  170. package/dist/lib/components/image.d.ts.map +0 -1
  171. package/dist/lib/core/registry.d.ts +0 -18
  172. package/dist/lib/core/registry.d.ts.map +0 -1
  173. package/dist/lib/core/value-accessor.d.ts +0 -18
  174. package/dist/lib/core/value-accessor.d.ts.map +0 -1
  175. package/dist/scss/_style.scss +0 -120
  176. package/dist/scss/_themes.scss +0 -23
  177. package/dist/scss/_utils.scss +0 -24
  178. package/dist/scss/_variables.scss +0 -30
  179. package/dist/scss/controls/_angle.scss +0 -64
  180. package/dist/scss/controls/_button.scss +0 -0
  181. package/dist/scss/controls/_checkbox.scss +0 -19
  182. package/dist/scss/controls/_color-picker.scss +0 -124
  183. package/dist/scss/controls/_color.scss +0 -14
  184. package/dist/scss/controls/_container.scss +0 -13
  185. package/dist/scss/controls/_group.scss +0 -69
  186. package/dist/scss/controls/_image.scss +0 -27
  187. package/dist/scss/controls/_number.scss +0 -38
  188. package/dist/scss/controls/_point.scss +0 -36
  189. package/dist/scss/controls/_position.scss +0 -9
  190. package/dist/scss/controls/_select.scss +0 -0
  191. package/dist/scss/controls/_spherical.scss +0 -87
  192. package/dist/scss/controls/_tabs.scss +0 -38
  193. package/dist/scss/controls/_text.scss +0 -0
  194. package/dist/scss/index.scss +0 -21
  195. package/dist/tweak-ui.css +0 -653
  196. package/dist/tweak-ui.css.map +0 -1
  197. package/dist/tweak-ui.min.css +0 -1
  198. package/dist/tweak-ui.min.css.map +0 -1
  199. package/dist/tweak-ui.umd.min.js +0 -17
  200. package/dist/tweak-ui.umd.min.js.map +0 -1
@@ -1,4420 +1,33 @@
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 getTouchPoint(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 getTouchInTarget(e, target, offset) {
2225
- target = target || e.target;
2226
- var rect = target.getBoundingClientRect();
2227
- var tx = window.pageXOffset || document.documentElement.scrollLeft;
2228
- var ty = window.pageYOffset || document.documentElement.scrollTop;
2229
- var cw = target.clientWidth;
2230
- var ch = target.clientHeight;
2231
- var _a = getTouchPoint(e), cx = _a[0], cy = _a[1];
2232
- if (offset) {
2233
- cx += offset[0];
2234
- cy += offset[1];
2235
- }
2236
- var x = cx - tx - rect.left;
2237
- var y = cy - ty - rect.top;
2238
- return {
2239
- width: cw,
2240
- height: ch,
2241
- x: x,
2242
- y: y,
2243
- normalizedX: x / cw,
2244
- normalizedY: y / ch,
2245
- };
2246
- }
2247
- /**
2248
- * @internal
2249
- */
2250
- function viewFn(fn) {
2251
- return function (node) {
2252
- return use(node.attrs.data, function (data) { return fn(data, node); });
2253
- };
2254
- }
2255
- function dragUtil(_a) {
2256
- var onStart = _a.onStart, onMove = _a.onMove, onEnd = _a.onEnd;
2257
- var util = {
2258
- target: null,
2259
- activate: function (e) {
2260
- util.deactivate();
2261
- util.target = e.target;
2262
- if (onStart) {
2263
- onStart(e);
2264
- }
2265
- if (onMove) {
2266
- document.addEventListener('mousemove', onMove, { passive: false });
2267
- document.addEventListener('touchmove', onMove, { passive: false });
2268
- }
2269
- if (onEnd) {
2270
- document.addEventListener('mouseup', onEnd);
2271
- document.addEventListener('touchend', onEnd);
2272
- document.addEventListener('touchcancel', onEnd);
2273
- }
2274
- },
2275
- deactivate: function () {
2276
- util.target = null;
2277
- if (onMove) {
2278
- document.removeEventListener('mousemove', onMove);
2279
- document.removeEventListener('touchmove', onMove);
2280
- }
2281
- if (onEnd) {
2282
- document.removeEventListener('mouseup', onEnd);
2283
- document.removeEventListener('touchend', onEnd);
2284
- document.removeEventListener('touchcancel', onEnd);
2285
- }
2286
- },
2287
- onStart: onStart,
2288
- onMove: onMove,
2289
- onEnd: onEnd,
2290
- };
2291
- return util;
2292
- }
2293
-
2294
- var TYPE$8 = 'angle';
2295
- var AngleComponent = function (vnode) {
2296
- var angle = 0;
2297
- var dragged = false;
2298
- var pos = [0, 0];
2299
- function toDeg(value) {
2300
- return value * (180 / Math.PI);
2301
- }
2302
- function toRad(value) {
2303
- return value * (Math.PI / 180);
2304
- }
2305
- function toScreen(value) {
2306
- return clamp((value / 2 + 0.5) * 100, 0, 100);
2307
- }
2308
- function fetchValue(node) {
2309
- var _a;
2310
- var data = node.attrs.data;
2311
- angle = (_a = getValue(data)) !== null && _a !== void 0 ? _a : angle;
2312
- if (data.degree) {
2313
- angle = toRad(angle);
2314
- }
2315
- updatePositions();
2316
- }
2317
- function onChange(type) {
2318
- updatePositions();
2319
- var data = vnode.attrs.data;
2320
- var value = data.degree ? toRad(angle) : angle;
2321
- var written = setValue(data, value);
2322
- call(type === 'input' ? data.onInput : data.onChange, data, written);
2323
- }
2324
- function updatePositions() {
2325
- pos[0] = Math.cos(angle);
2326
- pos[1] = Math.sin(angle);
2327
- }
2328
- function onStartPhi(e) {
2329
- dragged = true;
2330
- drag.activate(e);
2331
- }
2332
- var touchOffset;
2333
- var drag = dragUtil({
2334
- onStart: function (e) {
2335
- var touch = getTouchInTarget(e);
2336
- touchOffset = [
2337
- -(touch.x - touch.width / 2),
2338
- -(touch.y - touch.height / 2),
2339
- ];
2340
- drag.onMove(e);
2341
- },
2342
- onMove: function (e) {
2343
- e.preventDefault();
2344
- var position = getTouchInTarget(e, drag.target.parentElement, touchOffset);
2345
- var px = position.normalizedX - 0.5;
2346
- var py = position.normalizedY - 0.5;
2347
- if (dragged) {
2348
- // [-PI;PI]
2349
- angle = Math.atan2(px, py);
2350
- // convert to range [0;2PI]
2351
- angle += angle < 0 ? 2 * Math.PI : 0;
2352
- }
2353
- onChange('input');
2354
- mithril.redraw();
2355
- },
2356
- onEnd: function (e) {
2357
- drag.deactivate();
2358
- dragged = false;
2359
- onChange('change');
2360
- mithril.redraw();
2361
- },
2362
- });
2363
- function onPhiInput(model, value) {
2364
- angle = toRad(value);
2365
- onChange('input');
2366
- }
2367
- function onPhiChange(model, value) {
2368
- angle = toRad(value);
2369
- onChange('change');
2370
- }
2371
- return {
2372
- onremove: function () {
2373
- drag.deactivate();
2374
- },
2375
- oninit: function (node) {
2376
- fetchValue(node);
2377
- },
2378
- onupdate: function (node) {
2379
- fetchValue(node);
2380
- },
2381
- view: function () {
2382
- return mithril('div', {
2383
- class: twuiClass(TYPE$8),
2384
- style: {
2385
- '--angle-value': toDeg(-angle) + 90 + "deg",
2386
- '--angle-percent': (toDeg(angle) / 360) * 100 + "%",
2387
- },
2388
- }, mithril('div.left-container', mithril('div.pane', {
2389
- style: {
2390
- position: 'relative',
2391
- width: '100%',
2392
- 'padding-top': '100%',
2393
- },
2394
- }, mithril('div.angle-pane', {
2395
- class: cssClass({
2396
- 'is-dragging': dragged,
2397
- }),
2398
- style: {
2399
- position: 'absolute',
2400
- top: '0.5rem',
2401
- left: '0.5rem',
2402
- width: 'calc(100% - 1rem)',
2403
- height: 'calc(100% - 1rem)',
2404
- },
2405
- }, mithril('div.angle-knob', {
2406
- onmousedown: onStartPhi,
2407
- ontouchstart: onStartPhi,
2408
- style: {
2409
- position: 'absolute',
2410
- width: '15px',
2411
- height: '15px',
2412
- top: "calc(" + toScreen(pos[0]) + "% - 7px)",
2413
- left: "calc(" + toScreen(pos[1]) + "% - 7px)",
2414
- },
2415
- })))), mithril('div.right-container', mithril('label', mithril.trust('&alpha;')), renderModel({
2416
- type: 'number',
2417
- min: 0,
2418
- max: 360,
2419
- step: 0.1,
2420
- value: toDeg(angle),
2421
- onInput: onPhiInput,
2422
- onChange: onPhiChange,
2423
- })));
2424
- },
2425
- };
2426
- };
2427
- component(TYPE$8, AngleComponent);
2428
- function angleCodec(_a) {
2429
- var _b = _a === void 0 ? {} : _a, axes = _b.axes, length = _b.length, result = _b.result;
2430
- axes = axes || { x: 'right', y: 'up' };
2431
- var keys = Object.keys(axes);
2432
- var radius = function () {
2433
- return (typeof length === 'function' ? length() : length) || 1;
2434
- };
2435
- return {
2436
- decode: function (value) {
2437
- var x = 0;
2438
- var y = 0;
2439
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
2440
- var key = keys_1[_i];
2441
- switch (axes[key]) {
2442
- case 'right':
2443
- y = value[key];
2444
- break;
2445
- case 'left':
2446
- y = -value[key];
2447
- break;
2448
- case 'up':
2449
- case 'front':
2450
- x = -value[key];
2451
- break;
2452
- case 'down':
2453
- case 'back':
2454
- x = value[key];
2455
- }
2456
- }
2457
- var r = radius();
2458
- x /= r;
2459
- y /= r;
2460
- return Math.atan2(y, x) || 0;
2461
- },
2462
- encode: function (angle) {
2463
- var r = radius();
2464
- var x = r * Math.cos(angle);
2465
- var y = r * Math.sin(angle);
2466
- var value = result() || {};
2467
- for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
2468
- var key = keys_2[_i];
2469
- switch (axes[key]) {
2470
- case 'right':
2471
- value[key] = y;
2472
- break;
2473
- case 'left':
2474
- value[key] = -y;
2475
- break;
2476
- case 'up':
2477
- case 'front':
2478
- value[key] = -x;
2479
- break;
2480
- case 'down':
2481
- case 'back':
2482
- value[key] = x;
2483
- break;
2484
- }
2485
- }
2486
- return value;
2487
- },
2488
- };
2489
- }
2490
-
2491
- var TYPE$7 = 'checkbox';
2492
- var CheckboxComponent = function (node) {
2493
- function onChange(e) {
2494
- var data = node.attrs.data;
2495
- var checked = e.target.checked;
2496
- var written = setValue(data, checked);
2497
- call(data.onChange, data, written);
2498
- }
2499
- return {
2500
- view: viewFn(function (data) {
2501
- var _a;
2502
- var checked = getValue(data) === true;
2503
- return mithril('label', {
2504
- class: cssClass((_a = {},
2505
- _a[twuiClass(TYPE$7)] = true,
2506
- _a.checked = checked,
2507
- _a.disabled = data.disabled,
2508
- _a)),
2509
- }, mithril('input', {
2510
- type: 'checkbox',
2511
- checked: checked,
2512
- onchange: onChange,
2513
- disabled: data.disabled,
2514
- }), data.text);
2515
- }),
2516
- };
2517
- };
2518
- component(TYPE$7, CheckboxComponent);
2519
-
2520
- /*! *****************************************************************************
2521
- Copyright (c) Microsoft Corporation.
2522
-
2523
- Permission to use, copy, modify, and/or distribute this software for any
2524
- purpose with or without fee is hereby granted.
2525
-
2526
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2527
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2528
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2529
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2530
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2531
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2532
- PERFORMANCE OF THIS SOFTWARE.
2533
- ***************************************************************************** */
2534
-
2535
- var __assign = function() {
2536
- __assign = Object.assign || function __assign(t) {
2537
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2538
- s = arguments[i];
2539
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2540
- }
2541
- return t;
2542
- };
2543
- return __assign.apply(this, arguments);
2544
- };
2545
-
2546
- /**
2547
- * Converts hsv to rgb
2548
- *
2549
- * @public
2550
- * @param hsv - HSV components where H is in range [0:360] and S and V are in range [0:1]
2551
- * @returns RGB color components in range [0:1]
2552
- */
2553
- function hsv2rgb(hsv) {
2554
- var H = hsv.h % 360;
2555
- var S = clamp(hsv.s, 0, 1);
2556
- var V = clamp(hsv.v, 0, 1);
2557
- var C = V * S;
2558
- var X = C * (1 - Math.abs(((H / 60) % 2) - 1));
2559
- var m = V - C;
2560
- var rgb = { r: 0, g: 0, b: 0 };
2561
- if (H < 60) {
2562
- rgb.r = C;
2563
- rgb.g = X;
2564
- rgb.b = 0;
2565
- }
2566
- else if (H < 120) {
2567
- rgb.r = X;
2568
- rgb.g = C;
2569
- rgb.b = 0;
2570
- }
2571
- else if (H < 180) {
2572
- rgb.r = 0;
2573
- rgb.g = C;
2574
- rgb.b = X;
2575
- }
2576
- else if (H < 240) {
2577
- rgb.r = 0;
2578
- rgb.g = X;
2579
- rgb.b = C;
2580
- }
2581
- else if (H < 300) {
2582
- rgb.r = X;
2583
- rgb.g = 0;
2584
- rgb.b = C;
2585
- }
2586
- else {
2587
- rgb.r = C;
2588
- rgb.g = 0;
2589
- rgb.b = X;
2590
- }
2591
- rgb.r += m;
2592
- rgb.g += m;
2593
- rgb.b += m;
2594
- return rgb;
2595
- }
2596
- /**
2597
- * Converts rgb to hsv
2598
- *
2599
- * @public
2600
- * @remarks
2601
- * The RGB components are assumed to be in range [0:1].
2602
- * The resulting H component is in range [0:360] and S and V in range [0:1]
2603
- */
2604
- function rgb2hsv(rgb) {
2605
- var r = rgb.r;
2606
- var g = rgb.g;
2607
- var b = rgb.b;
2608
- var V = Math.max(r, g, b);
2609
- var d = V - Math.min(r, g, b);
2610
- var S = 0;
2611
- var H = 0;
2612
- if (d !== 0) {
2613
- S = d / V;
2614
- if (V === r) {
2615
- H = (g - b) / d + (g < b ? 6 : 0);
2616
- H = (H % 6) * 60;
2617
- }
2618
- else if (V === g) {
2619
- H = (b - r) / d + 2;
2620
- H = H * 60;
2621
- }
2622
- else {
2623
- H = (r - g) / d + 4;
2624
- H = H * 60;
2625
- }
2626
- }
2627
- return { h: H, s: S, v: V };
2628
- }
2629
-
2630
- var ArrayColorFormat = /** @class */ (function () {
2631
- function ArrayColorFormat(components, normalized) {
2632
- this.components = components;
2633
- this.normalized = normalized;
2634
- }
2635
- ArrayColorFormat.prototype.parse = function (v) {
2636
- var _this = this;
2637
- v = v || [];
2638
- var result = { r: 0, g: 0, b: 0, a: 1 };
2639
- this.components.forEach(function (key, i) {
2640
- result[key] = (v[i] || 0) / (_this.normalized ? 1 : 255);
2641
- });
2642
- return result;
2643
- };
2644
- ArrayColorFormat.prototype.format = function (rgba) {
2645
- var _this = this;
2646
- return this.components.map(function (key) { return (_this.normalized ? rgba[key] : Math.round(rgba[key] * 255)) || 0; });
2647
- };
2648
- return ArrayColorFormat;
2649
- }());
2650
-
2651
- var CssStringFormat = /** @class */ (function () {
2652
- function CssStringFormat(components) {
2653
- this.components = components;
2654
- }
2655
- CssStringFormat.prototype.parse = function (value) {
2656
- value = value || 'rgba(0, 0, 0)';
2657
- var result = { r: 0, g: 0, b: 0, a: 1 };
2658
- var values = value
2659
- .replace(/[rgba\(\)]/gi, '')
2660
- .split(/,\s*?/gi)
2661
- .map(Number);
2662
- this.components.forEach(function (key, i) {
2663
- result[key] = (values[i] || 0) / (key === 'a' ? 1 : 255);
2664
- });
2665
- return result;
2666
- };
2667
- CssStringFormat.prototype.format = function (rgba) {
2668
- return (this.components.join('') +
2669
- '(' +
2670
- this.components
2671
- .map(function (key) {
2672
- return key === 'a' ? rgba[key] : Math.round(rgba[key] * 255);
2673
- })
2674
- .join(', ') +
2675
- ')');
2676
- };
2677
- return CssStringFormat;
2678
- }());
2679
-
2680
- var HexStringFormat = /** @class */ (function () {
2681
- function HexStringFormat(components) {
2682
- this.components = components;
2683
- }
2684
- HexStringFormat.prototype.parse = function (value) {
2685
- value = value || '#000';
2686
- var result = { r: 0, g: 0, b: 0, a: 1 };
2687
- var v = value.match(/[0-9a-f]+/i)[0];
2688
- if (v.length === this.components.length) {
2689
- v = v
2690
- .split('')
2691
- .map(function (it) { return "" + it + it; })
2692
- .join('');
2693
- }
2694
- this.components.forEach(function (key, i) {
2695
- result[key] = parseInt(v.substr(i * 2, 2), 16) / 255;
2696
- });
2697
- return result;
2698
- };
2699
- HexStringFormat.prototype.format = function (rgba) {
2700
- return ('#' +
2701
- this.components
2702
- .map(function (key) { return padLeft(Math.round(rgba[key] * 255).toString(16), 2, '0'); })
2703
- .join(''));
2704
- };
2705
- return HexStringFormat;
2706
- }());
2707
-
2708
- // tslint:disable:no-bitwise
2709
- var NumberColorFormat = /** @class */ (function () {
2710
- function NumberColorFormat(components) {
2711
- this.components = components;
2712
- this.componentsRev = components.slice().reverse();
2713
- }
2714
- NumberColorFormat.prototype.parse = function (v) {
2715
- v = v || 0;
2716
- var result = { r: 0, g: 0, b: 0, a: 1 };
2717
- this.components.forEach(function (key, i) {
2718
- result[key] = ((v >> (i * 8)) & 255) / 255;
2719
- });
2720
- return result;
2721
- };
2722
- NumberColorFormat.prototype.format = function (rgba) {
2723
- var val = this.componentsRev
2724
- .map(function (key) {
2725
- return padLeft(Math.round(rgba[key] * 255 || 0).toString(16), 2, '0');
2726
- })
2727
- .join('');
2728
- return parseInt('0x' + val, 16);
2729
- };
2730
- return NumberColorFormat;
2731
- }());
2732
-
2733
- var ObjectColorFormat = /** @class */ (function () {
2734
- function ObjectColorFormat(components, normalized) {
2735
- this.components = components;
2736
- this.normalized = normalized;
2737
- }
2738
- ObjectColorFormat.prototype.parse = function (v) {
2739
- var _this = this;
2740
- v = v || {};
2741
- var result = { r: 0, g: 0, b: 0, a: 1 };
2742
- this.components.forEach(function (key, i) {
2743
- result[key] = (v[key] || 0) / (_this.normalized ? 1 : 255);
2744
- });
2745
- return result;
2746
- };
2747
- ObjectColorFormat.prototype.format = function (rgba) {
2748
- var _this = this;
2749
- var result = {};
2750
- this.components.forEach(function (key, i) {
2751
- result[key] =
2752
- (_this.normalized ? rgba[key] : Math.round(rgba[key] * 255)) || 0;
2753
- });
2754
- return result;
2755
- };
2756
- return ObjectColorFormat;
2757
- }());
2758
-
2759
- var formatter = {};
2760
- /**
2761
- * Gets a formatter implementation for the given format
2762
- *
2763
- * @public
2764
- * @param format - The format code
2765
- */
2766
- function getColorFormatter(format) {
2767
- if (format === void 0) { format = 'rgb'; }
2768
- if (format in formatter) {
2769
- return formatter[format];
2770
- }
2771
- var components = (format.match(/[rgba]+/)[0] || '').split('');
2772
- if (/(\[n?\])/.test(format)) {
2773
- formatter[format] = new ArrayColorFormat(components, /\[n\]/.test(format));
2774
- }
2775
- else if (/(\{n?\})/.test(format)) {
2776
- formatter[format] = new ObjectColorFormat(components, /\{n\}/.test(format));
2777
- }
2778
- else if (/0x/.test(format)) {
2779
- formatter[format] = new NumberColorFormat(components);
2780
- }
2781
- else if (/(\(\))/.test(format)) {
2782
- formatter[format] = new CssStringFormat(components);
2783
- }
2784
- else {
2785
- formatter[format] = new HexStringFormat(components);
2786
- }
2787
- return formatter[format];
2788
- }
2789
-
2790
- component('color-picker', function (node) {
2791
- var hue = 0; // range [0,1]
2792
- var sat = 0; // range [0,1]
2793
- var val = 0; // range [0,1]
2794
- var a = 0; // range [0,1]
2795
- function getHSVA(s, v) {
2796
- if (s === void 0) { s = sat; }
2797
- if (v === void 0) { v = val; }
2798
- return {
2799
- h: hue * 360,
2800
- s: s,
2801
- v: v,
2802
- a: a,
2803
- };
2804
- }
2805
- function getRGB(s, v) {
2806
- if (s === void 0) { s = sat; }
2807
- if (v === void 0) { v = val; }
2808
- return hsv2rgb(getHSVA(s, v));
2809
- }
2810
- function getRGBA(s, v, alpha) {
2811
- if (s === void 0) { s = sat; }
2812
- if (v === void 0) { v = val; }
2813
- if (alpha === void 0) { alpha = a; }
2814
- return __assign(__assign({}, getRGB(s, v)), { a: alpha });
2815
- }
2816
- function setHSV(hsv) {
2817
- hue = hsv.h / 360;
2818
- sat = hsv.s;
2819
- val = hsv.v;
2820
- }
2821
- function setHSVA(hsv) {
2822
- setHSV(hsv);
2823
- a = hsv.a;
2824
- }
2825
- function getHexRGB(s, v) {
2826
- return getColorFormatter('#rgb').format(getRGBA(s, v));
2827
- }
2828
- function getHexRGBA(s, v) {
2829
- return getColorFormatter('#rgba').format(getRGBA(s, v));
2830
- }
2831
- function getCssRGBA(s, v, alpha) {
2832
- if (s === void 0) { s = sat; }
2833
- if (v === void 0) { v = val; }
2834
- if (alpha === void 0) { alpha = a; }
2835
- return getColorFormatter('rgba()').format(getRGBA(s, v, alpha));
2836
- }
2837
- function parseInput(value, format) {
2838
- var rgba = getColorFormatter(format || 'rgb').parse(value);
2839
- setHSVA(__assign(__assign({}, rgb2hsv(rgba)), { a: rgba.a }));
2840
- }
2841
- function formatOutput(format) {
2842
- return getColorFormatter(format).format(getRGBA());
2843
- }
2844
- function triggerInput() {
2845
- use(node.attrs.data, function (data) {
2846
- var value = formatOutput(data.format);
2847
- var written = setValue(data, value);
2848
- call(data.onInput, data, written);
2849
- });
2850
- }
2851
- function triggerChange() {
2852
- use(node.attrs.data, function (data) {
2853
- var value = formatOutput(data.format);
2854
- var written = setValue(data, value);
2855
- call(data.onChange, data, written);
2856
- });
2857
- }
2858
- function hasAlpha() {
2859
- return use(node.attrs.data, function (data) {
2860
- return data.format && data.format.match(/a/i);
2861
- });
2862
- }
2863
- //
2864
- // manual input
2865
- //
2866
- function inputR(e) {
2867
- input(e, 'r');
2868
- }
2869
- function inputG(e) {
2870
- input(e, 'g');
2871
- }
2872
- function inputB(e) {
2873
- input(e, 'b');
2874
- }
2875
- function input(e, field) {
2876
- var color = getRGBA();
2877
- color[field] = parseInt(e.target.value, 10) / 255;
2878
- setHSV(rgb2hsv(color));
2879
- triggerInput();
2880
- triggerChange();
2881
- }
2882
- function inputHex(e) {
2883
- parseInput(e.target.value, hasAlpha() ? 'rgba' : 'rgb');
2884
- triggerInput();
2885
- triggerChange();
2886
- }
2887
- //
2888
- // drag input
2889
- //
2890
- var target;
2891
- var kind;
2892
- function beginPickSV(e) {
2893
- kind = 'sv';
2894
- enableDrag(e.target);
2895
- onMouseMove(e);
2896
- }
2897
- function beginPickH(e) {
2898
- kind = 'h';
2899
- enableDrag(e.target);
2900
- onMouseMove(e);
2901
- }
2902
- function beginPickA(e) {
2903
- kind = 'a';
2904
- enableDrag(e.target);
2905
- onMouseMove(e);
2906
- }
2907
- function enableDrag(el) {
2908
- disableDrag();
2909
- target = el;
2910
- var options = { passive: false };
2911
- document.addEventListener('mousemove', onMouseMove, options);
2912
- document.addEventListener('mouseup', onMouseUp, options);
2913
- document.addEventListener('touchmove', onMouseMove, options);
2914
- document.addEventListener('touchend', onMouseUp, options);
2915
- document.addEventListener('touchcancel', onMouseUp, options);
2916
- }
2917
- function disableDrag() {
2918
- document.removeEventListener('mousemove', onMouseMove);
2919
- document.removeEventListener('mouseup', onMouseUp);
2920
- document.removeEventListener('touchmove', onMouseMove);
2921
- document.removeEventListener('touchend', onMouseUp);
2922
- document.removeEventListener('touchcancel', onMouseUp);
2923
- }
2924
- function onMouseMove(e) {
2925
- if (!target) {
2926
- return;
2927
- }
2928
- e.preventDefault();
2929
- var rect = target.getBoundingClientRect();
2930
- var tx = window.pageXOffset || document.documentElement.scrollLeft;
2931
- var ty = window.pageYOffset || document.documentElement.scrollTop;
2932
- var cw = target.clientWidth;
2933
- var ch = target.clientHeight;
2934
- var _a = getTouchPoint(e), cx = _a[0], cy = _a[1];
2935
- cx = clamp((cx - tx - rect.left) / cw, 0, 1);
2936
- cy = clamp((cy - ty - rect.top) / ch, 0, 1);
2937
- if (kind === 'sv') {
2938
- sat = cx;
2939
- val = 1 - cy;
2940
- }
2941
- if (kind === 'h') {
2942
- hue = 1 - cx;
2943
- }
2944
- if (kind === 'a') {
2945
- a = cx;
2946
- }
2947
- triggerInput();
2948
- mithril.redraw();
2949
- }
2950
- function onMouseUp() {
2951
- if (target != null) {
2952
- target = null;
2953
- disableDrag();
2954
- triggerChange();
2955
- }
2956
- }
2957
- return {
2958
- onremove: function () {
2959
- disableDrag();
2960
- },
2961
- oninit: function () {
2962
- use(node.attrs.data, function (data) {
2963
- parseInput(getValue(data), data.format);
2964
- });
2965
- },
2966
- view: function () {
2967
- return use(node.attrs.data, function (data) {
2968
- var rgba = getRGBA();
2969
- return mithril('div', {
2970
- class: twuiClass(data.type),
2971
- }, mithril('.color-picker-inputs', mithril("input.input-hex[type='text']", {
2972
- value: hasAlpha() ? getHexRGBA() : getHexRGB(),
2973
- onchange: inputHex,
2974
- }), mithril("input.input-r[type='number']", {
2975
- min: 0,
2976
- max: 255,
2977
- step: 1,
2978
- value: Math.round(rgba.r * 255),
2979
- onchange: inputR,
2980
- }), mithril("input.input-g[type='number']", {
2981
- min: 0,
2982
- max: 255,
2983
- step: 1,
2984
- value: Math.round(rgba.g * 255),
2985
- onchange: inputG,
2986
- }), mithril("input.input-b[type='number']", {
2987
- min: 0,
2988
- max: 255,
2989
- step: 1,
2990
- value: Math.round(rgba.b * 255),
2991
- onchange: inputB,
2992
- })), mithril('.color-picker-panel', mithril('.color-picker-sv', {
2993
- tabindex: 0,
2994
- onmousedown: beginPickSV,
2995
- ontouchstart: beginPickSV,
2996
- style: {
2997
- 'background-color': "" + getCssRGBA(1, 1, 1),
2998
- 'user-select': 'none',
2999
- },
3000
- }, mithril('.color-picker-sv-bg', {
3001
- style: {
3002
- background: 'linear-gradient(to right,rgba(255,255,255,1),rgba(255,255,255,0))',
3003
- 'user-select': 'none',
3004
- 'pointer-events': 'none',
3005
- },
3006
- }), mithril('.color-picker-sv-bg', {
3007
- style: {
3008
- background: 'linear-gradient(to top,rgba(0,0,0,1),rgba(0,0,0,0))',
3009
- 'user-select': 'none',
3010
- 'pointer-events': 'none',
3011
- },
3012
- }), mithril('.color-picker-sv-cursor', {
3013
- style: {
3014
- 'user-select': 'none',
3015
- 'pointer-events': 'none',
3016
- 'background-color': "" + getCssRGBA(hue, sat, 1),
3017
- left: sat * 100 + "%",
3018
- top: (1 - val) * 100 + "%",
3019
- },
3020
- })), mithril('.color-picker-h', {
3021
- tabindex: 0,
3022
- onmousedown: beginPickH,
3023
- ontouchstart: beginPickH,
3024
- style: {
3025
- 'user-select': 'none',
3026
- background: 'linear-gradient(to right, #f00 0, #f0f 17% , #00f 33% , #0ff 50% , #0f0 67% , #ff0 83% , #f00 100%)',
3027
- },
3028
- }, mithril('.color-picker-h-cursor', {
3029
- style: {
3030
- 'user-select': 'none',
3031
- 'pointer-events': 'none',
3032
- 'background-color': "" + getCssRGBA(1, 1, 1),
3033
- position: 'absolute',
3034
- left: (1 - hue) * 100 + "%",
3035
- },
3036
- })), !hasAlpha()
3037
- ? null
3038
- : mithril('.color-picker-a', {
3039
- tabindex: 0,
3040
- onmousedown: beginPickA,
3041
- ontouchstart: beginPickA,
3042
- style: {
3043
- 'user-select': 'none',
3044
- },
3045
- }, mithril('.color-picker-a-bg', {
3046
- style: {
3047
- background: "linear-gradient(to right, " + getCssRGBA(sat, val, 0) + ", " + getCssRGBA(sat, val, 1) + ")",
3048
- },
3049
- }), mithril('.color-picker-a-cursor', {
3050
- style: {
3051
- 'user-select': 'none',
3052
- 'pointer-events': 'none',
3053
- position: 'absolute',
3054
- left: a * 100 + "%",
3055
- },
3056
- }))));
3057
- });
3058
- },
3059
- };
3060
- });
3061
-
3062
- component('color', function () {
3063
- var data;
3064
- var opened = false;
3065
- var value;
3066
- var rgba;
3067
- var rgbaFromatter = getColorFormatter('rgba()');
3068
- function fetchState(node) {
3069
- data = node.attrs.data;
3070
- value = getValue(data);
3071
- rgba = rgbaFromatter.format(getColorFormatter(data.format).parse(value));
3072
- }
3073
- function toggle() {
3074
- opened = !opened;
3075
- }
3076
- function onPickerInput(p, v) {
3077
- var written = setValue(data, v);
3078
- call(data.onInput, data, written);
3079
- }
3080
- function onPickerChange(p, v) {
3081
- var written = setValue(data, v);
3082
- call(data.onChange, data, written);
3083
- }
3084
- function getText() {
3085
- if (isString(value)) {
3086
- return value;
3087
- }
3088
- if (isNumber(value)) {
3089
- return '0x' + padLeft(value.toString(16), 8, '0');
3090
- }
3091
- if (isArray(value)) {
3092
- return value
3093
- .map(function (it) { return (it < 1 && it > 0 ? it.toFixed(2) : it); })
3094
- .join(' , ');
3095
- }
3096
- if (isObject(value)) {
3097
- return Object.keys(value)
3098
- .map(function (k) {
3099
- var it = value[k];
3100
- return k + ": " + (it < 1 && it > 0 ? it.toFixed(2) : it);
3101
- })
3102
- .join(' ');
3103
- }
3104
- if (value == null) {
3105
- return 'null';
3106
- }
3107
- return '?';
3108
- }
3109
- return {
3110
- oninit: function (node) {
3111
- fetchState(node);
3112
- },
3113
- onupdate: function (node) {
3114
- fetchState(node);
3115
- },
3116
- view: function () {
3117
- var _a;
3118
- return mithril('div', {
3119
- class: cssClass((_a = {},
3120
- _a[twuiClass(data.type)] = true,
3121
- _a[twuiClass(data.type + '-open')] = opened,
3122
- _a)),
3123
- }, mithril("button[type='button']", {
3124
- style: { 'background-color': rgba },
3125
- onclick: toggle,
3126
- }, getText() || '?'), renderModel({
3127
- type: 'color-picker',
3128
- value: value,
3129
- format: data.format,
3130
- onInput: onPickerInput,
3131
- onChange: onPickerChange,
3132
- hidden: !opened,
3133
- }));
3134
- },
3135
- };
3136
- });
3137
-
3138
- var NumberComponent = function () {
3139
- var type;
3140
- var min;
3141
- var max;
3142
- var step;
3143
- var disabled;
3144
- var placeholder;
3145
- var isSlider;
3146
- var value;
3147
- var percent;
3148
- var vnode;
3149
- // let data: NumberModel
3150
- function fetchState(node) {
3151
- vnode = node;
3152
- var data = node.attrs.data;
3153
- type = data.type;
3154
- isSlider = data.type === 'slider';
3155
- min = isSlider && data.min == null ? 0 : data.min;
3156
- max = isSlider && data.max == null ? 1 : data.max;
3157
- step = data.step;
3158
- value = getValue(data);
3159
- disabled = data.disabled;
3160
- percent = isSlider ? ((value - min) / (max - min)) * 100 : 0;
3161
- }
3162
- function setModelValue(e, v) {
3163
- v = value = clamp(isNaN(v) ? null : v, min, max);
3164
- var data = vnode.attrs.data;
3165
- var written = setValue(data, v);
3166
- call(e === 'input' ? data.onInput : data.onChange, data, written);
3167
- mithril.redraw();
3168
- }
3169
- function onInput(e) {
3170
- var el = e.target;
3171
- setModelValue('input', parseFloat(el.value));
3172
- }
3173
- function onChange(e) {
3174
- var el = e.target;
3175
- setModelValue('change', parseFloat(el.value));
3176
- }
3177
- function limit(v) {
3178
- v = clamp(v, min, max);
3179
- if (step != null) {
3180
- v = Math.round(v / step) * step;
3181
- }
3182
- return parseFloat(v.toFixed(5));
3183
- }
3184
- var drag = dragUtil({
3185
- onStart: function (e) {
3186
- drag.onMove(e);
3187
- },
3188
- onMove: function (e) {
3189
- e.preventDefault();
3190
- var s = getTouchInTarget(e, drag.target).normalizedX;
3191
- setModelValue('input', limit(min + s * (max - min)));
3192
- },
3193
- onEnd: function () {
3194
- setModelValue('change', value);
3195
- drag.deactivate();
3196
- },
3197
- });
3198
- function onDragStart(e) {
3199
- if (!disabled) {
3200
- drag.activate(e);
3201
- }
3202
- }
3203
- function onKeydown(e) {
3204
- var code = e.key || e.keyCode;
3205
- var dir = code === 'ArrowLeft' ? -1 : code === 'ArrowRight' ? 1 : 0;
3206
- var add = (step || 1) * dir;
3207
- if (add) {
3208
- setModelValue('change', limit((value || 0) + add));
3209
- }
3210
- }
3211
- function onWheel(e) {
3212
- e.preventDefault();
3213
- var dir = (e.ctrlKey ? 0.5 : 1) * clamp(e.deltaY, -1, 1);
3214
- var add = (step || 0.2) * dir;
3215
- if (add) {
3216
- setModelValue('change', limit((value || 0) - add));
3217
- }
3218
- }
3219
- function onFocus() {
3220
- }
3221
- function onBlur() {
3222
- }
3223
- function slider() {
3224
- return mithril('.twui-progress', __assign({ style: 'user-select: none;', class: cssClass({
3225
- disabled: !!disabled,
3226
- }) }, (disabled
3227
- ? {}
3228
- : {
3229
- tabindex: 0,
3230
- onmousedown: onDragStart,
3231
- ontouchstart: onDragStart,
3232
- onkeydown: onKeydown,
3233
- onwheel: onWheel,
3234
- })), mithril('.twui-progress-bar', {
3235
- style: {
3236
- width: percent + "%",
3237
- 'pointer-events': 'none',
3238
- 'user-select': 'none',
3239
- },
3240
- }));
3241
- }
3242
- return {
3243
- onremove: function () {
3244
- drag.deactivate();
3245
- },
3246
- oninit: function (node) {
3247
- fetchState(node);
3248
- },
3249
- onupdate: function (node) {
3250
- fetchState(node);
3251
- },
3252
- view: function () {
3253
- return mithril('div', {
3254
- class: twuiClass(type),
3255
- }, isSlider ? slider() : null, mithril("input[type='number']", {
3256
- min: min,
3257
- max: max,
3258
- step: step,
3259
- value: value,
3260
- oninput: onInput,
3261
- onchange: onChange,
3262
- onwheel: onWheel,
3263
- onfocus: onFocus,
3264
- onblur: onBlur,
3265
- placeholder: placeholder,
3266
- disabled: disabled,
3267
- }));
3268
- },
3269
- };
3270
- };
3271
- component('number', NumberComponent);
3272
- component('slider', NumberComponent);
3273
-
3274
- var TYPE$6 = 'point';
3275
- var DEFAULT_RANGE = [0, 1];
3276
- var DEFAULT_KEYS = ['x', 'y'];
3277
- component(TYPE$6, function (vnode) {
3278
- var kx;
3279
- var ky;
3280
- var xRange = DEFAULT_RANGE;
3281
- var yRange = DEFAULT_RANGE;
3282
- var vx = 0;
3283
- var vy = 0;
3284
- var x = 0;
3285
- var y = 0;
3286
- var rx;
3287
- var ry;
3288
- var snap;
3289
- function fetchValue(node) {
3290
- var _a;
3291
- var _b;
3292
- var data = node.attrs.data;
3293
- var keys = data.keys || DEFAULT_KEYS;
3294
- kx = keys[0];
3295
- ky = keys[1];
3296
- var value = (_b = getValue(data)) !== null && _b !== void 0 ? _b : (_a = {},
3297
- _a[kx] = vx,
3298
- _a[ky] = vy,
3299
- _a);
3300
- snap = data.snap;
3301
- vx = value[kx] || 0;
3302
- vy = value[ky] || 0;
3303
- xRange = data.xRange || xRange;
3304
- yRange = data.yRange || yRange;
3305
- x = (vx - xRange[0]) / (xRange[1] - xRange[0]);
3306
- y = (vy - yRange[0]) / (yRange[1] - yRange[0]);
3307
- var reset = data.reset;
3308
- if (reset) {
3309
- rx = (reset[0] - xRange[0]) / (xRange[1] - xRange[0]);
3310
- ry = (reset[1] - yRange[0]) / (yRange[1] - yRange[0]);
3311
- }
3312
- }
3313
- function updateValue() {
3314
- vx = xRange[0] + (xRange[1] - xRange[0]) * x;
3315
- vy = yRange[0] + (yRange[1] - yRange[0]) * y;
3316
- if (snap > 0) {
3317
- vx = Math.floor(vx / snap) * snap;
3318
- vy = Math.floor(vy / snap) * snap;
3319
- x = (vx - xRange[0]) / (xRange[1] - xRange[0]);
3320
- y = (vy - yRange[0]) / (yRange[1] - yRange[0]);
3321
- }
3322
- }
3323
- function onChange(type) {
3324
- var _a;
3325
- var _b;
3326
- updateValue();
3327
- var data = vnode.attrs.data;
3328
- var value = (_b = getValue(data)) !== null && _b !== void 0 ? _b : (_a = {},
3329
- _a[kx] = vx,
3330
- _a[ky] = vy,
3331
- _a);
3332
- value[kx] = vx;
3333
- value[ky] = vy;
3334
- call(type === 'input' ? data.onInput : data.onChange, data, value);
3335
- }
3336
- function onMouseDown(e) {
3337
- drag.activate(e);
3338
- }
3339
- var drag = dragUtil({
3340
- onMove: function (e) {
3341
- e.preventDefault();
3342
- var target = drag.target;
3343
- var rect = target.getBoundingClientRect();
3344
- var tx = window.pageXOffset || document.documentElement.scrollLeft;
3345
- var ty = window.pageYOffset || document.documentElement.scrollTop;
3346
- var cw = target.clientWidth;
3347
- var ch = target.clientHeight;
3348
- var _a = getTouchPoint(e), cx = _a[0], cy = _a[1];
3349
- x = clamp((cx - tx - rect.left) / cw, 0, 1);
3350
- y = clamp((cy - ty - rect.top) / ch, 0, 1);
3351
- onChange('input');
3352
- mithril.redraw();
3353
- },
3354
- onEnd: function () {
3355
- drag.deactivate();
3356
- if (rx != null && ry != null) {
3357
- x = rx;
3358
- y = ry;
3359
- onChange('input');
3360
- }
3361
- onChange('change');
3362
- mithril.redraw();
3363
- },
3364
- });
3365
- return {
3366
- onremove: drag.deactivate,
3367
- oninit: fetchValue,
3368
- onupdate: fetchValue,
3369
- view: function () {
3370
- return mithril('div', {
3371
- class: twuiClass(TYPE$6),
3372
- tabindex: 0,
3373
- onmousedown: onMouseDown,
3374
- ontouchstart: onMouseDown,
3375
- }, mithril('.point-x-axis', {
3376
- style: {
3377
- 'pointer-events': 'none',
3378
- position: 'absolute',
3379
- left: 0,
3380
- right: 0,
3381
- top: y * 100 + "%",
3382
- height: "1px",
3383
- },
3384
- }), mithril('.point-y-axis', {
3385
- style: {
3386
- 'pointer-events': 'none',
3387
- position: 'absolute',
3388
- left: x * 100 + "%",
3389
- top: 0,
3390
- bottom: 0,
3391
- width: "1px",
3392
- },
3393
- }), mithril('.point-cursor', {
3394
- style: {
3395
- 'pointer-events': 'none',
3396
- left: x * 100 + "%",
3397
- top: y * 100 + "%",
3398
- position: 'absolute',
3399
- width: '11px',
3400
- height: '11px',
3401
- 'margin-top': '-5px',
3402
- 'margin-left': '-5px',
3403
- border: '1px solid white',
3404
- 'border-radius': '5px',
3405
- 'box-shadow': '0px 0px 2px 1px rgba(0, 0, 0, 0.75)',
3406
- },
3407
- }));
3408
- },
3409
- };
3410
- });
3411
-
3412
- var TYPE$5 = 'position';
3413
- var defaultKeys = ['x', 'y', 'z'];
3414
- component(TYPE$5, function (node) {
3415
- function onChange(type, field, v) {
3416
- var data = node.attrs.data;
3417
- var value = getValue(data) || {};
3418
- value[field] = isNaN(v) ? null : v;
3419
- var written = setValue(data, value);
3420
- call(type === 'input' ? data.onInput : data.onChange, data, written, field);
3421
- }
3422
- return {
3423
- view: viewFn(function (data) {
3424
- var keys = data.keys || defaultKeys;
3425
- var value = getValue(data);
3426
- return mithril('div', {
3427
- class: twuiClass(TYPE$5),
3428
- }, keys.map(function (field) {
3429
- return renderModel({
3430
- type: 'number',
3431
- min: data.min,
3432
- max: data.max,
3433
- step: data.step,
3434
- value: value === null || value === void 0 ? void 0 : value[field],
3435
- disabled: data.disabled,
3436
- onInput: function (_, v) { return onChange('input', field, v); },
3437
- onChange: function (_, v) { return onChange('change', field, v); },
3438
- placeholder: field,
3439
- });
3440
- }));
3441
- }),
3442
- };
3443
- });
3444
-
3445
- var emptyArray = [];
3446
- function optionsFromFlatArray(arr) {
3447
- var res = [];
3448
- for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
3449
- var it_1 = arr_1[_i];
3450
- if (isString(it_1) || isNumber(it_1)) {
3451
- res.push({ value: it_1, label: String(it_1) });
3452
- continue;
3453
- }
3454
- if ('value' in it_1) {
3455
- res.push(it_1);
3456
- continue;
3457
- }
3458
- }
3459
- return res;
3460
- }
3461
- function optionsFromArray(arr) {
3462
- var res = [];
3463
- for (var _i = 0, arr_2 = arr; _i < arr_2.length; _i++) {
3464
- var it_2 = arr_2[_i];
3465
- if (isString(it_2) || isNumber(it_2) || it_2 == null) {
3466
- res.push({ value: it_2, label: String(it_2) });
3467
- }
3468
- else if ('value' in it_2) {
3469
- res.push(it_2);
3470
- }
3471
- else if ('options' in it_2) {
3472
- res.push({
3473
- label: it_2.label,
3474
- disabled: it_2.disabled,
3475
- options: Array.isArray(it_2.options)
3476
- ? optionsFromFlatArray(it_2.options)
3477
- : optionsFromObject(it_2.options),
3478
- });
3479
- }
3480
- }
3481
- return res;
3482
- }
3483
- function optionsFromObject(obj) {
3484
- return Object.keys(obj)
3485
- .sort()
3486
- .map(function (key) { return ({ value: obj[key], label: key }); });
3487
- }
3488
- function getOptions(node) {
3489
- var options = node.attrs.data.options;
3490
- if (!options) {
3491
- return emptyArray;
3492
- }
3493
- if (Array.isArray(options)) {
3494
- return optionsFromArray(options);
3495
- }
3496
- return optionsFromObject(options);
3497
- }
3498
- component('select', function (node) {
3499
- var options;
3500
- function getSelectedIndex() {
3501
- var data = node.attrs.data;
3502
- var value = getValue(data);
3503
- var i = 0;
3504
- for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
3505
- var o0 = options_1[_i];
3506
- if ('options' in o0) {
3507
- for (var _a = 0, _b = o0.options; _a < _b.length; _a++) {
3508
- var o1 = _b[_a];
3509
- if (o1.value === value) {
3510
- return i;
3511
- }
3512
- i++;
3513
- }
3514
- }
3515
- else {
3516
- if (o0.value === value) {
3517
- return i;
3518
- }
3519
- i++;
3520
- }
3521
- }
3522
- }
3523
- function getSelectionAt(index) {
3524
- var i = 0;
3525
- for (var _i = 0, options_2 = options; _i < options_2.length; _i++) {
3526
- var o0 = options_2[_i];
3527
- if ('options' in o0) {
3528
- for (var _a = 0, _b = o0.options; _a < _b.length; _a++) {
3529
- var o1 = _b[_a];
3530
- if (i === index) {
3531
- return o1.value;
3532
- }
3533
- i += 1;
3534
- }
3535
- }
3536
- else {
3537
- if (i === index) {
3538
- return o0.value;
3539
- }
3540
- i += 1;
3541
- }
3542
- }
3543
- return null;
3544
- }
3545
- function onChange(e) {
3546
- var el = e.target;
3547
- var data = node.attrs.data;
3548
- var value = getSelectionAt(el.selectedIndex);
3549
- var written = setValue(data, value);
3550
- call(data.onChange, data, written);
3551
- }
3552
- return {
3553
- view: viewFn(function (data) {
3554
- options = getOptions(node);
3555
- return mithril('select', {
3556
- class: twuiClass(data.type),
3557
- selectedIndex: getSelectedIndex(),
3558
- onchange: onChange,
3559
- disabled: data.disabled,
3560
- }, options.map(function (it) {
3561
- if ('options' in it) {
3562
- return mithril('optgroup', {
3563
- disabled: !!it.disabled,
3564
- label: it.label || '',
3565
- }, it.options.map(option));
3566
- }
3567
- return option(it);
3568
- }));
3569
- }),
3570
- };
3571
- });
3572
- function option(it) {
3573
- return mithril('option', {
3574
- value: it.value,
3575
- label: it.label,
3576
- disabled: !!it.disabled,
3577
- }, it.label || '');
3578
- }
3579
-
3580
- var TYPE$4 = 'spherical';
3581
- var KEYS = ['phi', 'theta'];
3582
- var SphericalComponent = function (vnode) {
3583
- var phi = 0; // azimuth [0, 2PI]
3584
- var theta = 0; // inclination [0, PI]
3585
- var backface = false;
3586
- var v2Phi = [0, 0];
3587
- var v2Theta = [0, 0];
3588
- var draggedKnob;
3589
- function toDeg(value) {
3590
- return value * (180 / Math.PI);
3591
- }
3592
- function toRad(value) {
3593
- return value * (Math.PI / 180);
3594
- }
3595
- function toScreen(value) {
3596
- return clamp((value / 2 + 0.5) * 100, 0, 100);
3597
- }
3598
- function read(node) {
3599
- var data = node.attrs.data;
3600
- var value = getValue(data) || {
3601
- phi: data.degree ? toDeg(phi) : phi,
3602
- theta: data.degree ? toDeg(theta) : theta,
3603
- };
3604
- var _a = data.keys || KEYS, kPhi = _a[0], kTheta = _a[1];
3605
- return { data: data, value: value, kPhi: kPhi, kTheta: kTheta };
3606
- }
3607
- function fetchValue(node) {
3608
- var _a = read(node), data = _a.data, value = _a.value, kPhi = _a.kPhi, kTheta = _a.kTheta;
3609
- phi = value[kPhi] || 0;
3610
- theta = value[kTheta] || 0;
3611
- if (data.degree) {
3612
- phi = toRad(phi);
3613
- theta = toRad(theta);
3614
- }
3615
- while (theta < 0) {
3616
- theta += Math.PI;
3617
- }
3618
- while (theta > Math.PI) {
3619
- theta -= Math.PI;
3620
- }
3621
- backface = theta > Math.PI / 2;
3622
- updatePositions();
3623
- }
3624
- function onChange(type) {
3625
- updatePositions();
3626
- var _a = read(vnode), data = _a.data, value = _a.value, kPhi = _a.kPhi, kTheta = _a.kTheta;
3627
- value[kPhi] = data.degree ? toDeg(phi) : phi;
3628
- value[kTheta] = data.degree ? toDeg(theta) : theta;
3629
- var written = setValue(data, value);
3630
- call(type === 'input' ? data.onInput : data.onChange, data, written);
3631
- }
3632
- function updatePositions() {
3633
- v2Phi[0] = Math.cos(phi);
3634
- v2Phi[1] = Math.sin(phi);
3635
- v2Theta[0] = Math.sin(theta) * Math.cos(phi);
3636
- v2Theta[1] = Math.sin(theta) * Math.sin(phi);
3637
- }
3638
- function onStartPhi(e) {
3639
- draggedKnob = 'phi';
3640
- drag.activate(e);
3641
- }
3642
- function onStartTheta(e) {
3643
- draggedKnob = 'theta';
3644
- drag.activate(e);
3645
- }
3646
- var touchOffset;
3647
- var drag = dragUtil({
3648
- onStart: function (e) {
3649
- var touch = getTouchInTarget(e);
3650
- touchOffset = [
3651
- -(touch.x - touch.width / 2),
3652
- -(touch.y - touch.height / 2),
3653
- ];
3654
- drag.onMove(e);
3655
- },
3656
- onMove: function (e) {
3657
- e.preventDefault();
3658
- var position = getTouchInTarget(e, drag.target.parentElement, touchOffset);
3659
- var px = position.normalizedX - 0.5;
3660
- var py = position.normalizedY - 0.5;
3661
- if (draggedKnob === 'phi') {
3662
- // [-PI;PI]
3663
- phi = Math.atan2(px, py);
3664
- // convert to range [0;2PI]
3665
- phi += phi < 0 ? 2 * Math.PI : 0;
3666
- }
3667
- else if (draggedKnob === 'theta') {
3668
- // closest point on segment
3669
- // p0: [0, 0], p1: vPhi
3670
- var ab = v2Phi;
3671
- var ac = [py, px];
3672
- var t = (ab[0] * ac[0] + ab[1] * ac[1]) / Math.sqrt(ab[0] * ab[0] + ab[1] * ab[1]);
3673
- theta = Math.PI * clamp(t, 0, 0.5);
3674
- if (backface) {
3675
- theta = Math.PI - theta;
3676
- }
3677
- }
3678
- onChange('input');
3679
- mithril.redraw();
3680
- },
3681
- onEnd: function (e) {
3682
- drag.deactivate();
3683
- draggedKnob = null;
3684
- onChange('change');
3685
- mithril.redraw();
3686
- },
3687
- });
3688
- function onPhiInput(model, value) {
3689
- phi = toRad(value);
3690
- onChange('input');
3691
- }
3692
- function onPhiChange(model, value) {
3693
- phi = toRad(value);
3694
- onChange('change');
3695
- }
3696
- function onThetaInput(model, value) {
3697
- theta = toRad(value);
3698
- onChange('input');
3699
- }
3700
- function onThetaChange(model, value) {
3701
- theta = toRad(value);
3702
- onChange('change');
3703
- }
3704
- function onBackfaceChange(model, value) {
3705
- backface = value;
3706
- theta = Math.PI - theta;
3707
- onChange('change');
3708
- setTimeout(function () { return mithril.redraw(); });
3709
- }
3710
- return {
3711
- onremove: function () {
3712
- drag.deactivate();
3713
- },
3714
- oninit: function (node) {
3715
- fetchValue(node);
3716
- },
3717
- onupdate: function (node) {
3718
- fetchValue(node);
3719
- },
3720
- view: function () {
3721
- return mithril('div', {
3722
- class: twuiClass(TYPE$4),
3723
- style: {
3724
- '--spherical-phi': toDeg(-phi) + 90 + "deg",
3725
- },
3726
- }, mithril('div.left-container', mithril('div.pane', {
3727
- style: {
3728
- position: 'relative',
3729
- width: '100%',
3730
- 'padding-top': '100%',
3731
- },
3732
- }, mithril('div.phi-pane', {
3733
- class: cssClass({
3734
- 'is-dragging': draggedKnob === 'phi',
3735
- }),
3736
- style: {
3737
- position: 'absolute',
3738
- top: '0.5rem',
3739
- left: '0.5rem',
3740
- width: 'calc(100% - 1rem)',
3741
- height: 'calc(100% - 1rem)',
3742
- },
3743
- }, mithril('div.phi-knob', {
3744
- onmousedown: onStartPhi,
3745
- ontouchstart: onStartPhi,
3746
- style: {
3747
- position: 'absolute',
3748
- width: '15px',
3749
- height: '15px',
3750
- top: "calc(" + toScreen(v2Phi[0]) + "% - 7px)",
3751
- left: "calc(" + toScreen(v2Phi[1]) + "% - 7px)",
3752
- },
3753
- })), mithril('div.theta-pane', {
3754
- class: cssClass({
3755
- 'is-dragging': draggedKnob === 'theta',
3756
- }),
3757
- style: {
3758
- position: 'absolute',
3759
- top: '1.5rem',
3760
- left: '1.5rem',
3761
- width: 'calc(100% - 3rem)',
3762
- height: 'calc(100% - 3rem)',
3763
- },
3764
- }, mithril('div.theta-knob', {
3765
- onmousedown: onStartTheta,
3766
- ontouchstart: onStartTheta,
3767
- style: {
3768
- position: 'absolute',
3769
- width: '15px',
3770
- height: '15px',
3771
- top: "calc(" + toScreen(v2Theta[0]) + "% - 7px)",
3772
- left: "calc(" + toScreen(v2Theta[1]) + "% - 7px)",
3773
- },
3774
- })))), mithril('div.right-container', mithril('label', mithril.trust('&phi;')), renderModel({
3775
- type: 'number',
3776
- min: 0,
3777
- max: 360,
3778
- step: 0.1,
3779
- value: toDeg(phi),
3780
- onInput: onPhiInput,
3781
- onChange: onPhiChange,
3782
- }), mithril('label', mithril.trust('&theta;')), renderModel({
3783
- type: 'number',
3784
- min: 0,
3785
- max: 180,
3786
- step: 0.1,
3787
- value: toDeg(theta),
3788
- onInput: onThetaInput,
3789
- onChange: onThetaChange,
3790
- }), renderModel({
3791
- type: 'checkbox',
3792
- value: backface,
3793
- text: 'Backface',
3794
- onChange: onBackfaceChange,
3795
- })));
3796
- },
3797
- };
3798
- };
3799
- component(TYPE$4, SphericalComponent);
3800
- function sphericalCodec(_a) {
3801
- var _b = _a === void 0 ? {} : _a, axes = _b.axes, length = _b.length, result = _b.result;
3802
- axes = axes || { x: 'right', y: 'up', z: 'back' };
3803
- var keys = Object.keys(axes);
3804
- var radius = function () {
3805
- return (typeof length === 'function' ? length() : length) || 1;
3806
- };
3807
- return {
3808
- decode: function (value) {
3809
- var x = 0;
3810
- var y = 0;
3811
- var z = 0;
3812
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
3813
- var key = keys_1[_i];
3814
- switch (axes[key]) {
3815
- case 'right':
3816
- y = value[key];
3817
- break;
3818
- case 'left':
3819
- y = -value[key];
3820
- break;
3821
- case 'back':
3822
- x = value[key];
3823
- break;
3824
- case 'front':
3825
- x = -value[key];
3826
- break;
3827
- case 'up':
3828
- z = value[key];
3829
- break;
3830
- case 'down':
3831
- z = -value[key];
3832
- break;
3833
- }
3834
- }
3835
- var r = radius();
3836
- x /= r;
3837
- y /= r;
3838
- z /= r;
3839
- return {
3840
- phi: Math.atan2(y, x) || 0,
3841
- theta: Math.atan(Math.sqrt(x * x + y * y) / z) || 0,
3842
- };
3843
- },
3844
- encode: function (_a) {
3845
- var phi = _a.phi, theta = _a.theta;
3846
- var r = radius();
3847
- var x = r * Math.sin(theta) * Math.cos(phi);
3848
- var y = r * Math.sin(theta) * Math.sin(phi);
3849
- var z = r * Math.cos(theta);
3850
- var value = (result === null || result === void 0 ? void 0 : result()) || {};
3851
- for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
3852
- var key = keys_2[_i];
3853
- switch (axes[key]) {
3854
- case 'right':
3855
- value[key] = y;
3856
- break;
3857
- case 'left':
3858
- value[key] = -y;
3859
- break;
3860
- case 'back':
3861
- value[key] = x;
3862
- break;
3863
- case 'front':
3864
- value[key] = -x;
3865
- break;
3866
- case 'up':
3867
- value[key] = z;
3868
- break;
3869
- case 'down':
3870
- value[key] = -z;
3871
- break;
3872
- }
3873
- }
3874
- return value;
3875
- },
3876
- };
3877
- }
3878
-
3879
- component('text', function (node) {
3880
- function onChange(e) {
3881
- var el = e.target;
3882
- var data = node.attrs.data;
3883
- var written = setValue(data, el.value);
3884
- call(e.type === 'input' ? data.onInput : data.onChange, data, written);
3885
- }
3886
- return {
3887
- view: viewFn(function (data) {
3888
- return mithril("input[type='text']", {
3889
- class: twuiClass(data.type),
3890
- value: getValue(data),
3891
- oninput: onChange,
3892
- onchange: onChange,
3893
- placeholder: data.placeholder,
3894
- disabled: data.disabled,
3895
- });
3896
- }),
3897
- };
3898
- });
3899
-
3900
- var TYPE$3 = 'accordion';
3901
- var EMPTY = [];
3902
- component(TYPE$3, function () {
3903
- return {
3904
- view: viewFn(function (data) {
3905
- var children = data.children || EMPTY;
3906
- data.expand = detectExpanded(data.expand, children);
3907
- return mithril.fragment({}, children.map(function (group, i) {
3908
- group.type = 'group';
3909
- group.collapsible = true;
3910
- group.collapsed = i !== data.expand;
3911
- return renderModel(group);
3912
- }));
3913
- }),
3914
- };
3915
- });
3916
- function detectExpanded(index, list) {
3917
- var result = null;
3918
- for (var i = 0; i < list.length; i++) {
3919
- if (!list[i].collapsed) {
3920
- if (i !== index) {
3921
- return i;
3922
- }
3923
- if (result == null) {
3924
- result = i;
3925
- }
3926
- }
3927
- }
3928
- return result;
3929
- }
3930
-
3931
- var TYPE$2 = 'container';
3932
- component(TYPE$2, function () {
3933
- return {
3934
- view: viewFn(function (data) {
3935
- var _a;
3936
- var _b;
3937
- return mithril('div', {
3938
- class: cssClass((_a = {},
3939
- _a[twuiClass(TYPE$2)] = true,
3940
- _a[twuiClass(TYPE$2, 'horizontal')] = data.horizontal,
3941
- _a)),
3942
- style: data.style,
3943
- }, mithril.fragment({}, (_b = data.children) === null || _b === void 0 ? void 0 : _b.map(renderModel)));
3944
- }),
3945
- };
3946
- });
3947
-
3948
- var TYPE$1 = 'group';
3949
- component(TYPE$1, function (node) {
3950
- function onClick(e) {
3951
- use(node.attrs.data, function (data) {
3952
- data.collapsed = !data.collapsed;
3953
- call(data.onToggle, data);
3954
- if (data.collapsed) {
3955
- call(data.onCollapse, data);
3956
- }
3957
- else {
3958
- call(data.onExpand, data);
3959
- }
3960
- });
3961
- }
3962
- function title(data) {
3963
- if (!data.title && !data.collapsible) {
3964
- return null;
3965
- }
3966
- return mithril('div', {
3967
- class: twuiClass(TYPE$1, 'title'),
3968
- onclick: data.collapsible ? onClick : null,
3969
- }, data.title);
3970
- }
3971
- function children(data) {
3972
- var _a;
3973
- if (data.collapsed || !data.children) {
3974
- return [];
3975
- }
3976
- return (_a = data.children) === null || _a === void 0 ? void 0 : _a.map(function (it) {
3977
- if (isString(it.label)) {
3978
- return mithril('div', { class: twuiClass(TYPE$1, 'control') }, mithril('label', it.label), mithril('section', renderModel(it)));
3979
- }
3980
- return renderModel(it);
3981
- });
3982
- }
3983
- return {
3984
- view: viewFn(function (data) {
3985
- var _a;
3986
- return mithril('div', {
3987
- class: cssClass((_a = {},
3988
- _a[twuiClass(TYPE$1)] = true,
3989
- _a[twuiClass(TYPE$1, 'collapsible')] = data.collapsible,
3990
- _a[twuiClass(TYPE$1, 'collapsed')] = data.collapsed,
3991
- _a)),
3992
- style: data.style,
3993
- }, mithril.fragment({}, [title(data)]), mithril.fragment({}, [children(data)]));
3994
- }),
3995
- };
3996
- });
3997
-
3998
- component('tabs', function () {
3999
- return {
4000
- view: viewFn(function (data) {
4001
- var tabs = data.children || [];
4002
- var active = clamp(data.active || 0, 0, tabs.length - 1);
4003
- var tab = tabs[active];
4004
- return mithril('div', {
4005
- class: twuiClass(data.type),
4006
- }, mithril('div', {
4007
- key: data.type + "-list",
4008
- class: twuiClass(data.type + "-list"),
4009
- }, tabs.map(function (it, index) {
4010
- return mithril("button[type='button']", {
4011
- key: data.type + "-" + index,
4012
- onclick: function () { return (data.active = index); },
4013
- class: active === index ? 'is-active' : '',
4014
- }, it.label || it.title);
4015
- })), mithril.fragment({ key: "panel-" + data.active }, [
4016
- renderModel({
4017
- type: 'group',
4018
- children: tab.children,
4019
- style: tab.style,
4020
- }),
4021
- ]));
4022
- }),
4023
- };
4024
- });
4025
-
4026
- var type = 'button';
4027
- component(type, function (node) {
4028
- return {
4029
- view: viewFn(function (data) {
4030
- return mithril(type, {
4031
- type: type,
4032
- class: twuiClass(type),
4033
- onclick: function () { return call(data.onClick, data); },
4034
- disabled: data.disabled,
4035
- }, data.text);
4036
- }),
4037
- };
4038
- });
4039
-
4040
- var CONTENT = 'content';
4041
- component(CONTENT, function () {
4042
- return {
4043
- view: viewFn(function (data) { return mithril.fragment({}, [data.content]); }),
4044
- };
4045
- });
4046
-
4047
- var TYPE = 'image';
4048
- component('image', function (node) {
4049
- var onClick = function () {
4050
- use(node.attrs.data, function (data) { return call(data.onClick, data); });
4051
- };
4052
- function aspect(spec) {
4053
- if (!spec) {
4054
- return null;
4055
- }
4056
- var _a = (spec || '1x1').split('x').map(Number), x = _a[0], y = _a[1];
4057
- var padding = ((y / x) || 1) * 100;
4058
- return padding + "%";
4059
- }
4060
- function width(data) {
4061
- if (isNumber(data.width)) {
4062
- return data.width + "px";
4063
- }
4064
- if (isString(data.width)) {
4065
- return data.width;
4066
- }
4067
- }
4068
- return {
4069
- view: viewFn(function (data) {
4070
- return (Array.isArray(data.src) ? data.src : [data.src]).map(function (src) {
4071
- var _a;
4072
- return mithril('picture', {
4073
- class: cssClass((_a = {},
4074
- _a[twuiClass(TYPE)] = true,
4075
- _a[twuiClass(TYPE, 'aspect')] = !!data.aspect,
4076
- _a)),
4077
- style: {
4078
- '--twui-aspect': aspect(data.aspect),
4079
- '--twui-fit': data.fit || 'fit',
4080
- width: width(data),
4081
- },
4082
- }, mithril('img', {
4083
- src: src,
4084
- onclick: onClick,
4085
- }));
4086
- });
4087
- }),
4088
- };
4089
- });
4090
-
4091
- // tslint:disable: unified-signatures
4092
- function assign(partial, overrides) {
4093
- Object.keys(overrides).forEach(function (key) {
4094
- partial[key] = overrides[key];
4095
- });
4096
- return partial;
4097
- }
4098
- function buildGroup() {
4099
- var label = null;
4100
- var opts = {};
4101
- var cb;
4102
- // tslint:disable-next-line: prefer-for-of
4103
- for (var i = 0; i < arguments.length; i++) {
4104
- var arg = arguments[i];
4105
- if (isString(arg)) {
4106
- label = arg;
4107
- }
4108
- else if (isObject(arg)) {
4109
- opts = arg;
4110
- }
4111
- else if (isFunction(arg)) {
4112
- cb = arg;
4113
- }
4114
- }
4115
- if (label) {
4116
- opts.label = label;
4117
- }
4118
- if (cb) {
4119
- var controls = this.controls;
4120
- this.controls = [];
4121
- cb(this);
4122
- opts.children = this.controls;
4123
- this.controls = controls;
4124
- }
4125
- return opts;
4126
- }
4127
- function buildControl() {
4128
- var opts = {};
4129
- if (arguments.length > 1) {
4130
- opts = arguments[2] || opts;
4131
- opts.target = arguments[0];
4132
- opts.property = arguments[1];
4133
- if (opts.label === undefined) {
4134
- opts.label = String(opts.property || '');
4135
- }
4136
- }
4137
- if (arguments.length === 1) {
4138
- opts = arguments[0] || opts;
4139
- }
4140
- return opts;
4141
- }
4142
- /**
4143
- *
4144
- * @public
4145
- */
4146
- var Builder = /** @class */ (function () {
4147
- function Builder() {
4148
- /**
4149
- * Collection of created controls
4150
- */
4151
- this.controls = [];
4152
- }
4153
- Builder.prototype.group = function () {
4154
- var opts = buildGroup.apply(this, arguments);
4155
- return this.add(assign(opts, {
4156
- type: 'group',
4157
- children: opts.children,
4158
- label: null,
4159
- title: opts.label,
4160
- }));
4161
- };
4162
- Builder.prototype.collapsible = function () {
4163
- var opts = buildGroup.apply(this, arguments);
4164
- return this.add(assign(opts, {
4165
- type: 'group',
4166
- children: opts.children,
4167
- collapsible: true,
4168
- label: null,
4169
- title: opts.label,
4170
- }));
4171
- };
4172
- Builder.prototype.container = function () {
4173
- var opts = buildGroup.apply(this, arguments);
4174
- return this.add(assign(opts, {
4175
- type: 'container',
4176
- children: opts.children,
4177
- }));
4178
- };
4179
- Builder.prototype.tabs = function () {
4180
- var opts = buildGroup.apply(this, arguments);
4181
- return this.add(assign(opts, {
4182
- type: 'tabs',
4183
- active: opts.active || 0,
4184
- children: opts.children,
4185
- }));
4186
- };
4187
- Builder.prototype.accordion = function () {
4188
- var opts = buildGroup.apply(this, arguments);
4189
- return this.add(assign(opts, {
4190
- type: 'accordion',
4191
- children: opts.children,
4192
- }));
4193
- };
4194
- Builder.prototype.checkbox = function () {
4195
- var opts = buildControl.apply(this, arguments);
4196
- return this.add(assign(opts, { type: 'checkbox' }));
4197
- };
4198
- Builder.prototype.text = function () {
4199
- var opts = buildControl.apply(this, arguments);
4200
- return this.add(assign(opts, { type: 'text' }));
4201
- };
4202
- Builder.prototype.number = function () {
4203
- var opts = buildControl.apply(this, arguments);
4204
- return this.add(assign(opts, { type: 'number' }));
4205
- };
4206
- Builder.prototype.slider = function () {
4207
- var opts = buildControl.apply(this, arguments);
4208
- return this.add(assign(opts, { type: 'slider' }));
4209
- };
4210
- Builder.prototype.position = function () {
4211
- var opts = buildControl.apply(this, arguments);
4212
- return this.add(assign(opts, { type: 'position' }));
4213
- };
4214
- Builder.prototype.select = function () {
4215
- var opts = buildControl.apply(this, arguments);
4216
- return this.add(assign(opts, { type: 'select' }));
4217
- };
4218
- Builder.prototype.color = function () {
4219
- var opts = buildControl.apply(this, arguments);
4220
- return this.add(assign(opts, { type: 'color' }));
4221
- };
4222
- Builder.prototype.colorPicker = function () {
4223
- var opts = buildControl.apply(this, arguments);
4224
- return this.add(assign(opts, { type: 'color-picker' }));
4225
- };
4226
- Builder.prototype.point = function () {
4227
- var opts = buildControl.apply(this, arguments);
4228
- return this.add(assign(opts, { type: 'point' }));
4229
- };
4230
- Builder.prototype.spherical = function () {
4231
- var opts = buildControl.apply(this, arguments);
4232
- return this.add(assign(opts, { type: 'spherical' }));
4233
- };
4234
- Builder.prototype.angle = function () {
4235
- var opts = buildControl.apply(this, arguments);
4236
- return this.add(assign(opts, { type: 'angle' }));
4237
- };
4238
- /**
4239
- * Adds a button control
4240
- *
4241
- * @param text - The button text
4242
- * @param opts - Additional options for the control
4243
- */
4244
- Builder.prototype.button = function (text, opts) {
4245
- if (opts === void 0) { opts = {}; }
4246
- return this.add(assign(opts, {
4247
- type: 'button',
4248
- text: text,
4249
- }));
4250
- };
4251
- Builder.prototype.image = function () {
4252
- var opts = buildGroup.apply(this, arguments);
4253
- return this.add(assign(opts, {
4254
- type: 'image',
4255
- }));
4256
- };
4257
- /**
4258
- * Adds a description text
4259
- *
4260
- * @param label - The control label
4261
- * @param text - The text message
4262
- * @param opts - Additional options for the control
4263
- */
4264
- Builder.prototype.content = function (label, content, opts) {
4265
- if (opts === void 0) { opts = {}; }
4266
- return this.add(assign(opts, {
4267
- type: 'content',
4268
- label: label,
4269
- content: content,
4270
- }));
4271
- };
4272
- /**
4273
- * Adds a control
4274
- *
4275
- * @param def - The control definition
4276
- */
4277
- Builder.prototype.add = function (def) {
4278
- var _this = this;
4279
- this.controls.push(assign(def, {
4280
- remove: function () {
4281
- var i = _this.controls.indexOf(def);
4282
- if (i >= 0) {
4283
- _this.controls.splice(i, 1);
4284
- }
4285
- },
4286
- }));
4287
- return def;
4288
- };
4289
- return Builder;
4290
- }());
4291
-
4292
- /**
4293
- * Mithril's hyperscript function.
4294
- *
4295
- * @public
4296
- * @remarks
4297
- * Useful to create custom components
4298
- */
4299
- var h = mithril;
4300
- /**
4301
- * Runs the function through a builder system and returns the created controls
4302
- *
4303
- * @param fn - The builder function
4304
- * @returns
4305
- */
4306
- function build(fn) {
4307
- var builder = new Builder();
4308
- fn(builder);
4309
- return builder.controls;
4310
- }
4311
- /**
4312
- * Mounts a ui to the given element
4313
- *
4314
- * @public
4315
- * @param el - The ui host element
4316
- * @param data - The ui definition object
4317
- */
4318
- function mount(el, data) {
4319
- el = typeof el === 'string' ? document.querySelector(el) : el;
4320
- el.classList.add('twui-root');
4321
- if (!data) {
4322
- mithril.mount(el, null);
4323
- }
4324
- else if (Array.isArray(data)) {
4325
- mithril.mount(el, {
4326
- view: function () {
4327
- return renderModel({
4328
- type: 'group',
4329
- children: data,
4330
- });
4331
- },
4332
- });
4333
- }
4334
- else if (isFunction(data)) {
4335
- var builder_1 = new Builder();
4336
- data(builder_1);
4337
- mithril.mount(el, {
4338
- view: function () {
4339
- return renderModel({
4340
- type: 'group',
4341
- children: builder_1.controls,
4342
- });
4343
- },
4344
- });
4345
- }
4346
- else {
4347
- mithril.mount(el, {
4348
- view: function () { return renderModel(data); },
4349
- });
4350
- }
4351
- }
4352
- /**
4353
- * Unmounts the ui from given host element
4354
- *
4355
- * @public
4356
- * @param el - The ui host element
4357
- */
4358
- function unmount(el) {
4359
- el = typeof el === 'string' ? document.querySelector(el) : el;
4360
- mithril.mount(el, null);
4361
- }
4362
- /**
4363
- * Redraws the ui
4364
- *
4365
- * @public
4366
- * @remarks
4367
- * When changing the ui description object qui callbacks (e.g. `onInput` or `onChange`)
4368
- * the ui will redraw automatically.
4369
- *
4370
- * However if the ui description object is changed from outside the qui callback
4371
- * then this method must be called in order to update the visual state.
4372
- */
4373
- function redraw() {
4374
- mithril.redraw();
4375
- }
4376
-
4377
- /**
4378
- * Tweak UI is a lightweight js library for building input controls with data binding
4379
- *
4380
- * @remarks
4381
- * The library provides a set of common ui components built with mithriljs. The main objective
4382
- * is to allow a developer to rapidly scaffold input interfaces for manipulating javascript objects
4383
- * at runtime.
4384
- *
4385
- * Similar projects are:
4386
- * {@link https://github.com/dataarts/dat.gui | dat.GUI}
4387
- * {@link https://github.com/automat/controlkit.js | controlkit}
4388
- * {@link https://github.com/colejd/guify | guify}
4389
- *
4390
- * @packageDocumentation
4391
- */
4392
- /**
4393
- * The version string
4394
- *
4395
- * @public
4396
- */
4397
- var VERSION = "0.4.3";
4398
-
4399
- exports.Builder = Builder;
4400
- exports.VERSION = VERSION;
4401
- exports.angleCodec = angleCodec;
4402
- exports.build = build;
4403
- exports.component = component;
4404
- exports.getColorFormatter = getColorFormatter;
4405
- exports.getComponent = getComponent;
4406
- exports.getValue = getValue;
4407
- exports.h = h;
4408
- exports.hsv2rgb = hsv2rgb;
4409
- exports.mount = mount;
4410
- exports.redraw = redraw;
4411
- exports.renderModel = renderModel;
4412
- exports.rgb2hsv = rgb2hsv;
4413
- exports.setValue = setValue;
4414
- exports.sphericalCodec = sphericalCodec;
4415
- exports.unmount = unmount;
4416
-
4417
- Object.defineProperty(exports, '__esModule', { value: true });
4418
-
4419
- })));
4420
- //# sourceMappingURL=tweak-ui.umd.js.map
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.TweakUI={}))})(this,function(e){var t=document.createElement(`style`);t.textContent=`:root{--twk-size:1.375rem;--twk-gap:.125rem;--twk-inset:.125rem;--twk-radius:.25rem;--twk-label-size:7rem;--twk-label-pad-x:.25rem;--twk-label-pad-y:0rem;--twk-input-height:var(--twk-size);--twk-input-pad-x:.375rem;--twk-input-pad-y:0rem;--twk-button-height:var(--twk-size);--twk-button-pad-x:.5rem;--twk-button-pad-y:.25rem;--twk-color-base-100:#2a303c;--twk-color-base-200:#242933;--twk-color-base-300:#20252e;--twk-color-base-content:#b2ccd6;--twk-color-neutral:#1c212b;--twk-color-neutral-content:#b2ccd6;--twk-color-accent:#f9aa33;--twk-color-bool-true:#f9aa33;--twk-color-bool-false:#2a303c}.twk-dark{--twk-color-base-100:#1d232a;--twk-color-base-200:#191e24;--twk-color-base-300:#15191e;--twk-color-base-content:#ecf9ff;--twk-color-neutral:#09090b;t:#e4e4e7;--twk-color-accent:#f9aa33}.twk-light{--twk-color-base-100:#fff;--twk-color-base-200:#f5f5f5;--twk-color-base-300:#ebebeb;--twk-color-base-content:#000;--twk-color-neutral:#000;--twk-color-neutral-content:#fff;--twk-color-accent:#2196f3}.tweak-ui{interpolate-size:allow-keywords;background-color:var(--twk-color-base-200);color:var(--twk-color-base-content);gap:var(--twk-gap);font-family:monospace;line-height:1.5;font-size:var(--twk-font-size,12px);width:var(--twk-width,20rem);box-sizing:border-box;border-radius:calc(var(--twk-radius) + var(--twk-inset));padding:0;padding:var(--twk-inset,0);flex-direction:column;flex:none;margin:0;display:flex;overflow:hidden auto}.tweak-ui::-webkit-scrollbar{width:.5rem}.tweak-ui::-webkit-scrollbar-track{background-color:var(--twk-color-base-200)}.tweak-ui::-webkit-scrollbar-thumb{background-color:var(--twk-color-base-200);border-style:solid;border-width:1px;border-color:var(--twk-color-base-300);transition:background-color .2s ease-in-out}.tweak-ui::-webkit-scrollbar-thumb:hover{background-color:var(--twk-color-primary)}.tweak-ui button,.tweak-ui input,.tweak-ui select,.tweak-ui optgroup,.tweak-ui textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border:0;border-radius:0;min-width:0;margin:0;padding:0}.tweak-ui button:not([type=checkbox],select),.tweak-ui input:not([type=checkbox],select),.tweak-ui select:not([type=checkbox],select),.tweak-ui optgroup:not([type=checkbox],select),.tweak-ui textarea:not([type=checkbox],select){appearance:none!important}.tweak-ui button:focus-visible,.tweak-ui input:focus-visible,.tweak-ui select:focus-visible,.tweak-ui optgroup:focus-visible,.tweak-ui textarea:focus-visible{outline:none}.tweak-ui input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.tweak-ui input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.tweak-ui input[type=number]{-moz-appearance:textfield}.tweak-ui .twk-input{cursor:text;box-sizing:border-box;white-space:nowrap;vertical-align:middle;touch-action:manipulation;align-items:center;gap:var(--twk-gap);height:calc(var(--twk-size));min-width:0;line-height:calc(var(--twk-size));padding:var(--twk-input-pad-y) var(--twk-input-pad-x);color:var(--twk-color-base-content);border-radius:var(--twk-radius);border:none;flex:1;transition:color .2s ease-in-out,background-color .2s ease-in-out,outline-color .2s ease-in-out;display:flex;position:relative;appearance:none!important}.tweak-ui .twk-input input{flex:1}.tweak-ui .twk-input:not(.twk-input-readonly){outline-offset:-1px;outline:1px solid #0000}.tweak-ui .twk-input:not(.twk-input-readonly):hover{background-color:var(--twk-color-base-100)}.tweak-ui .twk-input:not(.twk-input-readonly):focus-within{outline-color:var(--twk-color-accent)}.tweak-ui label{min-width:0}.tweak-ui select,.tweak-ui button,.tweak-ui a{cursor:pointer;align-items:center}.tweak-ui select:focus,.tweak-ui input:not([type=checkbox]):focus{color:var(--twk-color-accent)}.tweak-ui select{appearance:base-select;border-radius:var(--twk-radius);background:var(--twk-color-base-100);border-color:var(--twk-color-base-300);border:none}.tweak-ui ::picker(select){appearance:base-select;border-radius:var(--twk-radius);background:var(--twk-color-base-100);border-color:var(--twk-color-base-300);border:none}.tweak-ui select option{justify-content:flex-start;gap:var(--twk-gap);padding-inline:var(--twk-button-pad-x);background:var(--twk-color-base-100);color:var(--twk-color-base-content);display:flex}.tweak-ui select option:hover,.tweak-ui select option:focus{background:var(--twk-color-base-200)}.tweak-ui select{padding-inline:var(--twk-button-pad-x)}.tweak-ui .twk-btn{--twk-btn-bg:var(--twk-color-base-100);--twk-btn-color:var(--twk-color-content);--twk-btn-size:var(--twk-size);cursor:pointer;text-align:center;vertical-align:middle;-webkit-user-select:none;user-select:none;color:var(--twk-btn-color);min-height:var(--twk-btn-size);border-radius:var(--twk-radius);outline-offset:1px;background-color:var(--twk-btn-bg);padding-inline:var(--twk-button-pad-x);text-align:center;white-space:nowrap;outline-color:var(--twk-color-neutral);font-weight:700}.tweak-ui .twk-btn:hover{background-color:color-mix(in oklab, var(--btn-color,var(--twk-btn-bg)), #000 7%)}.tweak-ui .twk-btn:focus{outline-color:var(--twk-color-accent)}.tweak-ui .twk-btn:active{transform:translateY(1px)}.tweak-ui .twk-btn.twk-btn-accent{--twk-btn-bg:var(--twk-color-accent);--twk-btn-color:var(--twk-color-neutral)}.tweak-ui .twk-btn.twk-btn-lg{--twk-btn-size:calc(var(--twk-size) * 1.25)}.tweak-ui .twk-btn.twk-btn-sq{width:var(--twk-btn-size);height:var(--twk-btn-size);flex:none;padding-inline:0}.tweak-ui .twk-btn.twk-btn-bl{width:100%}dialog.twk-dialog{pointer-events:none;visibility:hidden;width:100%;max-width:none;height:100%;max-height:none;color:inherit;overscroll-behavior:contain;z-index:999;scrollbar-gutter:auto;background-color:#0000;border:none;place-items:center;margin:0;padding:0;display:grid;position:fixed;inset:0;overflow:clip}.twk-dialog-content{background-color:var(--twk-color-base-100);border-radius:var(--twk-radius);opacity:0;overscroll-behavior:contain;grid-row-start:1;grid-column-start:1;width:100%;max-width:32rem;max-height:100vh;overflow-y:auto}dialog.twk-dialog[open]{pointer-events:auto;visibility:visible;opacity:1;background-color:oklch(0% 0 0/.4)}dialog.twk-dialog[open] .twk-dialog-content{opacity:1;translate:0;scale:1}.twk-flex{align-items:stretch;gap:var(--twk-gap);flex-flow:column;display:flex}.twk-flex-row{gap:var(--twk-gap);flex-flow:row;display:flex}.twk-grid{gap:var(--twk-gap);display:grid}.twk-divider{padding:0 calc(var(--twk-size) / 2);align-items:center;display:flex}.twk-divider:not(:empty){gap:calc(var(--twk-size) / 2)}.twk-divider{height:var(--twk-size)}.twk-divider:before,.twk-divider:after{content:"";opacity:.125;background-color:currentColor;flex-grow:1;width:100%;height:1px}.twk-divider-v{flex-flow:column;align-items:center;display:flex}.twk-divider-v:not(:empty){gap:calc(var(--twk-size) / 2)}.twk-divider-v{width:var(--twk-size);height:100%}.twk-divider-v:before,.twk-divider-v:after{content:"";opacity:.125;background-color:currentColor;flex-grow:1;width:1px;height:100%}.twk-group,.twk-group-content{gap:var(--twk-gap);flex-direction:column;display:flex}.twk-group-content.animate.enter{animation:.25s ease-out forwards twk-group-content-enter;overflow:hidden}.twk-group-content.leave{animation:.25s ease-out forwards twk-group-content-leave;overflow:hidden}@keyframes twk-group-content-enter{0%{opacity:0;height:0}50%{opacity:0;height:auto}to{opacity:1;height:auto}}@keyframes twk-group-content-leave{0%{opacity:1;height:auto}50%{opacity:0;height:auto}to{opacity:0;height:0}}.twk-group-title{width:auto;height:var(--twk-size);background-color:var(--twk-color-neutral);color:var(--twk-color-neutral-content);border-radius:var(--twk-radius,0);text-transform:uppercase;flex-direction:row;align-items:center;margin:0;padding:0 .5rem;font-weight:700;display:flex}.twk-group-collapsible>.twk-group-title{cursor:pointer;-webkit-user-select:none;user-select:none;position:relative}.twk-group-collapsible>.twk-group-title:before{content:"";width:var(--twk-size);height:var(--twk-size);text-align:center;clip-path:polygon(50.05% 77.08%,83.58% 43.55%,87.11% 40.02%,80.03% 32.94%,76.5% 36.47%,50.03% 62.94%,23.56% 36.47%,20.03% 32.94%,12.95% 40.02%,16.48% 43.55%,46.48% 73.55%,50.02% 77.08%);background-color:currentColor;transition:opacity .2s ease-in-out,transform .2s ease-in-out;display:block;position:absolute;top:0;right:0;transform:scale(.5)rotate(0)}.twk-group-collapsed>.twk-group-title:before{transform:scale(.5)rotate(-90deg)}.twk-group:not(.twk-root>.twk-group) .twk-group{margin-left:calc(var(--twk-size) / 4)}.twk-group-description{opacity:.75;padding:.25rem .25rem .5rem 0;font-style:italic;line-height:1}.twk-tree{width:100%;height:100%;max-height:100vh;overflow-y:auto}.twk-tree-row{-webkit-user-select:none;user-select:none;width:100%;padding-left:calc(var(--twk-tree-row-depth) * .5 * var(--twk-tree-row-height));background-color:var(--twk-color-base-200);box-sizing:border-box;flex-direction:row;align-items:center;display:flex}.twk-tree-row:hover{background-color:var(--twk-color-base-100)}.twk-tree-row.selected{color:var(--twk-color-accent)}.twk-tree-toggle:before{content:"";width:var(--twk-tree-row-height);height:var(--twk-tree-row-height);text-align:center;transition:opacity .2s ease-in-out,transform .2s ease-in-out;display:block;transform:scale(.5)rotate(-90deg)}.twk-tree-toggle.expandable:before{clip-path:polygon(50.05% 77.08%,83.58% 43.55%,87.11% 40.02%,80.03% 32.94%,76.5% 36.47%,50.03% 62.94%,23.56% 36.47%,20.03% 32.94%,12.95% 40.02%,16.48% 43.55%,46.48% 73.55%,50.02% 77.08%);background-color:currentColor}.twk-tree-toggle.expanded:before{transform:scale(.5)rotate(0)}.twk-tree-icon{width:var(--twk-tree-row-height);height:var(--twk-tree-row-height);place-items:center;display:grid}.twk-tree-label{display:flex}.twk-tabs{border-color:var(--twk-color-base-300);align-items:stretch;gap:var(--twk-gap);flex-flow:wrap;display:flex}.twk-tabs button.twk-tab{background-color:var(--twk-color-base-100);color:color-mix(in srgb, var(--twk-color-base-content) 40%, transparent);flex:1;order:0}.twk-tabs button.twk-tab:hover{color:var(--twk-color-base-content)}.twk-tabs button.twk-tab.twk-btn:not(.active){background-color:#0000;font-weight:400}.twk-tabs button.twk-tab.twk-btn.active{color:var(--twk-color-accent);font-weight:700}.twk-tab-content{order:1;width:100%}.twk-tabs-vertical{grid-template-columns:auto 1fr;display:grid}.twk-tabs-vertical .twk-tab{grid-column:1}.twk-tabs-vertical .twk-tab-content{grid-area:1/2/-1}.twk-split-pane{overflow:hidden}.twk-split-pane.dragging{-webkit-user-select:none;user-select:none}.twk-split-pane>:not(.twk-split-gutter){flex:1;min-width:1rem;min-height:1rem}.twk-split-gutter:last-child{display:none}.twk-split-gutter:before{content:"";background-color:var(--twk-color-base-100);opacity:0;position:absolute}.twk-split-gutter:hover:before{background-color:var(--twk-color-base-100);opacity:1}.twk-split-gutter-v{cursor:row-resize;min-height:.25rem;position:relative}.twk-split-gutter-v:before{inset:1px .25rem}.twk-split-gutter-h{cursor:col-resize;min-width:.25rem;position:relative}.twk-split-gutter-h:before{inset:.25rem 1px}.twk-section{grid-template:"header""content"1fr"footer"/100%;width:100%;display:grid}.twk-section>*{grid-area:content}.twk-section-header,header{grid-area:header}.twk-section-content{grid-area:content}.twk-section-footer,footer{grid-area:footer}.twk-bar{gap:var(--twk-gap);min-height:var(--twk-size);grid-template-columns:auto 1fr auto;grid-template-areas:"start content end";align-items:center;display:grid}.twk-bar>*{grid-area:content}.twk-bar-start{grid-area:start}.twk-bar-content{grid-area:content}.twk-bar-end{grid-area:end}.twk-widget{gap:var(--twk-gap);grid-template-columns:.75fr 1fr;grid-template-areas:"label content";width:100%;display:grid}.twk-widget>*{grid-area:content;overflow:hidden}.twk-widget-label{min-height:var(--twk-size);padding:0 calc(var(--twk-size) / 4);color:color-mix(in srgb, var(--twk-color-base-content) 40%, transparent);flex:.75;grid-area:label;align-self:start;align-items:center;display:inline-flex;overflow:hidden}.twk-angle-label{height:var(--twk-size);white-space:nowrap;text-align:right}.twk-angle-input{gap:var(--twk-gap);column-gap:calc(var(--twk-gap) * 2);grid-template:"display input""display output"min-content/min-content auto;display:grid}.twk-angle-input .twk-scalar-input{grid-area:input}.twk-angle-input .twk-angle-label{grid-area:output}.twk-angle-pane{width:100%;width:var(--twk-size);height:var(--twk-size);outline:1px solid var(--twk-color-base-content);outline-offset:-1px;background-image:conic-gradient(from 0deg, var(--twk-color-base-content) calc(var(--angle-value) / 360 * 100%), transparent 0);border-radius:50%;grid-area:display}.twk-bitmask-input{gap:var(--twk-gap);flex-direction:column;display:flex}.twk-bitmask-input .twk-bitmask-row{gap:var(--twk-gap);cursor:pointer;flex-direction:row;display:flex}.twk-bitmask-input .twk-bitmask-row>*{flex:none}.twk-bitmask-input .twk-bitmask-name{text-overflow:ellipsis;flex:1;padding-left:.25rem;overflow:hidden}.twk-bitmask-input .twk-bitmask-bit{opacity:.5;padding-right:.25rem}.twk-bitmask-input .twk-bitmask-value{opacity:.5}.twk-bitmask-input .twk-bitmask-indicator{width:var(--twk-size);height:var(--twk-size);background-color:var(--twk-color-base-100)}.twk-bitmask-active .twk-bitmask-indicator:before{content:"";background-color:var(--twk-color-accent);width:50%;height:50%;margin:25%;display:block}.twk-bitmask-active .twk-bitmask-value{opacity:1}.twk-bool-input{align-items:center;gap:var(--twk-gap);flex-direction:row;display:flex}.twk-bool-input input{text-align:right;min-width:0}.twk-bool-input.twk-align-end{justify-content:flex-end}.twk-color-picker{gap:var(--twk-gap);flex-direction:row;flex:auto;display:flex}.twk-color-picker .color-picker-panel{flex:1;position:relative}.twk-color-picker .color-picker-inputs{gap:var(--twk-gap);flex-direction:column;flex:none;display:flex}.twk-color-picker .color-picker-inputs .input-r{border-left:2px solid red!important}.twk-color-picker .color-picker-inputs .input-g{border-left:2px solid #0f0!important}.twk-color-picker .color-picker-inputs .input-b{border-left:2px solid #00f!important}.twk-color-picker .color-picker-inputs .input-a{border-image:linear-gradient(90deg,#fff,#0000)}.twk-color-picker .color-picker-inputs .input-hex{border-left:2px solid #000!important}.twk-color-picker .color-picker-inputs input{flex:none;width:4rem;display:block}.twk-color-picker .color-picker-sv:focus,.twk-color-picker .color-picker-h:focus,.twk-color-picker .color-picker-a:focus{border-color:var(--twk-color-accent);outline:none}.twk-color-picker .color-picker-sv,.twk-color-picker .color-picker-h,.twk-color-picker .color-picker-a{border-radius:var(--twk-radius)}.twk-color-picker .color-picker-sv{box-sizing:border-box;cursor:crosshair;z-index:1;border-bottom:1px solid;border-color:var(--twk-color-base-300);width:100%;padding-top:100%;position:relative}.twk-color-picker .color-picker-sv-bg{border-radius:var(--twk-radius);position:absolute;inset:0}.twk-color-picker .color-picker-sv-cursor{box-sizing:border-box;border:1px solid #fff;border-radius:5px;width:10px;height:10px;margin-top:-5px;margin-left:-5px;position:absolute;box-shadow:0 0 2px 1px #000000bf}.twk-color-picker .color-picker-h,.twk-color-picker .color-picker-a{box-sizing:border-box;cursor:ew-resize;border-bottom:1px solid;border-color:var(--twk-color-base-300);height:1rem;position:relative}.twk-color-picker .color-picker-h-cursor,.twk-color-picker .color-picker-a-cursor{border:1px solid #fff;border-radius:2px;width:4px;height:calc(1rem - 2px);margin-left:-3px;position:absolute;box-shadow:0 0 2px 1px #000000bf}.twk-color-picker .color-picker-a{background-blend-mode:normal, difference, normal;background-image:linear-gradient(90deg,#0000,#0000),linear-gradient(90deg,gray 50%,#fff 50%),linear-gradient(gray 50%,#fff 50%);background-size:1rem 1rem}.twk-color-picker .color-picker-a-bg{position:absolute;inset:0}.twk-color-picker .color-picker-sv,.twk-color-picker .color-picker-h,.twk-color-picker .color-picker-a{border-color:var(--twk-color-base-300)}.twk-color-input{align-items:stretch;gap:var(--twk-gap);flex-direction:column;flex:auto;display:flex}.twk-color-input button.twk-btn{text-transform:uppercase;flex-direction:row;flex:1;justify-content:start;align-items:center;gap:.5rem;padding-left:0;display:flex}.twk-color-input button.twk-btn:before{content:"";width:calc(var(--twk-size));height:calc(var(--twk-size));background-color:var(--twk-color-value);border-radius:var(--twk-radius);flex:none;display:inline-block}.tweak-ui input[type=checkbox]{flex:none}input.twk-toggle[type=checkbox]{width:calc(var(--twk-size) * 2);height:calc(var(--twk-size));border-radius:var(--twk-size);border:2px solid var(--twk-color-base-100);background-color:var(--twk-color-base-100);cursor:pointer;appearance:none;vertical-align:middle;webkit-user-select:none;-webkit-user-select:none;user-select:none;flex-shrink:0;grid-template-columns:1fr 1fr;place-content:center;margin:0;padding:2px;display:inline-grid}input.twk-toggle[type=checkbox]:checked{border-color:var(--twk-color-base-content)}input.twk-toggle[type=checkbox]:focus{border-color:var(--twk-color-accent)}input.twk-toggle[type=checkbox]:before{aspect-ratio:1;content:"";background-color:var(--twk-color-base-content);opacity:.25;border-radius:100%;grid-row-start:1;grid-column-start:1;transition:background-color .1s,translate .2s;translate:0}input.twk-toggle[type=checkbox]:checked:before{opacity:1;translate:100%}input.twk-check[type=checkbox]{width:calc(var(--twk-size) - 4px);height:calc(var(--twk-size) - 4px);border-radius:var(--twk-radius);cursor:pointer;appearance:none;background-color:var(--twk-color-base-300);outline:1px solid var(--twk-color-base-content);outline-offset:-1px;place-content:center;margin:2px;transition:background-color .1s;display:grid;flex:none!important}input.twk-check[type=checkbox]:checked{background-color:var(--twk-color-accent);outline-color:var(--twk-color-accent)}input.twk-check[type=checkbox]:checked:before{content:"";width:calc(var(--twk-size) / 2);height:calc(var(--twk-size) / 4);border-left:2px solid var(--twk-color-base-300);border-bottom:2px solid var(--twk-color-base-300);margin-top:-2px;transform:rotate(-45deg)}canvas.twk-graph{width:100%}table.twk-graph{text-align:right;border-collapse:collapse;table-layout:fixed;width:100%;margin:0;display:table!important}table.twk-graph thead,table.twk-graph tbody{width:100%}table.twk-graph td,table.twk-graph th{white-space:nowrap;text-overflow:ellipsis;padding:0 4px;overflow:hidden}table.twk-graph th:first-child,table.twk-graph td:first-child{width:var(--twk-label-size);text-align:left}table.twk-graph .twk-current{width:70px;font-weight:600}table.twk-graph .twk-stats{color:#888;width:110px;font-size:.85em}.twk-image{max-width:100%;display:block}.twk-image.twk-loading{opacity:0}.twk-matrix-input{gap:var(--twk-gap)}.twk-point .point-area{background-color:var(--twk-color-base-100);border-color:var(--twk-color-base-300);background-image:linear-gradient(var(--twk-color-base-200) 1px, transparent 1px), linear-gradient(90deg, var(--twk-color-base-200) 1px, transparent 1px);aspect-ratio:1;box-sizing:border-box;cursor:crosshair;z-index:1;background-size:10% 10%,10% 10%;align-self:end;width:100%;transition:border-color .2s ease-in-out,background-color .2s ease-in-out;position:relative;overflow:visible}.twk-point .point-area .point-x-axis,.twk-point .point-area .point-y-axis{background-color:var(--twk-color-base-300)}.twk-point .point-area:focus .point-x-axis,.twk-point .point-area:focus .point-y-axis{background-color:var(--twk-color-accent)}.twk-point .point-area:focus{border-color:var(--twk-color-accent);outline:none}.twk-scalar-input{align-items:center;gap:var(--twk-gap);grid-auto-flow:column;display:grid;position:relative}.twk-scalar-input input{text-align:right;min-width:0}.twk-scalar-input .unit{opacity:.5}.twk-scalar-dragable input{cursor:ew-resize}.twk-scalar-range:after{pointer-events:none;content:"";opacity:.125;background:linear-gradient(to right, var(--twk-color-accent) 0%, var(--twk-color-accent) calc(var(--twk-scalar-value,0) * 100%), transparent calc(var(--twk-scalar-value,0) * 100%), transparent 100%);border-radius:var(--twk-radius);width:100%;position:absolute;top:0;bottom:0;left:0}.twk-scalar-range:hover:after{opacity:.25}.twk-spherical-label{height:var(--twk-size);white-space:nowrap;text-align:center}.twk-spherical-pane{outline:3px solid var(--twk-color-base-content);outline-offset:-3px;border-radius:50%;width:100%;max-width:150px;margin:1rem auto}.twk-spherical-arm{border:1px solid var(--twk-color-base-content);border-radius:calc(var(--twk-size) / 2);background-image:linear-gradient(to right, var(--twk-color-base-content), var(--twk-color-base-content) calc(var(--polar-value) / 90 * 100%), var(--twk-color-base-300) calc(var(--polar-value) / 90 * 100%))}.twk-spherical-knob{background-color:var(--twk-color-base-content);-webkit-user-select:none;user-select:none;width:1rem;height:1rem;box-shadow:0 0 3px var(--twk-color-neutral);border-radius:50%}.twk-spherical-knob:focus,.twk-spherical-arm:focus{outline:2px solid var(--twk-color-accent);outline-offset:2px}.twk-string-input input,.twk-string-input .twk-input-value{flex:1}.twk-vector-input{gap:var(--twk-gap)}.twk-widget .twk-poll{flex:1}.tweak-ui .twk-p-0{padding:0}.tweak-ui .twk-p-1{padding:var(--twk-gap)}.tweak-ui .twk-p-2{padding:calc(var(--twk-gap) * 2)}.tweak-ui .twk-p-4{padding:calc(var(--twk-gap) * 4)}.tweak-ui .twk-px-0{padding-inline:0}.tweak-ui .twk-px-1{padding-inline:var(--twk-gap)}.tweak-ui .twk-px-2{padding-inline:calc(var(--twk-gap) * 2)}.tweak-ui .twk-px-4{padding-inline:calc(var(--twk-gap) * 4)}.tweak-ui .twk-py-0{padding-block:0}.tweak-ui .twk-py-1{padding-block:var(--twk-gap)}.tweak-ui .twk-py-2{padding-block:calc(var(--twk-gap) * 2)}.tweak-ui .twk-py-4{padding-block:calc(var(--twk-gap) * 4)}.tweak-ui .twk-p-inset{padding:var(--twk-inset)}.tweak-ui .twk-px-label{padding-inline:var(--twk-label-pad-x)}.tweak-ui .twk-px-input{padding-inline:var(--twk-input-pad-x)}.tweak-ui .twk-px-button{padding-inline:var(--twk-button-pad-x)}.tweak-ui .twk-gap-0{gap:0}.tweak-ui .twk-gap-1{gap:var(--twk-gap)}.tweak-ui .twk-gap-2{gap:calc(var(--twk-gap) * 2)}.tweak-ui .twk-gap-4{gap:calc(var(--twk-gap) * 4)}.tweak-ui .twk-w-full{width:100%}.tweak-ui .twk-w-label{width:var(--twk-label-size)}.tweak-ui .twk-h-input{height:var(--twk-input-height)}.tweak-ui .twk-h-btn{height:var(--twk-button-height)}.tweak-ui .twk-h-full{height:100%}.tweak-ui .twk-rounded-none{border-radius:0}.tweak-ui .twk-rounded{border-radius:var(--twk-radius)}.tweak-ui .twk-rounded-full{border-radius:9999px}.tweak-ui .twk-text-end{text-align:end}.tweak-ui .twk-text-right{text-align:right}.tweak-ui .twk-text-start{text-align:start}.tweak-ui .twk-text-left{text-align:left}.tweak-ui .twk-text-center{text-align:center}.tweak-ui .twk-text-xs{font-size:.625rem}.tweak-ui .twk-text-sm{font-size:.75rem}.tweak-ui .twk-text-md{font-size:.875rem}.tweak-ui .twk-bg-100{background-color:var(--twk-color-base-100)}.tweak-ui .twk-bg-200{background-color:var(--twk-color-base-200)}.tweak-ui .twk-bg-300{background-color:var(--twk-color-base-300)}.tweak-ui .twk-bg-content{background-color:var(--twk-color-base-content)}.tweak-ui .twk-bg-neutral{background-color:var(--twk-color-neutral)}.tweak-ui .twk-bg-neutral-content{background-color:var(--twk-color-neutral-content)}.tweak-ui .twk-bg-accent{background-color:var(--twk-color-accent)}.tweak-ui .twk-color-100{color:var(--twk-color-base-100)}.tweak-ui .twk-color-200{color:var(--twk-color-base-200)}.tweak-ui .twk-color-300{color:var(--twk-color-base-300)}.tweak-ui .twk-color-content{color:var(--twk-color-base-content)}.tweak-ui .twk-color-neutral{color:var(--twk-color-neutral)}.tweak-ui .twk-color-neutral-content{color:var(--twk-color-neutral-content)}.tweak-ui .twk-color-accent{color:var(--twk-color-accent)}.tweak-ui .twk-color-muted{color:color-mix(in srgb, var(--twk-color-base-content) 40%, transparent)}.tweak-ui .twk-color-dim{color:color-mix(in srgb, var(--twk-color-base-content) 20%, transparent)}.tweak-ui .twk-glass{background-color:color-mix(in srgb, var(--twk-glass-color,#000) var(--twk-glass-percent,50%), transparent);-webkit-backdrop-filter:blur(40px);backdrop-filter:blur(40px)}.tweak-ui .twk-glass-100{--twk-glass-color:var(--twk-color-base-100)}.tweak-ui .twk-glass-200{--twk-glass-color:var(--twk-color-base-200)}.tweak-ui .twk-glass-300{--twk-glass-color:var(--twk-color-base-300)}@keyframes twk-fade{0%{opacity:0}to{opacity:1}}:root{--twk-pattern-color-a:color-mix(in srgb, var(--twk-color-base-300) 100%, transparent);--twk-pattern-color-b:color-mix(in srgb, var(--twk-color-base-100) 80%, transparent);--twk-pattern-color-line:color-mix(in srgb, var(--twk-color-base-content) 8%, transparent);--twk-pattern-size:.5rem;--twk-pattern-line-width:1px}.twk-bg-checker,.twk-bg-checker-coarse,.twk-bg-checker-fine{background-color:var(--twk-pattern-color-a);background-image:repeating-conic-gradient(var(--twk-pattern-color-b) 0% 25%, transparent 25% 50%);background-size:calc(var(--twk-pattern-size) * 2) calc(var(--twk-pattern-size) * 2);background-position:0 0}.twk-bg-checker-fine{--twk-pattern-size:.25rem}.twk-bg-checker-coarse{--twk-pattern-size:1rem}.twk-bg-grid{background-color:var(--twk-pattern-color-a);background-image:linear-gradient(to right, var(--twk-pattern-color-line) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width)), linear-gradient(to bottom, var(--twk-pattern-color-line) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width));background-size:var(--twk-pattern-size) var(--twk-pattern-size);background-position:0 0}.twk-bg-grid-axis{--twk-pattern-color-axis:color-mix(in srgb, var(--twk-color-base-content) 20%, transparent);background-color:var(--twk-pattern-color-a);background-image:linear-gradient(to right, var(--twk-pattern-color-axis) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width)), linear-gradient(to bottom, var(--twk-pattern-color-axis) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width)), linear-gradient(to right, var(--twk-pattern-color-line) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width)), linear-gradient(to bottom, var(--twk-pattern-color-line) var(--twk-pattern-line-width), transparent var(--twk-pattern-line-width));background-size:100% 100%, 100% 100%, var(--twk-pattern-size) var(--twk-pattern-size), var(--twk-pattern-size) var(--twk-pattern-size);background-position:0,50% 0,0 0,0 0}.twk-bg-dots{--twk-pattern-dot-size:1.5px;background-color:var(--twk-pattern-color-a);background-image:radial-gradient(circle, var(--twk-pattern-color-line) var(--twk-pattern-dot-size), transparent var(--twk-pattern-dot-size));background-size:var(--twk-pattern-size) var(--twk-pattern-size);background-position:0 0}.twk-bg-stripes{background-color:var(--twk-pattern-color-a);background-image:repeating-linear-gradient(-45deg, var(--twk-pattern-color-b) 0px, var(--twk-pattern-color-b) var(--twk-pattern-size), transparent var(--twk-pattern-size), transparent calc(var(--twk-pattern-size) * 2))}
2
+ /*$vite$:1*/`,document.head.appendChild(t),Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=c(((e,t)=>{function n(e,t,n,r,i,a){return{tag:e,key:t,attrs:n,children:r,text:i,dom:a,is:void 0,domSize:void 0,state:void 0,events:void 0,instance:void 0}}n.normalize=function(e){return Array.isArray(e)?n(`[`,void 0,void 0,n.normalizeChildren(e),void 0,void 0):e==null||typeof e==`boolean`?null:typeof e==`object`?e:n(`#`,void 0,void 0,String(e),void 0,void 0)},n.normalizeChildren=function(e){for(var t=Array(e.length),r=0,i=0;i<e.length;i++)t[i]=n.normalize(e[i]),t[i]!==null&&t[i].key!=null&&r++;if(r!==0&&r!==e.length)throw TypeError(t.includes(null)?`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.`);return t},t.exports=n})),f=c(((e,t)=>{var n=d();t.exports=function(e,t){return e==null||typeof e==`object`&&e.tag==null&&!Array.isArray(e)?t.length===1&&Array.isArray(t[0])&&(t=t[0]):(t=t.length===0&&Array.isArray(e)?e:[e,...t],e=void 0),n(``,e&&e.key,e,t)}})),p=c(((e,t)=>{t.exports={}.hasOwnProperty})),m=c(((e,t)=>{t.exports={}})),h=c(((e,t)=>{var n=m();t.exports=new Map([[n,!0]])})),g=c(((e,t)=>{var n=d(),r=f(),i=p(),a=m(),o=h(),s=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,c=Object.create(null);function l(e){for(var t in e)if(i.call(e,t))return!1;return!0}function u(e){return e===`value`||e===`checked`||e===`selectedIndex`||e===`selected`}function g(e){for(var t,n=`div`,r=[],i={},d=!0;t=s.exec(e);){var f=t[1],p=t[2];if(f===``&&p!==``)n=p;else if(f===`#`)i.id=p;else if(f===`.`)r.push(p);else if(t[3][0]===`[`){var m=t[6];m&&=m.replace(/\\(["'])/g,`$1`).replace(/\\\\/g,`\\`),t[4]===`class`?r.push(m):(i[t[4]]=m===``?m:m||!0,u(t[4])&&(d=!1))}}return r.length>0&&(i.className=r.join(` `)),l(i)?i=a:o.set(i,d),c[e]={tag:n,attrs:i,is:i.is}}function _(e,t){t.tag=e.tag;var n=t.attrs;if(n==null)return t.attrs=e.attrs,t.is=e.is,t;if(i.call(n,`class`)&&(n.class!=null&&(n.className=n.class),n.class=null),e.attrs!==a){var r=n.className;n=Object.assign({},e.attrs,n),e.attrs.className!=null&&(n.className=r==null?e.attrs.className:String(e.attrs.className)+` `+String(r))}return e.tag===`input`&&i.call(n,`type`)&&(n=Object.assign({type:n.type},n)),t.is=n.is,t.attrs=n,t}function v(e,t,...i){if(e==null||typeof e!=`string`&&typeof e!=`function`&&typeof e.view!=`function`)throw Error(`The selector must be either a string or a component.`);var a=r(t,i);return typeof e==`string`&&(a.children=n.normalizeChildren(a.children),e!==`[`)?_(c[e]||g(e),a):(a.attrs??={},a.tag=e,a)}t.exports=v})),_=c(((e,t)=>{var n=d();t.exports=function(e){return e??=``,n(`<`,void 0,void 0,e,void 0,void 0)}})),v=c(((e,t)=>{var n=d(),r=f();t.exports=function(e,...t){var i=r(e,t);return i.attrs??={},i.tag=`[`,i.children=n.normalizeChildren(i.children),i}})),y=c(((e,t)=>{var n=g();n.trust=_(),n.fragment=v(),t.exports=n})),b=c(((e,t)=>{t.exports=new WeakMap})),x=c(((e,t)=>{var n=b();function*r(e){var t=e.dom,r=e.domSize,i=n.get(t);if(t!=null)do{var a=t.nextSibling;n.get(t)===i&&(yield t,r--),t=a}while(r)}t.exports=r})),S=c(((e,t)=>{var n=d(),r=b(),i=x(),a=h();t.exports=function(){var e={svg:`http://www.w3.org/2000/svg`,math:`http://www.w3.org/1998/Math/MathML`},t,o;function s(e){return e.ownerDocument}function c(t){return t.attrs&&t.attrs.xmlns||e[t.tag]}function l(e,t){if(e.state!==t)throw Error(`'vnode.state' must not be modified.`)}function u(e){var t=e.state;try{return this.apply(t,arguments)}finally{l(e,t)}}function d(e){try{return s(e).activeElement}catch{return null}}function f(e,t,n,r,i,a,o){for(var s=n;s<r;s++){var c=t[s];c!=null&&p(e,c,i,o,a)}}function p(e,t,n,r,i){var a=t.tag;if(typeof a==`string`)switch(t.state={},t.attrs!=null&&H(t.attrs,t,n),a){case`#`:m(e,t,i);break;case`<`:g(e,t,r,i);break;case`[`:_(e,t,n,r,i);break;default:v(e,t,n,r,i)}else b(e,t,n,r,i)}function m(e,t,n){t.dom=s(e).createTextNode(t.children),N(e,t.dom,n)}var h={caption:`table`,thead:`table`,tbody:`table`,tfoot:`table`,tr:`tbody`,th:`tr`,td:`tr`,colgroup:`table`,col:`colgroup`};function g(e,t,n,r){var i=t.children.match(/^\s*?<(\w+)/im)||[],a=s(e).createElement(h[i[1]]||`div`);n===`http://www.w3.org/2000/svg`?(a.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg">`+t.children+`</svg>`,a=a.firstChild):a.innerHTML=t.children,t.dom=a.firstChild,t.domSize=a.childNodes.length;for(var o=s(e).createDocumentFragment(),c;c=a.firstChild;)o.appendChild(c);N(e,o,r)}function _(e,t,n,r,i){var a=s(e).createDocumentFragment();if(t.children!=null){var o=t.children;f(a,o,0,o.length,n,null,r)}t.dom=a.firstChild,t.domSize=a.childNodes.length,N(e,a,i)}function v(e,t,n,r,i){var a=t.tag,o=t.attrs,l=t.is;r=c(t)||r;var u=r?l?s(e).createElementNS(r,a,{is:l}):s(e).createElementNS(r,a):l?s(e).createElement(a,{is:l}):s(e).createElement(a);if(t.dom=u,o!=null&&re(t,o,r),N(e,u,i),!P(t)&&t.children!=null){var d=t.children;f(u,d,0,d.length,n,null,r),t.tag===`select`&&o!=null&&ae(t,o)}}function y(e,t){var r;if(typeof e.tag.view==`function`){if(e.state=Object.create(e.tag),r=e.state.view,r.$$reentrantLock$$!=null)return;r.$$reentrantLock$$=!0}else{if(e.state=void 0,r=e.tag,r.$$reentrantLock$$!=null)return;r.$$reentrantLock$$=!0,e.state=e.tag.prototype!=null&&typeof e.tag.prototype.view==`function`?new e.tag(e):e.tag(e)}if(H(e.state,e,t),e.attrs!=null&&H(e.attrs,e,t),e.instance=n.normalize(u.call(e.state.view,e)),e.instance===e)throw Error(`A view cannot return the vnode it received as argument`);r.$$reentrantLock$$=null}function b(e,t,n,r,i){y(t,n),t.instance==null?t.domSize=0:(p(e,t.instance,n,r,i),t.dom=t.instance.dom,t.domSize=t.instance.domSize)}function x(e,t,n,r,i,a){if(!(t===n||t==null&&n==null))if(t==null||t.length===0)f(e,n,0,n.length,r,i,a);else if(n==null||n.length===0)F(e,t,0,t.length);else{var o=t[0]!=null&&t[0].key!=null,s=n[0]!=null&&n[0].key!=null,c=0,l=0;if(!o)for(;l<t.length&&t[l]==null;)l++;if(!s)for(;c<n.length&&n[c]==null;)c++;if(o!==s)F(e,t,l,t.length),f(e,n,c,n.length,r,i,a);else if(s){for(var u=t.length-1,d=n.length-1,m,h,g,_,v,y;u>=l&&d>=c&&(_=t[u],v=n[d],_.key===v.key);)_!==v&&S(e,_,v,r,i,a),v.dom!=null&&(i=v.dom),u--,d--;for(;u>=l&&d>=c&&(h=t[l],g=n[c],h.key===g.key);)l++,c++,h!==g&&S(e,h,g,r,j(t,l,i),a);for(;u>=l&&d>=c&&!(c===d||h.key!==v.key||_.key!==g.key);)y=j(t,l,i),M(e,_,y),_!==g&&S(e,_,g,r,y,a),++c<=--d&&M(e,h,i),h!==v&&S(e,h,v,r,i,a),v.dom!=null&&(i=v.dom),l++,u--,_=t[u],v=n[d],h=t[l],g=n[c];for(;u>=l&&d>=c&&_.key===v.key;)_!==v&&S(e,_,v,r,i,a),v.dom!=null&&(i=v.dom),u--,d--,_=t[u],v=n[d];if(c>d)F(e,t,l,u+1);else if(l>u)f(e,n,c,d+1,r,i,a);else{var b=i,x=d-c+1,C=Array(x),w=0,T=0,E=2147483647,D=0,m,k;for(T=0;T<x;T++)C[T]=-1;for(T=d;T>=c;T--){m??=O(t,l,u+1),v=n[T];var N=m[v.key];N!=null&&(E=N<E?N:-1,C[T-c]=N,_=t[N],t[N]=null,_!==v&&S(e,_,v,r,i,a),v.dom!=null&&(i=v.dom),D++)}if(i=b,D!==u-l+1&&F(e,t,l,u+1),D===0)f(e,n,c,d+1,r,i,a);else if(E===-1)for(k=A(C),w=k.length-1,T=d;T>=c;T--)g=n[T],C[T-c]===-1?p(e,g,r,a,i):k[w]===T-c?w--:M(e,g,i),g.dom!=null&&(i=n[T].dom);else for(T=d;T>=c;T--)g=n[T],C[T-c]===-1&&p(e,g,r,a,i),g.dom!=null&&(i=n[T].dom)}}else{var P=t.length<n.length?t.length:n.length;for(c=c<l?c:l;c<P;c++)h=t[c],g=n[c],!(h===g||h==null&&g==null)&&(h==null?p(e,g,r,a,j(t,c+1,i)):g==null?L(e,h):S(e,h,g,r,j(t,c+1,i),a));t.length>P&&F(e,t,c,t.length),n.length>P&&f(e,n,c,n.length,r,i,a)}}}function S(e,t,n,r,i,a){var o=t.tag;if(o===n.tag&&t.is===n.is){if(n.state=t.state,n.events=t.events,W(n,t))return;if(typeof o==`string`)switch(n.attrs!=null&&U(n.attrs,n,r),o){case`#`:C(t,n);break;case`<`:w(e,t,n,a,i);break;case`[`:T(e,t,n,r,i,a);break;default:E(t,n,r,a)}else D(e,t,n,r,i,a)}else L(e,t),p(e,n,r,a,i)}function C(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children),t.dom=e.dom}function w(e,t,n,r,i){t.children===n.children?(n.dom=t.dom,n.domSize=t.domSize):(te(e,t),g(e,n,r,i))}function T(e,t,n,r,i,a){x(e,t.children,n.children,r,i,a);var o=0,s=n.children;if(n.dom=null,s!=null)for(var c=0;c<s.length;c++){var l=s[c];l!=null&&l.dom!=null&&(n.dom??=l.dom,o+=l.domSize||1)}n.domSize=o}function E(e,t,n,r){var i=t.dom=e.dom;r=c(t)||r,(e.attrs!=t.attrs||t.attrs!=null&&!a.get(t.attrs))&&oe(t,e.attrs,t.attrs,r),P(t)||x(i,e.children,t.children,n,null,r)}function D(e,t,r,i,a,o){if(r.instance=n.normalize(u.call(r.state.view,r)),r.instance===r)throw Error(`A view cannot return the vnode it received as argument`);U(r.state,r,i),r.attrs!=null&&U(r.attrs,r,i),r.instance==null?(t.instance!=null&&L(e,t.instance),r.domSize=0):(t.instance==null?p(e,r.instance,i,o,a):S(e,t.instance,r.instance,i,a,o),r.dom=r.instance.dom,r.domSize=r.instance.domSize)}function O(e,t,n){for(var r=Object.create(null);t<n;t++){var i=e[t];if(i!=null){var a=i.key;a!=null&&(r[a]=t)}}return r}var k=[];function A(e){for(var t=[0],n=0,r=0,i=0,a=k.length=e.length,i=0;i<a;i++)k[i]=e[i];for(var i=0;i<a;++i)if(e[i]!==-1){var o=t[t.length-1];if(e[o]<e[i]){k[i]=o,t.push(i);continue}for(n=0,r=t.length-1;n<r;){var s=(n>>>1)+(r>>>1)+(n&r&1);e[t[s]]<e[i]?n=s+1:r=s}e[i]<e[t[n]]&&(n>0&&(k[i]=t[n-1]),t[n]=i)}for(n=t.length,r=t[n-1];n-- >0;)t[n]=r,r=k[r];return k.length=0,t}function j(e,t,n){for(;t<e.length;t++)if(e[t]!=null&&e[t].dom!=null)return e[t].dom;return n}function M(e,t,n){if(t.dom!=null){var r;if(t.domSize==null||t.domSize===1)r=t.dom;else{r=s(e).createDocumentFragment();for(var a of i(t))r.appendChild(a)}N(e,r,n)}}function N(e,t,n){n==null?e.appendChild(t):e.insertBefore(t,n)}function P(e){if(e.attrs==null||e.attrs.contenteditable==null&&e.attrs.contentEditable==null)return!1;var t=e.children;if(t!=null&&t.length===1&&t[0].tag===`<`){var n=t[0].children;e.dom.innerHTML!==n&&(e.dom.innerHTML=n)}else if(t!=null&&t.length!==0)throw Error(`Child node of a contenteditable must be trusted.`);return!0}function F(e,t,n,r){for(var i=n;i<r;i++){var a=t[i];a!=null&&L(e,a)}}function ee(e,t,n,a){var s=t.state,c=u.call(n.onbeforeremove,t);if(c!=null){var d=o;for(var f of i(t))r.set(f,d);a.v++,Promise.resolve(c).finally(function(){l(t,s),I(e,t,a)})}}function I(e,t,n){--n.v===0&&(ne(t),te(e,t))}function L(e,t){var n={v:1};typeof t.tag!=`string`&&typeof t.state.onbeforeremove==`function`&&ee(e,t,t.state,n),t.attrs&&typeof t.attrs.onbeforeremove==`function`&&ee(e,t,t.attrs,n),I(e,t,n)}function te(e,t){if(t.dom!=null)if(t.domSize==null||t.domSize===1)e.removeChild(t.dom);else for(var n of i(t))e.removeChild(n)}function ne(e){if(typeof e.tag!=`string`&&typeof e.state.onremove==`function`&&u.call(e.state.onremove,e),e.attrs&&typeof e.attrs.onremove==`function`&&u.call(e.attrs.onremove,e),typeof e.tag!=`string`)e.instance!=null&&ne(e.instance);else{e.events!=null&&(e.events._=null);var t=e.children;if(Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];r!=null&&ne(r)}}}function re(e,t,n){for(var r in t)R(e,r,null,t[r],n)}function R(e,t,n,r,i){if(!(t===`key`||r==null||ce(t)||n===r&&!se(e,t)&&typeof r!=`object`)){if(t[0]===`o`&&t[1]===`n`)return le(e,t,r);if(t.slice(0,6)===`xlink:`)e.dom.setAttributeNS(`http://www.w3.org/1999/xlink`,t.slice(6),r);else if(t===`style`)B(e.dom,n,r);else if(z(e,t,i)){if(t===`value`){if((e.tag===`input`||e.tag===`textarea`)&&e.dom.value===``+r||e.tag===`select`&&n!==null&&e.dom.value===``+r||e.tag===`option`&&n!==null&&e.dom.value===``+r)return;if(e.tag===`input`&&e.attrs.type===`file`&&``+r!=``){console.error("`value` is read-only on file inputs!");return}}e.tag===`input`&&t===`type`?e.dom.setAttribute(t,r):e.dom[t]=r}else typeof r==`boolean`?r?e.dom.setAttribute(t,``):e.dom.removeAttribute(t):e.dom.setAttribute(t===`className`?`class`:t,r)}}function ie(e,t,n,r){if(!(t===`key`||n==null||ce(t)))if(t[0]===`o`&&t[1]===`n`)le(e,t,void 0);else if(t===`style`)B(e.dom,n,null);else if(z(e,t,r)&&t!==`className`&&t!==`title`&&!(t===`value`&&(e.tag===`option`||e.tag===`select`&&e.dom.selectedIndex===-1&&e.dom===d(e.dom)))&&!(e.tag===`input`&&t===`type`))e.dom[t]=null;else{var i=t.indexOf(`:`);i!==-1&&(t=t.slice(i+1)),n!==!1&&e.dom.removeAttribute(t===`className`?`class`:t)}}function ae(e,t){if(`value`in t)if(t.value===null)e.dom.selectedIndex!==-1&&(e.dom.value=null);else{var n=``+t.value;(e.dom.value!==n||e.dom.selectedIndex===-1)&&(e.dom.value=n)}`selectedIndex`in t&&R(e,`selectedIndex`,null,t.selectedIndex,void 0)}function oe(e,t,n,r){var i;if(t!=null)for(var o in t===n&&!a.has(n)&&console.warn(`Don't reuse attrs object, use new object for every redraw, this will throw in next major`),t)(i=t[o])!=null&&(n==null||n[o]==null)&&ie(e,o,i,r);if(n!=null)for(var o in n)R(e,o,t&&t[o],n[o],r)}function se(e,t){return t===`value`||t===`checked`||t===`selectedIndex`||t===`selected`&&(e.dom===d(e.dom)||e.tag===`option`&&e.dom.parentNode===d(e.dom))}function ce(e){return e===`oninit`||e===`oncreate`||e===`onupdate`||e===`onremove`||e===`onbeforeremove`||e===`onbeforeupdate`}function z(e,t,n){return n===void 0&&(e.tag.indexOf(`-`)>-1||e.is||t!==`href`&&t!==`list`&&t!==`form`&&t!==`width`&&t!==`height`)&&t in e.dom}function B(e,t,n){if(t!==n)if(n==null)e.style=``;else if(typeof n!=`object`)e.style=n;else if(typeof t!=`object`||!t)for(var r in e.style=``,n){var i=n[r];i!=null&&(r.includes(`-`)?e.style.setProperty(r,String(i)):e.style[r]=String(i))}else{for(var r in t)t[r]!=null&&n[r]==null&&(r.includes(`-`)?e.style.removeProperty(r):e.style[r]=``);for(var r in n){var i=n[r];i!=null&&(i=String(i))!==String(t[r])&&(r.includes(`-`)?e.style.setProperty(r,i):e.style[r]=i)}}}function V(){this._=t}V.prototype=Object.create(null),V.prototype.handleEvent=function(e){var t=this[`on`+e.type],n;typeof t==`function`?n=t.call(e.currentTarget,e):typeof t.handleEvent==`function`&&t.handleEvent(e);var r=this;r._!=null&&(e.redraw!==!1&&(0,r._)(),n!=null&&typeof n.then==`function`&&Promise.resolve(n).then(function(){r._!=null&&e.redraw!==!1&&(0,r._)()})),n===!1&&(e.preventDefault(),e.stopPropagation())};function le(e,n,r){if(e.events!=null){if(e.events._=t,e.events[n]===r)return;r!=null&&(typeof r==`function`||typeof r==`object`)?(e.events[n]??e.dom.addEventListener(n.slice(2),e.events,!1),e.events[n]=r):(e.events[n]!=null&&e.dom.removeEventListener(n.slice(2),e.events,!1),e.events[n]=void 0)}else r!=null&&(typeof r==`function`||typeof r==`object`)&&(e.events=new V,e.dom.addEventListener(n.slice(2),e.events,!1),e.events[n]=r)}function H(e,t,n){typeof e.oninit==`function`&&u.call(e.oninit,t),typeof e.oncreate==`function`&&n.push(u.bind(e.oncreate,t))}function U(e,t,n){typeof e.onupdate==`function`&&n.push(u.bind(e.onupdate,t))}function W(e,t){do{if(e.attrs!=null&&typeof e.attrs.onbeforeupdate==`function`){var n=u.call(e.attrs.onbeforeupdate,e,t);if(n!==void 0&&!n)break}if(typeof e.tag!=`string`&&typeof e.state.onbeforeupdate==`function`){var n=u.call(e.state.onbeforeupdate,e,t);if(n!==void 0&&!n)break}return!1}while(!1);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}var G;return function(e,r,i){if(!e)throw TypeError(`DOM element being rendered to does not exist.`);if(G!=null&&e.contains(G))throw TypeError(`Node is currently being rendered to and thus is locked.`);var a=t,s=G,c=[],l=d(e),u=e.namespaceURI;G=e,t=typeof i==`function`?i:void 0,o={};try{e.vnodes??(e.textContent=``),r=n.normalizeChildren(Array.isArray(r)?r:[r]),x(e,e.vnodes,r,c,null,u===`http://www.w3.org/1999/xhtml`?void 0:u),e.vnodes=r,l!=null&&d(e)!==l&&typeof l.focus==`function`&&l.focus();for(var f=0;f<c.length;f++)c[f]()}finally{t=a,G=s}}}})),C=c(((e,t)=>{t.exports=S()()})),w=c(((e,t)=>{var n=d();t.exports=function(e,t,r){var i=[],a=!1,o=-1;function s(){for(o=0;o<i.length;o+=2)try{e(i[o],n(i[o+1]),c)}catch(e){r.error(e)}o=-1}function c(){a||(a=!0,t(function(){a=!1,s()}))}c.sync=s;function l(t,r){if(r!=null&&r.view==null&&typeof r!=`function`)throw TypeError(`m.mount expects a component, not a vnode.`);var a=i.indexOf(t);a>=0&&(i.splice(a,2),a<=o&&(o-=2),e(t,[])),r!=null&&(i.push(t,r),e(t,n(r),c))}return{mount:l,redraw:c}}})),T=c(((e,t)=>{var n=C();t.exports=w()(n,typeof requestAnimationFrame<`u`?requestAnimationFrame:null,typeof console<`u`?console:null)})),E=c(((e,t)=>{t.exports=function(e){if(Object.prototype.toString.call(e)!==`[object Object]`)return``;var t=[];for(var n in e)r(n,e[n]);return t.join(`&`);function r(e,n){if(Array.isArray(n))for(var i=0;i<n.length;i++)r(e+`[`+i+`]`,n[i]);else if(Object.prototype.toString.call(n)===`[object Object]`)for(var i in n)r(e+`[`+i+`]`,n[i]);else t.push(encodeURIComponent(e)+(n!=null&&n!==``?`=`+encodeURIComponent(n):``))}}})),D=c(((e,t)=>{var n=E();t.exports=function(e,t){if(/:([^\/\.-]+)(\.{3})?:/.test(e))throw SyntaxError(`Template parameter names must be separated by either a '/', '-', or '.'.`);if(t==null)return e;var r=e.indexOf(`?`),i=e.indexOf(`#`),a=i<0?e.length:i,o=r<0?a:r,s=e.slice(0,o),c={};Object.assign(c,t);var l=s.replace(/:([^\/\.-]+)(\.{3})?/g,function(e,n,r){return delete c[n],t[n]==null?e:r?t[n]:encodeURIComponent(String(t[n]))}),u=l.indexOf(`?`),d=l.indexOf(`#`),f=d<0?l.length:d,p=u<0?f:u,m=l.slice(0,p);r>=0&&(m+=e.slice(r,a)),u>=0&&(m+=(r<0?`?`:`&`)+l.slice(u,f));var h=n(c);return h&&(m+=(r<0&&u<0?`?`:`&`)+h),i>=0&&(m+=e.slice(i)),d>=0&&(m+=(i<0?``:`&`)+l.slice(d)),m}})),O=c(((e,t)=>{var n=D(),r=p();t.exports=function(e,t){function i(e){return new Promise(e)}function a(t,i){return new Promise(function(a,s){t=n(t,i.params);var c=i.method==null?`GET`:i.method.toUpperCase(),l=i.body,u=(i.serialize==null||i.serialize===JSON.serialize)&&!(l instanceof e.FormData||l instanceof e.URLSearchParams),d=i.responseType||(typeof i.extract==`function`?``:`json`),f=new e.XMLHttpRequest,p=!1,m=!1,h=f,g,_=f.abort;for(var v in f.abort=function(){p=!0,_.call(this)},f.open(c,t,i.async!==!1,typeof i.user==`string`?i.user:void 0,typeof i.password==`string`?i.password:void 0),u&&l!=null&&!o(i,`content-type`)&&f.setRequestHeader(`Content-Type`,`application/json; charset=utf-8`),typeof i.deserialize!=`function`&&!o(i,`accept`)&&f.setRequestHeader(`Accept`,`application/json, text/*`),i.withCredentials&&(f.withCredentials=i.withCredentials),i.timeout&&(f.timeout=i.timeout),f.responseType=d,i.headers)r.call(i.headers,v)&&f.setRequestHeader(v,i.headers[v]);f.onreadystatechange=function(e){if(!p&&e.target.readyState===4)try{var n=e.target.status>=200&&e.target.status<300||e.target.status===304||/^file:\/\//i.test(t),r=e.target.response,o;if(d===`json`){if(!e.target.responseType&&typeof i.extract!=`function`)try{r=JSON.parse(e.target.responseText)}catch{r=null}}else (!d||d===`text`)&&(r??=e.target.responseText);if(typeof i.extract==`function`?(r=i.extract(e.target,i),n=!0):typeof i.deserialize==`function`&&(r=i.deserialize(r)),n){if(typeof i.type==`function`)if(Array.isArray(r))for(var c=0;c<r.length;c++)r[c]=new i.type(r[c]);else r=new i.type(r);a(r)}else{var l=function(){try{o=e.target.responseText}catch{o=r}var t=Error(o);t.code=e.target.status,t.response=r,s(t)};f.status===0?setTimeout(function(){m||l()}):l()}}catch(e){s(e)}},f.ontimeout=function(e){m=!0;var t=Error(`Request timed out`);t.code=e.target.status,s(t)},typeof i.config==`function`&&(f=i.config(f,i,t)||f,f!==h&&(g=f.abort,f.abort=function(){p=!0,g.call(this)})),l==null?f.send():typeof i.serialize==`function`?f.send(i.serialize(l)):l instanceof e.FormData||l instanceof e.URLSearchParams?f.send(l):f.send(JSON.stringify(l))})}i.prototype=Promise.prototype,i.__proto__=Promise;function o(e,t){for(var n in e.headers)if(r.call(e.headers,n)&&n.toLowerCase()===t)return!0;return!1}return{request:function(e,n){typeof e==`string`?n??={}:(n=e,e=e.url);var r=a(e,n);if(n.background===!0)return r;var o=0;function s(){--o===0&&typeof t==`function`&&t()}return c(r);function c(e){var t=e.then;return e.constructor=i,e.then=function(){o++;var n=t.apply(e,arguments);return n.then(s,function(e){if(s(),o===0)throw e}),c(n)},e}}}}})),k=c(((e,t)=>{var n=T();t.exports=O()(typeof window<`u`?window:null,n.redraw)})),A=c(((e,t)=>{var n=/%(?:[0-7]|(?!c[01]|e0%[89]|ed%[ab]|f0%8|f4%[9ab])(?:c|d|(?:e|f[0-4]%[89ab])[\da-f]%[89ab])[\da-f]%[89ab])[\da-f]/gi;t.exports=function(e){return String(e).replace(n,decodeURIComponent)}})),j=c(((e,t)=>{var n=A();t.exports=function(e){if(e===``||e==null)return{};e.charAt(0)===`?`&&(e=e.slice(1));for(var t=e.split(`&`),r={},i={},a=0;a<t.length;a++){var o=t[a].split(`=`),s=n(o[0]),c=o.length===2?n(o[1]):``;c===`true`?c=!0:c===`false`&&(c=!1);var l=s.split(/\]\[?|\[/),u=i;s.indexOf(`[`)>-1&&l.pop();for(var d=0;d<l.length;d++){var f=l[d],p=l[d+1],m=p==``||!isNaN(parseInt(p,10));if(f===``){var s=l.slice(0,d).join();r[s]??(r[s]=Array.isArray(u)?u.length:0),f=r[s]++}else if(f===`__proto__`)break;if(d===l.length-1)u[f]=c;else{var h=Object.getOwnPropertyDescriptor(u,f);h!=null&&(h=h.value),h??(u[f]=h=m?[]:{}),u=h}}}return i}})),M=c(((e,t)=>{var n=j();t.exports=function(e){var t=e.indexOf(`?`),r=e.indexOf(`#`),i=r<0?e.length:r,a=t<0?i:t,o=e.slice(0,a).replace(/\/{2,}/g,`/`);return o?o[0]!==`/`&&(o=`/`+o):o=`/`,{path:o,params:t<0?{}:n(e.slice(t+1,i))}}})),N=c(((e,t)=>{var n=M();t.exports=function(e){var t=n(e),r=Object.keys(t.params),i=[],a=RegExp(`^`+t.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,function(e,t,n){return t==null?`\\`+e:(i.push({k:t,r:n===`...`}),n===`...`?`(.*)`:n===`.`?`([^/]+)\\.`:`([^/]+)`+(n||``))})+`\\/?$`);return function(e){for(var n=0;n<r.length;n++)if(t.params[r[n]]!==e.params[r[n]])return!1;if(!i.length)return a.test(e.path);var o=a.exec(e.path);if(o==null)return!1;for(var n=0;n<i.length;n++)e.params[i[n].k]=i[n].r?o[n+1]:decodeURIComponent(o[n+1]);return!0}}})),P=c(((e,t)=>{var n=p(),r=/^(?:key|oninit|oncreate|onbeforeupdate|onupdate|onbeforeremove|onremove)$/;t.exports=function(e,t){var i={};if(t!=null)for(var a in e)n.call(e,a)&&!r.test(a)&&t.indexOf(a)<0&&(i[a]=e[a]);else for(var a in e)n.call(e,a)&&!r.test(a)&&(i[a]=e[a]);return i}})),F=c(((e,t)=>{var n=d(),r=g(),i=A(),a=D(),o=M(),s=N(),c=P();t.exports=function(e,t){var l=Promise.resolve(),u=!1,d=!1,f=!1,p,m,h,g,_,v,y,b,x={onremove:function(){d=f=!1,e.removeEventListener(`popstate`,w,!1)},view:function(){var e=n(_,v.key,v);return g?g.render(e):[e]}},S=T.SKIP={};function C(){u=!1;var n=e.location.hash;T.prefix[0]!==`#`&&(n=e.location.search+n,T.prefix[0]!==`?`&&(n=e.location.pathname+n,n[0]!==`/`&&(n=`/`+n)));var r=i(n).slice(T.prefix.length),a=o(r);Object.assign(a.params,e.history.state);function s(e){console.error(e),T.set(h,null,{replace:!0})}c(0);function c(e){for(;e<m.length;e++)if(m[e].check(a)){var n=m[e].component,i=m[e].route,o=n,u=b=function(i){if(u===b){if(i===S)return c(e+1);_=i!=null&&(typeof i.view==`function`||typeof i==`function`)?i:`div`,v=a.params,y=r,b=null,g=n.render?n:null,f?t.redraw():(f=!0,t.mount(p,x))}};n.view||typeof n==`function`?(n={},u(o)):n.onmatch?l.then(function(){return n.onmatch(a.params,r,i)}).then(u,r===h?null:s):u();return}if(r===h)throw Error(`Could not resolve default route `+h+`.`);T.set(h,null,{replace:!0})}}function w(){u||(u=!0,setTimeout(C))}function T(t,n,r){if(!t)throw TypeError(`DOM element being rendered to does not exist.`);if(m=Object.keys(r).map(function(e){if(e[0]!==`/`)throw SyntaxError(`Routes must start with a '/'.`);if(/:([^\/\.-]+)(\.{3})?:/.test(e))throw SyntaxError(`Route parameter names must be separated with either '/', '.', or '-'.`);return{route:e,component:r[e],check:s(e)}}),h=n,n!=null){var i=o(n);if(!m.some(function(e){return e.check(i)}))throw ReferenceError(`Default route doesn't match any known routes.`)}p=t,e.addEventListener(`popstate`,w,!1),d=!0,C()}return T.set=function(t,n,r){if(b!=null&&(r||={},r.replace=!0),b=null,t=a(t,n),d){w();var i=r?r.state:null,o=r?r.title:null;r&&r.replace?e.history.replaceState(i,o,T.prefix+t):e.history.pushState(i,o,T.prefix+t)}else e.location.href=T.prefix+t},T.get=function(){return y},T.prefix=`#!`,T.Link={view:function(e){var t=r(e.attrs.selector||`a`,c(e.attrs,[`options`,`params`,`selector`,`onclick`]),e.children),n,i,o;return(t.attrs.disabled=!!t.attrs.disabled)?(t.attrs.href=null,t.attrs[`aria-disabled`]=`true`):(n=e.attrs.options,i=e.attrs.onclick,o=a(t.attrs.href,e.attrs.params),t.attrs.href=T.prefix+o,t.attrs.onclick=function(e){var t;typeof i==`function`?t=i.call(e.currentTarget,e):typeof i!=`object`||!i||typeof i.handleEvent==`function`&&i.handleEvent(e),t!==!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,T.set(o,null,n))}),t}},T.param=function(e){return v&&e!=null?v[e]:v},T}})),ee=c(((e,t)=>{var n=T();t.exports=F()(typeof window<`u`?window:null,n)})),I=u(c(((e,t)=>{var n=y(),r=T(),i=k(),a=ee(),o=function(){return n.apply(this,arguments)};o.m=n,o.trust=n.trust,o.fragment=n.fragment,o.Fragment=`[`,o.mount=r.mount,o.route=a,o.render=C(),o.redraw=r.redraw,o.request=i.request,o.parseQueryString=j(),o.buildQueryString=E(),o.parsePathname=M(),o.buildPathname=D(),o.vnode=d(),o.censor=P(),o.domFor=x(),t.exports=o}))(),1);function L(e,t){return(0,I.default)(R,e,t)}function te(e,t){return(0,I.default)(ie,e,t)}function ne(e,t){return(0,I.default)(ae,e,t)}function re(e,t){return(0,I.default)(oe,e,t)}var R=()=>({view:({attrs:{start:e,end:t,...n},children:r})=>(0,I.default)(`div.twk-bar`,n,[e?(0,I.default)(ie,e):null,r,t?(0,I.default)(ae,t):null])}),ie=()=>({view:({attrs:e,children:t})=>(0,I.default)(`div.twk-bar-start`,e,t)}),ae=()=>({view:({attrs:e,children:t})=>(0,I.default)(`div.twk-bar-end`,e,t)}),oe=()=>({view:({attrs:e,children:t})=>(0,I.default)(`div.twk-bar-content`,e,t)});function se(e,t){return(0,I.default)(ce,e,t)}var ce=()=>({view:e=>{let t=e.attrs;return(0,I.default)(`div.twk-grid`,{style:{gridTemplateColumns:typeof t.columns==`number`?`repeat(${t.columns}, 1fr)`:t.columns||`none`,gridTemplateRows:typeof t.rows==`number`?`repeat(${t.rows}, 1fr)`:t.rows||`none`,...t.style||{}}},e.children)}});function z(e){return typeof e==`string`}function B(e){return typeof e==`number`}function V(e){return typeof e==`function`}function le(e){return Array.isArray(e)}function H(e){return typeof e==`object`&&!!e&&!le(e)}function U(e,...t){return V(e)?e(...t):null}function W(e,t,n){if(e!=null){if(t!=null&&e<t)return t;if(n!=null&&e>n)return n}return e}function G(){if(arguments.length===1&&z(arguments[0]))return arguments[0];if(arguments.length===0)return``;let e=[],t=n=>{if(n){if(typeof n==`function`){t(n());return}if(typeof n==`string`){n&&e.push(n);return}if(Array.isArray(n)){for(let e of n)t(e);return}if(typeof n==`object`)for(let t in n){let r=n[t];(typeof r==`function`?r():r)&&e.push(t)}}};for(let e of arguments)t(e);return e.join(` `)}function ue(e,t,n){for(;e.length<t;)e=`${n}${e}`;return e}function de(e){let t=0,n=0;return`touches`in e?(t=e.touches.item(0).pageX,n=e.touches.item(0).pageY):(t=e.pageX,n=e.pageY),[t,n]}function fe(e,t,n){t||=e.target;let r=t.getBoundingClientRect(),i=window.pageXOffset||document.documentElement.scrollLeft,a=window.pageYOffset||document.documentElement.scrollTop,o=t.clientWidth,s=t.clientHeight,[c,l]=de(e);n&&(c+=n[0],l+=n[1]);let u=c-i-r.left,d=l-a-r.top;return{width:o,height:s,x:u,y:d,normalizedX:u/o,normalizedY:d/s}}function pe({onStart:e,onMove:t,onEnd:n}){let r={target:null,activate:i=>{r.deactivate(),r.target=i.target,e&&e(i),t&&(document.addEventListener(`mousemove`,t,{passive:!1}),document.addEventListener(`touchmove`,t,{passive:!1})),n&&(document.addEventListener(`mouseup`,n),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n))},deactivate:()=>{r.target=null,t&&(document.removeEventListener(`mousemove`,t),document.removeEventListener(`touchmove`,t)),n&&(document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n))},onStart:e,onMove:t,onEnd:n};return r}function me(e,t,n){return new Promise(r=>{let i=!1,a=n=>{i=!0,e.removeEventListener(t,a),r(!0)};e.addEventListener(t,a),setTimeout(()=>{e.removeEventListener(t,a),i||(i=!0,r(!1))},n)})}function he(e,t){return(0,I.default)(ge,e,t)}var ge=()=>{let e,t,n,r,i=!1;function a(t){let i=t.attrs;e=i.title||``,n=!!i.collapsible,r??=!!i.collapsed}function o(){i=!0,r=!r}function s(){return!t&&!e&&!n?null:(0,I.default)(`div.twk-group-title`,{onclick:n?o:void 0},t,e)}return{oninit:a,onupdate:a,view:({attrs:a,children:o})=>(e=a.title||``,t=a.icon||``,n=!!a.collapsible,r??=!!a.collapsed,(0,I.default)(`div.twk-group`,{class:G({"twk-group-collapsible":!!n,"twk-group-collapsed":!!r}),style:a.style},I.default.fragment({},[s()]),r?null:(0,I.default)(_e,{animate:i},o)))}},_e=()=>({onbeforeremove:async({dom:e})=>{e.classList.remove(`enter`),e.classList.add(`leave`),await me(e,`animationstart`,50)&&await me(e,`animationend`,2e3)},view:({children:e,attrs:t})=>(0,I.default)(`div.twk-group-content`,{class:G({animate:t.animate,enter:!0})},e)});function ve(e,t){return(0,I.default)(ye,e,t)}var ye=()=>({view:({attrs:{flex:e,flow:t,style:n,...r},children:i})=>(0,I.default)(`div.twk-flex`,{style:{flex:e??`auto`,flexFlow:t||`column nowrap`,...n||{}},...r},i)});function be(e,t){return(0,I.default)(we,e,t)}function xe(e,t){return(0,I.default)(Te,e,t)}function Se(e,t){return(0,I.default)(Ee,e,t)}function Ce(e,t){return(0,I.default)(De,e,t)}var we=()=>({view:({attrs:{header:e,footer:t,...n},children:r})=>(0,I.default)(`div.twk-section`,n,[e?(0,I.default)(Te,e):null,r,t?(0,I.default)(Ee,t):null])}),Te=()=>({view:({attrs:e,children:t})=>(0,I.default)(`header.twk-section-header`,e,t)}),Ee=()=>({view:({attrs:e,children:t})=>(0,I.default)(`footer.twk-section-footer`,e,t)}),De=()=>({view:({attrs:e,children:t})=>(0,I.default)(`main.twk-section-content`,e,t)});function K(e){return Me(e,Oe(e))}function q(e,t){let n=je(e,t);return ke(e,n),n}function Oe(e){return e.binding?e.binding.get(e.value,e.field):e.value==null?null:e.field==null?e.value:e.value[e.field]}function ke(e,t){if(e.binding){e.binding.set?.(t,e.value,e.field);return}if(e.value!=null){if(e.field){if(!Ae(e.value,e.field)){console.warn(`Cannot write value to control model. Property "${String(e.field)}" is not writeable.`);return}e.value[e.field]=t;return}e.value=t}}function Ae(e,t){let n=Object.getOwnPropertyDescriptor(e,t);return!n||!!n.writable||!!n.set}function je(e,t){return e.adapter?e.adapter.fromControl(t):t}function Me(e,t){return e.adapter?e.adapter.toControl(t):t}function Ne(e){return typeof e==`object`&&!!e&&`tag`in e}function Pe(e,t){return Array.isArray(e)?e.map((e,n,r)=>Ne(e)?t(e,n,r):e):Ne(e)?t(e,0,[e]):e}function Fe(e){return e==null?null:typeof e==`function`?e():Array.isArray(e)?e.map(e=>{if(Ie(e)){let{component:t,attributes:n,children:r}=e;return(0,I.default)(t,n,Fe(r||[]))}return e}):e}function Ie(e){return typeof e==`object`&&!!e&&`component`in e&&`attributes`in e}function Le(e){return()=>{let t;return arguments.length===1?t=arguments[0]||{}:arguments.length>1?(t=arguments[1]||{},t.label=arguments[0]):t={},(0,I.default)(e,t)}}function Re(e,t){return{get:()=>e[t],set:n=>e[t]=n}}var ze=I.default;function Be(e,t){let n=typeof e==`string`?document.querySelector(e):e;if(n.classList.add(`tweak-ui`),!t)I.default.mount(n,null);else if(Array.isArray(t))I.default.mount(n,{view:()=>t});else if(typeof t==`function`){let e=Kn.build(t);I.default.mount(n,{view:()=>Fe(e)})}else I.default.mount(n,t)}function Ve(e){let t=typeof e==`string`?document.querySelector(e):e;I.default.mount(t,null)}function He(){I.default.redraw()}function Ue(e,t){return(0,I.default)(Ke,e,t)}function We(e,t){return(0,I.default)(Ge,e,t)}var Ge=e=>({view:({attrs:e,children:t})=>ze(`div`,{...e,class:G({fluid:!!e.fluid},e.class)},t)}),Ke=()=>{let e=!1,t=0,n,r,i,a,o,s=null,c=null;function l(e,t,s,c){f(),e.stopPropagation(),n=e,r=s.dom?.getBoundingClientRect(),i=c.dom?.getBoundingClientRect(),a=s.dom,o=c.dom,window.addEventListener(`mousemove`,u),window.addEventListener(`mouseup`,f);let l=a.parentElement;l&&l.classList.add(`dragging`)}function u(c){if(!r||!i||!n||!a||!o)return;s??=d();let l=e?c.clientX-n.clientX:c.clientY-n.clientY,u=e?r.width:r.height,f=u+(e?i.width:i.height),p=Math.max(t,Math.min(u+l,f-t)),m=f-p,h=p/s*100,g=m/s*100;a.style.flex=`0 0 ${h}%`,o.style.flex=`0 0 ${g}%`}function d(){if(!c)return 0;let t=0;for(let n=0;n<c.children.length;n++){let r=c.children[n],i=r.getBoundingClientRect(),a=e?i.width:i.height;t+=a,r.classList.contains(`fluid`)?r.style.flex=`1`:r.style.flex=`0 0 ${a}px`}return t}function f(){let e=a?.parentElement;e&&e.classList.remove(`dragging`),a=null,o=null,r=null,i=null,n=null,s=null,window.removeEventListener(`mousemove`,u),window.removeEventListener(`mouseup`,f),d()}return{oncreate:({dom:e})=>{c=e},view:({attrs:{style:n,flow:r,minSize:i,...a},children:o})=>(e=r===`row`,t=i=Math.max(i||16,0),queueMicrotask(d),(0,I.default)(`div.twk-split-pane`,{...a,class:G({"twk-split-pane-h":e,"twk-split-pane-v":!e}),style:{...n||{},display:`flex`,flexDirection:e?`row`:`column`}},Pe(o,(t,n,r)=>t?[t,r[n+1]?(0,I.default)(`div.twk-split-gutter`,{class:G({"twk-split-gutter-h":e,"twk-split-gutter-v":!e}),onmousedown:e=>l(e,n,t,r[n+1])}):null]:null)))}},qe=Symbol(`tabsHost`),Je=()=>{let e,t;return{oninit:n=>{if(e=n.attrs[qe],t=n,!e)throw Error(`TabPane must be used inside a Tabs component`);e.attach(n)},onremove:()=>{e.detach(t)},view:({attrs:n,children:r})=>{let i=n.title,a=e.isActive(t);return[(0,I.default)(`button.twk-btn.twk-tab`,{class:G({active:a}),onclick:()=>e.activate(t)},i),a?(0,I.default)(`div.twk-tab-content`,{},r):null]}}};function Ye(e,t){return(0,I.default)(Xe,e,t)}var Xe=()=>{let e=[],t=null,n={attach(n){e.push(n),t||=n,n.attrs.active&&(t=n)},detach(n){let r=e.indexOf(n);r>=0&&e.splice(r,1),t===n&&(t=e[0]||null)},activate(e){t=e},isActive(e){return t===e}};function r(e){return Pe(e.children,e=>{if(!e)return e;if(e.tag===Je)return(0,I.default)(e.tag,{...e.attrs,[qe]:n},e.children);let t=e.attrs;return(0,I.default)(Je,{title:t.title||``,[qe]:n},(0,I.default)(e.tag,{...t,title:void 0},e.children))})}return{view:e=>(0,I.default)(`div.twk-tabs`,{class:G({"twk-tabs-vertical":!!e.attrs.vertical})},I.default.fragment({},[r(e)]))}};function Ze(e){return(0,I.default)(et,e)}function Qe(e,t,n=0,r=[]){for(let i of e){let e=t.isExpanded(i)??!1,a=t.nodeChildren(i);r.push({node:i,depth:n,expanded:e}),a&&e&&Qe(a,t,n+1,r)}return r}var $e=22,et=()=>{let e=0,t=null,n=0,r=[],i=null,a,o,s,c=[],l=null;return{onremove(){t?.disconnect()},oncreate({dom:e}){t=new ResizeObserver(e=>{let t=e[0].contentRect.height;t!==n&&(n=t,I.default.redraw())}),t.observe(e)},onupdate({attrs:{adapter:e}}){e.connect?.({scrollTo(e){let t=r.findIndex(t=>t.node===e);t>=0&&(l?.scrollTo({top:t*(o??$e),behavior:`instant`}),I.default.redraw())}})},view({attrs:t}){c=t.data,i=t.adapter,a=t.selectedId,o=t.rowHeight??$e,s=t.onSelect,r=Qe(c,i);let u=r.length,d=Math.ceil(n/o),f=Math.floor(e/o),p=Math.min(f+d,u),m=f*o,h=r.slice(f,p);return(0,I.default)(`div.twk-tree`,{style:t.style??{},oncreate:({dom:e})=>{l=e},onscroll:t=>{e=t.target.scrollTop}},(0,I.default)(`div.twk-tree-spacer`,{style:{height:`${u*o}px`}},(0,I.default)(`div.twk-tree-viewport`,{style:{"--twk-tree-row-height":`${o}px`,transform:`translateY(${m}px)`}},h.map(({node:e,depth:t,expanded:n})=>{let r=i.nodeId(e),c=r===a,l=i.nodeIcon(e,i.isExpanded(e)),u=!!i.nodeChildren(e);return(0,I.default)(`div.twk-tree-row`,{key:r,class:G({selected:c,expandable:u}),style:{height:`${o}px`,"--twk-tree-row-depth":t},onclick:()=>s?.(e)},[(0,I.default)(`span.twk-tree-toggle`,{class:G({expanded:n,expandable:u}),onclick:t=>{u&&(t.stopPropagation(),i.setExpanded(e,!n))}}),l?(0,I.default)(`span.twk-tree-icon`,{},l):null,(0,I.default)(`span.twk-tree-label`,{},i.nodeLabel(e))])}))))}}};function tt(e,t){return(0,I.default)(nt,e,t)}var nt=()=>{let e=null;return{oncreate:({dom:t})=>{e=t,e.addEventListener(`close`,He)},onremove:()=>{e?.removeEventListener(`close`,He),e=null},view:({attrs:t,children:n})=>(0,I.default)(`dialog.twk-dialog`,t,[e?.open?n:null])}};function rt(e,t){return(0,I.default)(it,e,t)}var it=()=>({view:({attrs:e,children:t})=>{let{square:n,block:r,class:i,style:a,...o}=e;return(0,I.default)(`button.twk-btn`,{type:`button`,class:G({"twk-btn-sq":!!n,"twk-btn-bl":!!r,"twk-btn-lg":!!e.large,"twk-btn-accent":!!e.accent},i),style:{flex:e.flex,...a||{}},...o},t)}});function at(e){return(0,I.default)(ot,e)}var ot=()=>({view:e=>(0,I.default)(`div.twk-divider`,e.attrs,e.children)});function st(e,t){let n={color:e.color,noGraph:e.noGraph,fractionDigits:e.fractionDigits,smoothing:e.smoothing??0,transform:ut,min:e.min??0,max:e.max??1,value:null,normalized:0,buffer:new Float32Array(t),head:0,count:0,index:0,sum:0,avg:0,minDeque:new Float32Array(t),maxDeque:new Float32Array(t),minIdx:new Uint32Array(t),maxIdx:new Uint32Array(t),minHead:0,minTail:0,maxHead:0,maxTail:0,minSeen:1/0,maxSeen:-1/0,sample:()=>dt(e.sample(),n)};switch(e.transform){case`log`:n.transform=ct;break;case`exp`:n.transform=lt;break;default:n.transform=ut;break}return n}function ct(e){return Math.log10(1+Math.max(0,e))}function lt(e){return Math.exp(e)-1}function ut(e){return e}function dt(e,t){if(t.value==null)t.value=e;else{let n=t.smoothing;t.value=n*t.value+(1-n)*e}let n=t.value,r=t.index++,i=t.buffer.length;if(t.count===i){let e=t.buffer[t.head];t.sum-=e}else t.count++;for(t.buffer[t.head]=n,t.head=(t.head+1)%i,t.sum+=n,t.avg=t.sum/t.count;t.minHead!==t.minTail;){let e=(t.minTail-1+i)%i;if(t.minDeque[e]<=n)break;t.minTail=e}for(t.minDeque[t.minTail]=n,t.minIdx[t.minTail]=r,t.minTail=(t.minTail+1)%i;t.minHead!==t.minTail&&t.minIdx[t.minHead]<=r-i;)t.minHead=(t.minHead+1)%i;for(;t.maxHead!==t.maxTail;){let e=(t.maxTail-1+i)%i;if(t.maxDeque[e]>=n)break;t.maxTail=e}for(t.maxDeque[t.maxTail]=n,t.maxIdx[t.maxTail]=r,t.maxTail=(t.maxTail+1)%i;t.maxHead!==t.maxTail&&t.maxIdx[t.maxHead]<=r-i;)t.maxHead=(t.maxHead+1)%i;let a=t.minHead===t.minTail?t.min:t.minDeque[t.minHead],o=t.maxHead===t.maxTail?t.max:t.maxDeque[t.maxHead];t.minSeen=a,t.maxSeen=o;let s=t.transform,c=s(n),l=s(Math.min(t.min,a)),u=s(Math.max(t.max,o))-l||1,d=(c-l)/u;return t.normalized=Math.max(0,Math.min(1,d)),t.normalized}function ft(e){let t=e.getContext(`webgl2`);if(!t)throw Error(`WebGL2 is not supported in this browser`);let n=gt(t),r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.enableVertexAttribArray(0),t.enableVertexAttribArray(1),t.enableVertexAttribArray(2),t.vertexAttribPointer(0,1,t.FLOAT,!1,12,0),t.vertexAttribPointer(1,1,t.FLOAT,!1,12,4),t.vertexAttribPointer(2,1,t.FLOAT,!1,12,8);let i=t.getUniformLocation(n,`u_history`),a=t.getUniformLocation(n,`u_width`),o=t.getUniformLocation(n,`u_height`),s=t.getUniformLocation(n,`u_rowH`),c=t.getUniformLocation(n,`u_padding`),l=t.getUniformLocation(n,`u_color`),u=!1,d=100,f=0,p,m,h,g=[],_=[];function v(e){u=!!e.collapsed,f=e.rows.length,d=Math.max(e.historySize||100,100),m=new Float32Array(f*d),h=new Uint32Array(f),p=new Float32Array(f*d*3),_.length=f,g.length=f;for(let t=0;t<f;t++){_[t]=st(e.rows[t],d);let n=e.rows[t].color;g[t]=[parseInt(n.slice(1,3),16)/255,parseInt(n.slice(3,5),16)/255,parseInt(n.slice(5,7),16)/255]}}function y(t,n){e.width=t,e.height=n}function b(){for(let e=0;e<_.length;e++)h[e]=(h[e]+1)%d,m[e*d+h[e]]=_[e].sample()}function x(){for(let e=0;e<f;e++)for(let t=0;t<d;t++){let n=(h[e]+t+1)%d,r=(e*d+t)*3;p[r+0]=t,p[r+1]=u?0:e,p[r+2]=m[e*d+n]}t.viewport(0,0,e.width,e.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.useProgram(n),t.uniform1f(i,d),t.uniform1f(a,e.width),t.uniform1f(o,e.height),t.uniform1f(c,0),t.uniform1f(s,(e.height-0-f*0)/(u?1:f)),t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,p,t.DYNAMIC_DRAW);for(let e=0;e<f;e++)_[e].noGraph||(t.uniform3fv(l,g[e]),t.drawArrays(t.LINE_STRIP,e*d,d))}return{resize:y,configure:v,update:b,render:x,sampler:e=>_[e],samplerCount:_.length}}var pt=`#version 300 es
3
+ precision highp float;
4
+
5
+ layout(location=0) in float a_x;
6
+ layout(location=1) in float a_row;
7
+ layout(location=2) in float a_value;
8
+
9
+ uniform float u_history;
10
+ uniform float u_width;
11
+ uniform float u_height;
12
+ uniform float u_padding;
13
+ uniform float u_rowH;
14
+
15
+ void main() {
16
+ float x = u_padding + (a_x / (u_history - 1.0)) * (u_width - 2.0 * u_padding);
17
+ float yBase = u_padding + a_row * (u_rowH + u_padding);
18
+ float y = yBase + u_rowH - 2.0 - a_value * (u_rowH - 4.0);
19
+
20
+ float ndcX = (x / u_width) * 2.0 - 1.0;
21
+ float ndcY = 1.0 - (y / u_height) * 2.0;
22
+
23
+ gl_Position = vec4(ndcX, ndcY, 0.0, 1.0);
24
+ }
25
+ `,mt=`#version 300 es
26
+ precision highp float;
27
+ uniform vec3 u_color;
28
+ out vec4 outColor;
29
+ void main(){
30
+ outColor = vec4(u_color,1.0);
31
+ }
32
+ `;function ht(e,t,n){let r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw e.getShaderInfoLog(r);return r}function gt(e){let t=e.createProgram();return e.attachShader(t,ht(e,e.VERTEX_SHADER,pt)),e.attachShader(t,ht(e,e.FRAGMENT_SHADER,mt)),e.linkProgram(t),e.useProgram(t),t}function _t(e,t){return(0,I.default)(vt,e,t)}var vt=()=>{let e=null,t=null,n=null,r,i={rows:[]},a=[],o=null;function s(t){n=t,e?.observe(n),l(),o=setInterval(u,250)}function c(){e?.disconnect(),t!==null&&(cancelAnimationFrame(t),t=null),o!==null&&(clearInterval(o),o=null)}function l(){n?.isConnected?(r.update(),r.render(),t=requestAnimationFrame(l)):c()}function u(){bt(r,a)}function d({dom:t}){c();let n=t;if(!(n instanceof HTMLCanvasElement)){console.error(`Graph component must be a canvas element`);return}e=new ResizeObserver(e=>{let t=yt(e);t&&r&&r.resize(t.width,t.height)}),r=ft(n);for(let e=0;e<i.rows.length;e++)i.rows[e].color||=Ct(e);r.configure(i),s(n)}function f(){c()}function p(e){i={...e.attrs,rows:(e.attrs.rows||[]).map((e,t)=>({...e,name:e.name||`Row ${t+1}`,color:e.color||Ct(t)}))}}return{oninit:p,onupdate:p,onremove:()=>{c()},view:({attrs:{rowHeight:e,collapsed:t}})=>[(0,I.default)(`canvas.twk-graph`,{style:`width: 100%; height: ${(e||50)*(t?1:i.rows.length)*devicePixelRatio}px`,oncreate:d,onremove:f}),(0,I.default)(`table.twk-graph`,{},[(0,I.default)(`tbody`,{},i.rows.map((e,t)=>(0,I.default)(`tr`,{oncreate:({dom:e})=>a[t]=e},[(0,I.default)(`td`,{style:e.noGraph?{}:`color: ${e.color}`,title:e.name},[(0,I.default)(`span`,e.name)]),(0,I.default)(`td.twk-stats`,{title:`min / max / avg`},[]),(0,I.default)(`td.twk-current`,{})])))])]}};function yt(e){let t=e[0];return t.devicePixelContentBoxSize?{width:t.devicePixelContentBoxSize[0].inlineSize,height:t.devicePixelContentBoxSize[0].blockSize}:t.contentBoxSize?{width:Math.round(t.contentBoxSize[0].inlineSize*devicePixelRatio),height:Math.round(t.contentBoxSize[0].blockSize*devicePixelRatio)}:null}function bt(e,t){if(e)for(let n=0;n<t.length;n++){let r=t[n],i=e.sampler(n);if(!i||!r)continue;let a=r.querySelector(`.twk-current`),o=r.querySelector(`.twk-stats`);if(a&&(a.textContent=xt(i.value,i.fractionDigits)),o)if(i.noGraph)o.textContent=``;else{let e=i.fractionDigits;o.textContent=`${xt(i.minSeen,e)}/${xt(i.maxSeen,e)}/${xt(i.avg,e)}`}}}function xt(e,t){if(e==null)return`n/a`;if(t!=null)return e.toFixed(t);let n=Math.abs(e);return n<2**-52?`0`:n<1?e.toFixed(3):n<10?e.toFixed(2):n<100?e.toFixed(1):e.toFixed(0)}var St=[`#1F77B4`,`#FF7F0E`,`#2CA02C`,`#D62728`,`#9467BD`,`#8C564B`,`#E377C2`,`#7F7F7F`,`#5DA5DA`,`#F17CB0`,`#60BD68`,`#B2912F`,`#B276B2`,`#DECF3F`,`#F15854`,`#4D4D4D`,`#17BECF`,`#AEC7E8`,`#FFBB78`,`#98DF8A`];function Ct(e){return St[e%St.length]}function wt(e,t){return(0,I.default)(Tt,e,t)}var Tt=()=>{let e,t,n,r,i,a,o,s=0,c,l;function u(){return t!==c||e!==l}function d(e){return B(e)?`${e}px`:e}function f(e){return String(e||``)}function p(o){e=typeof o.src==`string`?o.src:``,t=o.src,n=o.render,i=f(o.aspect),r=d(o.width),a=o.fit||`fit`}async function m(){if(!o||!u())return;if(c=t,l=e,!n){o.src=e;return}s++;let r=s;o.classList.add(`twk-loading`);let i=await n(t);if(r!==s){i.close();return}await h(o,i),o.classList.remove(`twk-loading`)}async function h(e,t){let n=new OffscreenCanvas(t.width,t.height);n.getContext(`2d`).drawImage(t,0,0);let r=await n.convertToBlob({type:`image/png`});t.close();let i=URL.createObjectURL(r);URL.revokeObjectURL(e.src),e.src=i}function g(e){let{src:t,render:n,aspect:r,width:i,fit:a,...o}=e;return o}return{oninit({attrs:e}){p(e)},onbeforeupdate({attrs:e},t){p(e)},onupdate(){m()},view:({attrs:t})=>(0,I.default)(`img.twk-image`,{src:e,style:{width:r,aspectRatio:i,objectFit:a,...t.style||{}},onremove:()=>{o=null},oncreate:({dom:e})=>{o=e,m()},...g(t)})}},Et=()=>({view:e=>{let{label:t,tip:n,tagName:r,...i}=e.attrs;return[(0,I.default)(`${r||`div`}.twk-widget`,{...i},t===!1?null:(0,I.default)(`div.twk-widget-label`,{},t),e.children)]}});function J(e,t){return(0,I.default)(Et,e,t)}function Dt(e,t){return(0,I.default)(kt,e,t)}function Ot(e,t){return(0,I.default)(At,e,t)}var kt=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-scalar-widget`,label:e??n.field,class:t},[(0,I.default)(At,n)])}),At=()=>{let e,t,n,r,i,a,o,s=!1,c=!1,l=!1,u=!1,d;function f(o){(!d||o.attrs.decimals!==a.decimals)&&(d=new Intl.NumberFormat(`en-US`,{minimumFractionDigits:o.attrs.decimals??1,maximumFractionDigits:o.attrs.decimals??1,useGrouping:!1})),a=o.attrs,e=a.min,t=a.max,n=a.step,u=!!a.range,i=K(a),r=!!a.readonly,s=e!=null&&t!=null,c=n!=null,l=s||c}function p(n,r){i=isNaN(r)?null:W(r,e,t),q(a,i),(n===`input`?a.oninput:a.onchange)?.(a.value,i),I.default.redraw()}function m(){o=!0}function h(){o=!1}function g(e){let t=e.target;p(`input`,parseFloat(t.value))}function _(e){let t=e.target;p(`change`,parseFloat(t.value))}function v(r){return r=W(r,e,t),n!=null&&(r=Math.round(r/n)*n),parseFloat(r.toFixed(5))}function y(e){!l||r||S.activate(e)}let b,x,S=pe({onStart:e=>{b=i,x=fe(e,S.target).normalizedX},onMove:r=>{r.preventDefault(),S.target?.blur();let i=x-fe(r,S.target).normalizedX,a=b;s?a-=i*(t-e):c&&(a-=Math.round(i*100)*n),p(`input`,v(a))},onEnd:()=>{p(`change`,i),S.deactivate()}});function C(e){if(!o)return;e.preventDefault();let t=(e.ctrlKey?.5:1)*W(e.deltaY,-1,1),r=(n||.2)*t;r&&p(`change`,v((i||0)-r))}return{onremove:()=>{S.deactivate()},oninit:f,onbeforeupdate:f,view:a=>{f(a);let l=s?(i-e)/(t-e):NaN;return(0,I.default)(`div.twk-input.twk-scalar-input`,{style:s?`--twk-scalar-value: ${l}`:``,class:G({"twk-input-readonly":r,"twk-scalar-dragable":!r&&(s||c),"twk-scalar-range":u},a.attrs.class)},[a.attrs.slotBefore?(0,I.default)(`span`,{},a.attrs.slotBefore):null,(0,I.default)(`input`,{type:o?`number`:`text`,min:e,max:t,step:n,value:o?i:d.format(i),onfocus:m,onblur:h,oninput:g,onchange:_,onwheel:C,onmousedown:y,ontouchstart:y,placeholder:void 0,disabled:r}),a.attrs.unit?(0,I.default)(`span.twk-color-muted`,{},a.attrs.unit):null,a.attrs.slotAfter?(0,I.default)(`span`,{},a.attrs.slotAfter):null])}}};function jt(e,t){return(0,I.default)(Nt,e,t)}function Mt(e,t){return(0,I.default)(Lt,e,t)}var Nt=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-angle-widget`,label:e??n.field,class:t},[(0,I.default)(Lt,n)])}),Pt=180/Math.PI,Y=Math.PI/180,Ft={toControl:e=>e*Pt,fromControl:e=>e*Y},It={toControl:e=>e*Y,fromControl:e=>e*Pt},Lt=()=>{let e=0,t=!1,n=[0,0],r,i,a,o,s;function c(e){return i!=null&&a!=null?i<=a?e<i?e=i:e>a&&(e=a):e>=i||e<=a||(e=Math.abs(e-i)<Math.abs(e-a)?i:a):i==null?a!=null&&e>a&&(e=a):e<i&&(e=i),o!=null&&(e=Math.round(e/o)*o),e}function l(e){return e%=360,e<0&&(e+=360),e}function u(t){s=t.attrs,i=s.min,a=s.max,o=s.step,i=i==null?null:l(i)*Y,a=a==null?null:l(a)*Y,o=o==null?null:l(o)*Y,e=K(s)??e,s.degree&&(e*=Y),f()}function d(t){f();let n=s.degree?e*Pt:e;q(s,n),U(t===`input`?s.oninput:s.onchange,s.value,n)}function f(){n[0]=Math.cos(e),n[1]=Math.sin(e)}let p,m=pe({onStart:e=>{let t=fe(e);p=[-(t.x-t.width/2),-(t.y-t.height/2)]},onMove:n=>{n.preventDefault();let i=fe(n,r,p),a=i.normalizedX-.5,o=i.normalizedY-.5;t&&(e=Math.atan2(a,-o),e<0&&(e+=2*Math.PI)),e=c(e),d(`input`),I.default.redraw()},onEnd:()=>{m.deactivate(),t=!1,d(`change`),I.default.redraw()}});function h(e){return e<0&&(e+=360),e%360}return{onremove:()=>{m.deactivate()},oninit:e=>{u(e)},onupdate:e=>{u(e)},view:({attrs:{...n}})=>(0,I.default)(`div.twk-angle-input`,{style:{"--angle-value":`${h(e*Pt)}`}},[Ot({unit:s.degree?`°`:`rad`,range:!0,...n,slotAfter:(0,I.default)(`span.twk-flex-row`,[(0,I.default)(`span.twk-color-dim`,`/`),(s.degree?e:e*Pt).toFixed(1),(0,I.default)(`span.twk-color-dim`,s.degree?`rad`:`°`)])}),(0,I.default)(`div.twk-angle-pane`,{oncreate:e=>r=e.dom,class:G({"is-dragging":t}),style:{aspectRatio:`1`,display:`flex`,"align-items":`center`,"justify-content":`center`,position:`relative`}})])}};function Rt(e,t){return(0,I.default)(Bt,e,t)}function zt(e,t){return(0,I.default)(Vt,e,t)}var Bt=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-bool-widget`,label:e??n.field,class:t},[(0,I.default)(Vt,n)])}),Vt=()=>{let e;function t(t){let n=t.target.checked;q(e,n),e.oninput?.(e.value,n),e.onchange?.(e.value,n)}return{view:n=>{e=n.attrs;let r=K(e)===!0,i=e.align===`end`;return(0,I.default)(`div.twk-bool-input`,{class:G({"twk-align-start":!i,"twk-align-end":!!i,"twk-bool-true":r,"twk-bool-false":!r})},[e.slotBefore,e.readonly?r?e.slotTrue||(0,I.default)(`span`,`true`):e.slotFalse||(0,I.default)(`span`,`false`):(0,I.default)(`input`,{class:G({"twk-toggle":!!e.toggle,"twk-check":!e.toggle}),type:`checkbox`,checked:r,onchange:t}),e.slotAfter,n.children])}}};function Ht(e){let t=e.h%360,n=W(e.s,0,1),r=W(e.v,0,1),i=r*n,a=i*(1-Math.abs(t/60%2-1)),o=r-i,s={r:0,g:0,b:0};return t<60?(s.r=i,s.g=a,s.b=0):t<120?(s.r=a,s.g=i,s.b=0):t<180?(s.r=0,s.g=i,s.b=a):t<240?(s.r=0,s.g=a,s.b=i):t<300?(s.r=a,s.g=0,s.b=i):(s.r=i,s.g=0,s.b=a),s.r+=o,s.g+=o,s.b+=o,s}function Ut(e){let t=e.r,n=e.g,r=e.b,i=Math.max(t,n,r),a=i-Math.min(t,n,r),o=0,s=0;return a!==0&&(o=a/i,i===t?(s=(n-r)/a+(n<r?6:0),s=s%6*60):i===n?(s=(r-t)/a+2,s*=60):(s=(t-n)/a+4,s*=60)),{h:s,s:o,v:i}}var Wt=class{constructor(e,t){this.components=e,this.normalized=t}toControl(e){e||=[];let t={r:0,g:0,b:0,a:1};return this.components.forEach((n,r)=>{t[n]=(e[r]||0)/(this.normalized?1:255)}),t}fromControl(e){return this.components.map(t=>(this.normalized?e[t]:Math.round(e[t]*255))||0)}},Gt=class{components=[`r`,`g`,`b`,`a`];constructor(e){this.components=e}toControl(e){e||=`rgba(0, 0, 0)`;let t={r:0,g:0,b:0,a:1},n=e.replace(/[rgba\(\)]/gi,``).split(/,\s*?/gi).map(Number);return this.components.forEach((e,r)=>{t[e]=(n[r]||0)/(e===`a`?1:255)}),t}fromControl(e){return this.components.join(``)+`(`+this.components.map(t=>t===`a`?e[t]:Math.round(e[t]*255)).join(`, `)+`)`}},Kt=class{constructor(e,t=`#`){this.components=e,this.prefix=t}toControl(e){e||=`#000`;let t={r:0,g:0,b:0,a:1},n=e.match(/[0-9a-f]+/i)?.[0];return n==null?t:(n.length===this.components.length&&(n=n.split(``).map(e=>`${e}${e}`).join(``)),this.components.forEach((e,r)=>{t[e]=parseInt(n.substr(r*2,2),16)/255}),t)}fromControl(e){return this.prefix+this.components.map(t=>ue(Math.round(e[t]*255).toString(16),2,`0`)).join(``)}},qt=class{componentsRev;constructor(e){this.components=e,this.componentsRev=e.slice().reverse()}toControl(e){e||=0;let t={r:0,g:0,b:0,a:1};return this.components.forEach((n,r)=>{t[n]=(e>>r*8&255)/255}),t}fromControl(e){let t=this.componentsRev.map(t=>ue(Math.round(e[t]*255||0).toString(16),2,`0`)).join(``);return parseInt(`0x`+t,16)}},Jt=[`r`,`g`,`b`,`a`],Yt=class{constructor(e,t){this.components=e,this.normalized=t}toControl(e){e||={};let t={r:0,g:0,b:0,a:1};return this.components.forEach((n,r)=>{t[Jt[r]]=(e[n]||0)/(this.normalized?1:255)}),t}fromControl(e){let t={};return this.components.forEach((n,r)=>{t[n]=(this.normalized?e[Jt[r]]:Math.round(e[n]*255))||0}),t}},X={};function Z(e=`rgb()`){if(e in X)return X[e];{let t=e.match(/^\[(n?)\]([rgba]+)?$/i);if(t){let n=!!t[1];return X[e]=new Wt((t[2]||`rgba`).toLowerCase().split(``),n),X[e]}}{let t=e.match(/^\{(n?)\}([rgbaxyzw]+)?$/i);if(t){let n=!!t[1];return X[e]=new Yt((t[2]||`rgba`).split(``),n),X[e]}}{let t=e.match(/^0x([rgba]+)?$/i);if(t)return X[e]=new qt((t[1]||`rgba`).toLowerCase().split(``)),X[e]}{let t=e.match(/^#([rgba]+)?$/);if(t)return X[e]=new Kt((t[1]||`rgba`).toLowerCase().split(``),`#`),X[e]}{let t=e.match(/^(rgb|rgba)\(\)$/);if(t)return X[e]=new Gt((t[2]||`rgba`).toLowerCase().split(``)),X[e]}return e.match(/^[rgba]+$/)&&(X[e]=new Kt(e.split(``),``)),X[e]}function Xt(e,t){return(0,I.default)(Qt,e,t)}function Zt(e,t){return(0,I.default)($t,e,t)}var Qt=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`div.twk-picker-color-widget`,label:e??n.field,class:t},[(0,I.default)($t,n)])}),$t=()=>{let e=0,t=0,n=0,r=0,i;function a(i=t,a=n){return{h:e*360,s:i,v:a,a:r}}function o(e=t,r=n){return Ht(a(e,r))}function s(e=t,i=n,a=r){return{...o(e,i),a}}function c(r){e=r.h/360,t=r.s,n=r.v}function l(e){c(e),r=e.a}function u(e,t){return Z(`#rgb`).fromControl(s(e,t))}function d(e,t){return Z(`#rgba`).fromControl(s(e,t))}function f(e=t,i=n,a=r){return Z(`rgba()`).fromControl(s(e,i,a))}function p(e,t){let n=Z(t||`rgb`).toControl(e);l({...Ut(n),a:n.a})}function m(e){return Z(e).fromControl(s())}function h(){let e=m(i.format),t=q(i,e);U(i.oninput,i.value,t)}function g(){let e=m(i.format),t=q(i,e);U(i.onchange,i.value,t)}function _(){return i.format?.match(/a/i)}function v(e){x(e,`r`)}function y(e){x(e,`g`)}function b(e){x(e,`b`)}function x(e,t){let n=s();n[t]=parseInt(e.target.value,10)/255,c(Ut(n)),h(),g()}function S(e){p(e.target.value,_()?`rgba`:`rgb`),h(),g()}let C=null,w;function T(e){w=`sv`,O(e.target),A(e)}function E(e){w=`h`,O(e.target),A(e)}function D(e){w=`a`,O(e.target),A(e)}function O(e){k(),C=e;let t={passive:!1};document.addEventListener(`mousemove`,A,t),document.addEventListener(`mouseup`,j,t),document.addEventListener(`touchmove`,A,t),document.addEventListener(`touchend`,j,t),document.addEventListener(`touchcancel`,j,t)}function k(){document.removeEventListener(`mousemove`,A),document.removeEventListener(`mouseup`,j),document.removeEventListener(`touchmove`,A),document.removeEventListener(`touchend`,j),document.removeEventListener(`touchcancel`,j)}function A(i){if(!C)return;i.preventDefault();let a=C.getBoundingClientRect(),o=window.pageXOffset||document.documentElement.scrollLeft,s=window.pageYOffset||document.documentElement.scrollTop,c=C.clientWidth,l=C.clientHeight,[u,d]=de(i);u=W((u-o-a.left)/c,0,1),d=W((d-s-a.top)/l,0,1),w===`sv`&&(t=u,n=1-d),w===`h`&&(e=1-u),w===`a`&&(r=u),h(),I.default.redraw()}function j(){C!=null&&(C=null,k(),g())}return{onremove:()=>{k()},oninit:e=>{i=e.attrs,p(K(i),i.format)},onupdate:e=>{i=e.attrs,p(K(i),i.format)},view:a=>{i=a.attrs,p(K(i),i.format);let o=s();return(0,I.default)(`div.twk-color-picker`,{},[(0,I.default)(`.color-picker-inputs`,(0,I.default)(`input.twk-input.input-hex[type='text']`,{value:_()?d():u(),onchange:S}),(0,I.default)(`input.twk-input.input-r[type='number']`,{min:0,max:255,step:1,value:Math.round(o.r*255),onchange:v}),(0,I.default)(`input.twk-input.input-g[type='number']`,{min:0,max:255,step:1,value:Math.round(o.g*255),onchange:y}),(0,I.default)(`input.twk-input.input-b[type='number']`,{min:0,max:255,step:1,value:Math.round(o.b*255),onchange:b})),(0,I.default)(`.color-picker-panel`,(0,I.default)(`.color-picker-sv`,{tabindex:0,onmousedown:T,ontouchstart:T,style:{"background-color":`${f(1,1,1)}`,"user-select":`none`}},(0,I.default)(`.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`}}),(0,I.default)(`.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`}}),(0,I.default)(`.color-picker-sv-cursor`,{style:{"user-select":`none`,"pointer-events":`none`,"background-color":`${f(e,t,1)}`,left:`${t*100}%`,top:`${(1-n)*100}%`}})),(0,I.default)(`.color-picker-h`,{tabindex:0,onmousedown:E,ontouchstart:E,style:{"user-select":`none`,background:`linear-gradient(to right, #f00 0, #f0f 17% , #00f 33% , #0ff 50% , #0f0 67% , #ff0 83% , #f00 100%)`}},(0,I.default)(`.color-picker-h-cursor`,{style:{"user-select":`none`,"pointer-events":`none`,"background-color":`${f(1,1,1)}`,position:`absolute`,left:`${(1-e)*100}%`}})),_()?(0,I.default)(`.color-picker-a`,{tabindex:0,onmousedown:D,ontouchstart:D,style:{"user-select":`none`}},(0,I.default)(`.color-picker-a-bg`,{style:{background:`linear-gradient(to right, ${f(t,n,0)}, ${f(t,n,1)})`}}),(0,I.default)(`.color-picker-a-cursor`,{style:{"user-select":`none`,"pointer-events":`none`,position:`absolute`,left:`${r*100}%`}})):null)])}}};function en(e,t){return(0,I.default)(nn,e,t)}function tn(e,t){return(0,I.default)(rn,e,t)}var nn=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`div.twk-color-widget`,label:e??n.field,class:t},[(0,I.default)(rn,n)])}),rn=()=>{let e,t=!1,n,r,i=Z(`rgba()`);function a(t){e=t.attrs,r=K(e),n=i.fromControl(Z(e.format).toControl(r))}function o(){t=!t}function s(t,n){q(e,n),e.oninput?.(e.value,n)}function c(t,n){q(e,n),e.onchange?.(e.value,n)}function l(){return z(r)?r:B(r)?`0x`+ue(r.toString(16),8,`0`):le(r)?r.map(e=>e<1&&e>0?e.toFixed(2):e).join(` , `):H(r)?Object.keys(r).map(e=>{let t=r[e];return`${e}: ${t<1&&t>0?t.toFixed(2):t}`}).join(` `):r==null?`null`:`?`}return{oninit:a,onbeforeupdate:a,view:({attrs:{value:e,field:r,binding:i,format:a}})=>[(0,I.default)(`div.twk-color-input`,{style:{"--twk-color-value":n}},(0,I.default)(`button.twk-btn[type='button']`,{onclick:o},l()||`?`),t?I.default.fragment({},[Zt({binding:i,value:e,field:r,format:a,oninput:s,onchange:c})]):null)]}};function an(e,t){return(0,I.default)(sn,e,t)}function on(e,t){return(0,I.default)(sn,e,t)}var sn=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-input-widget`,label:e??n.field,class:t},(0,I.default)(cn,n))}),cn=()=>{let e;function t(t){let n=t.target.value;q(e,n),(t.type===`input`?e.oninput:e.onchange)?.(e.value,n)}return{view:n=>(e=n.attrs,(0,I.default)(`div.twk-input`,{},[n.attrs.slotBefore?(0,I.default)(`span`,{},n.attrs.slotBefore):null,(0,I.default)(`input`,{type:e.type||`text`,value:K(e),oninput:t,onchange:t,placeholder:e.placeholder,disabled:e.readonly}),n.attrs.slotAfter?(0,I.default)(`span`,{},n.attrs.slotAfter):null]))}};function ln(e,t){return(0,I.default)(un,e,t)}var un=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-matrix-widget`,label:e??n.field,class:t},[(0,I.default)(fn,n)])});function dn(e,t){return(0,I.default)(fn,e,t)}var fn=()=>{let e;function t(t,n,r){let i=K(e)||{};i[n]=r,q(e,i),(t===`input`?e.oninput:e.onchange)?.(e.value,i)}function n(t,n){let r=[];n=e.rowMajor?t:n,t=e.rowMajor?n:t;for(let e=0;e<n;e++)for(let i=0;i<t;i++)r.push(i*n+e);return r}return{view:r=>{e=r.attrs;let i=e.cols??1,a=e.rows??1,o=K(e);return(0,I.default)(`div.twk-matrix-input`,{style:{display:`grid`,gridTemplateColumns:`repeat(${i}, auto)`}},n(a,i).map(n=>Ot({min:e.min,max:e.max,step:e.step,value:o,field:n,readonly:e.readonly,oninput:(e,r)=>t(`input`,n,r),onchange:(e,r)=>t(`change`,n,r)})))}}},pn=[0,1],mn=[`x`,`y`];function hn(e,t){return(0,I.default)(gn,e,t)}var gn=()=>{let e,t,n=pn,r=pn,i=0,a=0,o=0,s=0,c,l,u,d;function f(f){d=f.attrs;let p=d.keys||mn;e=p[0],t=p[1];let m=K(d)??{[e]:i,[t]:a};u=d.snap,i=m[e]||0,a=m[t]||0,n=d.rangeX||n,r=d.rangeY||r,o=(i-n[0])/(n[1]-n[0]),s=(a-r[0])/(r[1]-r[0]);let h=d.reset;h&&(c=(h[0]-n[0])/(n[1]-n[0]),l=(h[1]-r[0])/(r[1]-r[0]))}function p(){i=n[0]+(n[1]-n[0])*o,a=r[0]+(r[1]-r[0])*s,u>0&&(i=Math.floor(i/u)*u,a=Math.floor(a/u)*u,o=(i-n[0])/(n[1]-n[0]),s=(a-r[0])/(r[1]-r[0]))}function m(n){p();let r=K(d)??{[e]:i,[t]:a};r[e]=i,r[t]=a,U(n===`input`?d.oninput:d.onchange,d,r)}function h(e){g.activate(e)}let g=pe({onMove:e=>{e.preventDefault();let t=g.target,n=t.getBoundingClientRect(),r=window.pageXOffset||document.documentElement.scrollLeft,i=window.pageYOffset||document.documentElement.scrollTop,a=t.clientWidth,c=t.clientHeight,[l,u]=de(e);o=W((l-r-n.left)/a,0,1),s=W((u-i-n.top)/c,0,1),m(`input`),I.default.redraw()},onEnd:()=>{g.deactivate(),c!=null&&l!=null&&(o=c,s=l,m(`input`)),m(`change`),I.default.redraw()}});return{onremove:g.deactivate,oninit:f,onupdate:f,view:e=>(f(e),J({label:d.label,class:G(`twk-point`,d.class)},(0,I.default)(`.point-area`,{tabindex:0,onmousedown:h,ontouchstart:h},(0,I.default)(`.point-x-axis`,{style:{"pointer-events":`none`,position:`absolute`,left:0,right:0,top:`${s*100}%`,height:`1px`}}),(0,I.default)(`.point-y-axis`,{style:{"pointer-events":`none`,position:`absolute`,left:`${o*100}%`,top:0,bottom:0,width:`1px`}}),(0,I.default)(`.point-cursor`,{style:{"pointer-events":`none`,left:`${o*100}%`,top:`${s*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)`}}))))}};function _n(e){let t=[];for(let n of e){if(z(n)||B(n)){t.push({value:n,label:String(n)});continue}if(`value`in n){t.push(n);continue}}return t}function vn(e){let t=[];for(let n of e)z(n)||B(n)||n==null?t.push({value:n,label:String(n)}):`value`in n?t.push(n):`options`in n&&t.push({label:n.label,disabled:n.disabled,options:Array.isArray(n.options)?_n(n.options):yn(n.options)});return t}function yn(e){return Object.keys(e).sort().map(t=>({value:e[t],label:t}))}function bn(e){let t=e.attrs.options;return t?Array.isArray(t)?vn(t):yn(t):[]}function xn(e,t){return(0,I.default)(Sn,e,t)}var Sn=()=>{let e,t;function n(){let n=K(e),r=0;for(let e of t)if(`options`in e)for(let t of e.options){if(t.value===n)return r;r++}else{if(e.value===n)return r;r++}}function r(e){let n=0;for(let r of t)if(`options`in r)for(let t of r.options){if(n===e)return t.value;n+=1}else{if(n===e)return r.value;n+=1}return null}function i(t){let n=t.target,i=r(n.selectedIndex),a=q(e,i);e.onchange?.(e,a)}return{view:r=>(e=r.attrs,t=bn(r),J({tagName:`label.twk-select`,label:e.label??e.field,class:e.class},(0,I.default)(`select.twk-select-input`,{selectedIndex:n(),onchange:i,disabled:e.readonly},t.map(e=>`options`in e?(0,I.default)(`optgroup`,{disabled:!!e.disabled,label:e.label||``},e.options.map(Cn)):Cn(e)))))}};function Cn(e){return(0,I.default)(`option`,{value:e.value,label:e.label,disabled:!!e.disabled},e.label||``)}function wn(e,t){return(0,I.default)(Tn,e,t)}var Tn=()=>{let e=1,t=0,n=0,r=!1,i,a=null,o,s;function c(){return Dn(K(o)||On(e,t,n))}function l(i){o=i.attrs;let a=c();e=a.radius??1,t=a.azimuth??0,n=a.polar??0,r=n>Math.PI/2}function u(r){let i=On(e,t,n);q(o,i),U(r===`input`?o.oninput:o.onchange,o.value,i)}function d(e){return a=`pol`,p.activate(e),e.target.focus(),!1}function f(e){return a=`azi`,p.activate(e),e.target.focus(),!1}let p=pe({onStart:e=>{},onMove:e=>{let o=fe(e,i),s=o.normalizedX-.5,c=o.normalizedY-.5;if(a===`azi`)t=Math.atan2(c,s),t<0&&(t+=2*Math.PI);else if(a===`pol`){let e=[Math.cos(t),Math.sin(t)],i=[s,c],a=(e[0]*i[0]+e[1]*i[1])/Math.sqrt(e[0]*e[0]+e[1]*e[1]);n=Math.PI*W(a,0,.5),r&&(n=Math.PI-n)}u(`input`),I.default.redraw()},onEnd:e=>{p.deactivate(),a=null,u(`change`),I.default.redraw()}});return{onremove:()=>{p.deactivate()},oninit:l,onupdate:l,view:()=>(s=On(e,t,n,s),J({tagName:`label.twk-spherical`,label:o.label??o.field,class:o.class,style:{"--azimuth-value":`${En(t)}`,"--polar-value":`${En(n)}`}},[(0,I.default)(`div.twk-spherical-label`,{},`x: ${s.x.toFixed(2)} y: ${s.y.toFixed(2)} z: ${s.z.toFixed(2)}`),(0,I.default)(`div.twk-spherical-pane`,{oncreate:e=>i=e.dom,class:G({"is-dragging":!!a}),style:{aspectRatio:`1`,display:`flex`,"align-items":`center`,"justify-content":`center`,position:`relative`}},(0,I.default)(`div.twk-spherical-arm`,{onmousedown:d,ontouchstart:d,tabIndex:0,style:{width:`50%`,display:`flex`,justifyContent:`end`,alignItems:`center`,transform:`translateX(50%) rotate(${t}rad)`,transformOrigin:`left center`}},(0,I.default)(`div.twk-spherical-knob`,{onmousedown:f,ontouchstart:f,tabIndex:0,style:{aspectRatio:`1`,transform:`translateX(100%)`}})))]))}};function En(e){return 180/Math.PI*e}function Dn(e){let t=e?.x??0,n=e?.y??0,r=e?.z??0,i=Math.sqrt(t*t+n*n+r*r)||1;return{radius:i,azimuth:Math.atan2(r,t)||0,polar:Math.acos(n/i)||0}}function On(e,t,n,r){let i=Math.sin(n);return r||={},r.x=e*Math.cos(t)*i,r.y=e*Math.cos(n),r.z=e*Math.sin(t)*i,r}function kn(e,t){return(0,I.default)(jn,e,t)}function An(e,t){return(0,I.default)(Mn,e,t)}var jn=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-string-widget`,label:e??n.field,class:t},[(0,I.default)(Mn,n)])}),Mn=()=>{let e;function t(t){let n=t.target.value;q(e,n),(t.type===`input`?e.oninput:e.onchange)?.(e.value,n)}return{view:n=>{e=n.attrs;let r=!e.readonly,i=K(e);return(0,I.default)(`div.twk-input.twk-string-input`,{class:G({"twk-input-readonly":!!e.readonly})},[e.slotStart??null,r?null:(0,I.default)(`div.twk-input-value`,i),r?(0,I.default)(e.rows?`textarea`:`input[type='text']`,{value:i,oninput:t,onchange:t,placeholder:e.placeholder,disabled:e.readonly,rows:e.rows}):null,e.slotEnd??null])}}};function Nn(e,t){return(0,I.default)(Fn,e,t)}function Pn(e,t){return(0,I.default)(Ln,e,t)}var Fn=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`label.twk-vector-widget`,label:e??n.field,class:t},[(0,I.default)(Ln,n)])}),In=[`x`,`y`,`z`],Ln=()=>{function e(e,t,n,r){let i=K(r)||{};i[t]=isNaN(n)?null:n,q(r,i),(e===`input`?r.oninput:r.onchange)?.(r.value,i,t)}return{view:({attrs:t})=>{let n=t.keys||In,r=t.cols||n.length,i=K(t);return(0,I.default)(`div.twk-vector-input`,{style:{display:`grid`,gridTemplateColumns:`repeat(${r}, 1fr)`}},n.map(n=>Ot({min:t.min,max:t.max,step:t.step,value:i,field:n,readonly:t.readonly,slotBefore:t.unlabeled?null:(0,I.default)(`span.twk-color-muted`,n),oninput:(r,i)=>e(`input`,n,i,t),onchange:(r,i)=>e(`change`,n,i,t),placeholder:n})))}}};function Rn(e,t){return(0,I.default)(zn,e,t)}var zn=()=>({view:({attrs:{label:e,class:t,...n}})=>J({tagName:`div.twk-Bitmask-widget`,label:e??n.field,class:t},[(0,I.default)(Vn,n)])});function Bn(e,t){return(0,I.default)(Vn,e,t)}var Vn=()=>{let e;function t(){return e.bitCount||32}function n(t){let n=K(e);n^=1<<t,r(n)}function r(t){q(e,t),e.oninput?.(e.value,t),e.onchange?.(e.value,t)}function i(e,t){return(e&1<<t)!=0}function a(t){if(e.names){for(let[n,r]of Object.entries(e.names))if(r===1<<t)return n}return null}return{view:r=>{e=r.attrs;let o=t(),s=K(e);return(0,I.default)(`div.twk-bitmask-input`,{},Array.from({length:o},(e,t)=>(0,I.default)(`label.twk-bitmask-row`,{tabindex:0,class:G({"twk-bitmask-active":i(s,t)}),onclick:()=>n(t)},[(0,I.default)(`div.twk-bitmask-indicator`,{}),(0,I.default)(`div.twk-bitmask-name`,{},a(t)||``),(0,I.default)(`div.twk-bitmask-bit`,{},`bit ${t}`),(0,I.default)(`div.twk-bitmask-value`,{},`0x`+String((2**t).toString(16)).padStart(Math.ceil(o/4),`0`))])))}}};function Hn(e,t){return(0,I.default)(Wn,e,t)}function Un(e,t){return(0,I.default)(Gn,e,t)}var Wn=()=>({view:({attrs:e})=>J({tagName:`label.twk-input.twk-input-readonly`,label:e.label??e.field,class:e.class},(0,I.default)(Gn,e))}),Gn=()=>{let e,t,n;return{oncreate({dom:r}){e=r,t=setInterval(()=>{let t=K(n)??``;e.textContent=String(t)},n.interval??500)},onremove(){clearInterval(t)},view:e=>(n=e.attrs,(0,I.default)(`div.twk-poll`,{}))}},Kn=class e{static build(t){let n=new e;return t(n),n.close()}schema=[];close(){let e=this.schema;return this.schema=[],e}group=qn(this,ge);flex=$(this,ye);grid=$(this,ce);tabs=$(this,Xe);split=$(this,Ke);splitContent=$(this,Ge);section=$(this,we);sectionHeader=$(this,Te);sectionFooter=$(this,Ee);bar=$(this,R);barStart=$(this,ie);barEnd=$(this,ae);barContent=$(this,oe);bool=Q(this,Bt);string=Q(this,jn);scalar=Q(this,kt);vector=Q(this,Fn);matrix=Q(this,un);select=Q(this,Sn);angle=Q(this,Nt);bitmask=Q(this,zn);poll=Q(this,Wn);color=Q(this,nn);colorPicker=Q(this,Qt);boolInput=Q(this,Vt);stringInput=Q(this,Mn);scalarInput=Q(this,At);vectorInput=Q(this,Ln);matrixInput=Q(this,fn);selectInput=Q(this,Sn);angleInput=Q(this,Lt);bitmaskInput=Q(this,Vn);pollInput=Q(this,Gn);colorInput=Q(this,rn);colorPickerInput=Q(this,$t);point=Q(this,gn);spherical=Q(this,Tn);button(e,t={}){this.add(it,t,e)}image(e){this.add(Tt,e)}divider(e){this.add(ot,{},e)}tree(e){this.add(et,e)}graph(e){this.add(vt,e)}widget(e,t){this.add(Et,{label:e},t)}pre(e,t){this.add(Et,{label:e,style:{whiteSpace:`pre`}},t)}view(e){this.add({view:e})}control(e,t){this.add(Et,e,t)}add(e,t,n){if(this.schema)this.schema.push({component:e,attributes:t,children:n});else throw Error(`Cannot use control builder after it was closed`)}};function qn(e,t){return function(){let{options:n,children:r}=Jn(e,arguments);e.add(t,n,r)}}function Q(e,t){return function(){e.add(t,Yn(arguments))}}function $(e,t){return function(){let{options:n,children:r}=Xn(e,arguments);e.add(t,n,r)}}function Jn(e,t){let n=null,r={},i=null;for(let e=0;e<t.length;e++){let a=t[e];z(a)?n=a:H(a)?r=a:V(a)&&(i=a)}n&&(r.title=n);let a=[];if(i){let t=e.schema;e.schema=a,i(e),e.schema=t}return{options:r,children:a}}function Yn(e){let t;return e.length===1?e[0]||{}:(e.length>1?(t=e[2]||{},t.value=e[0],t.field=e[1],t.label===void 0&&(t.label=String(t.field||``))):t={},t)}function Xn(e,t){let n=null,r=null;if(!t.length)return{options:{},children:[]};for(let e=0;e<t.length;e++){let i=t[e];H(i)?n=i:V(i)&&(r=i)}let i=[];if(r){let t=e.schema;e.schema=i,r(e),e.schema=t}return{options:n||{},children:i}}e.AngleInputComponent=Lt,e.AngleWidgetComponent=Nt,e.BarComponent=R,e.BarContentComponent=oe,e.BarEndComponent=ae,e.BarStartComponent=ie,e.BitmaskInputComponent=Vn,e.BitmaskWidgetComponent=zn,e.BoolInputComponent=Vt,e.BoolWidgetComponent=Bt,e.Builder=Kn,e.ButtonComponent=it,e.ColorComponent=rn,e.ColorPicker=$t,e.ColorPickerWidgetComponent=Qt,e.ColorWidgetComponent=nn,e.DialogComponent=nt,e.Divider=ot,e.FlexComponent=ye,e.GraphComponent=vt,e.GridComponent=ce,e.GroupComponent=ge,e.ImageComponent=Tt,e.InputComponent=cn,e.InputWidgetComponent=sn,e.MatrixInputComponent=fn,e.MatrixWidgetComponent=un,e.PointComponent=gn,e.PollComponent=Gn,e.PollWidgetComponent=Wn,e.ScalarInputComponent=At,e.ScalarWidgetComponent=kt,e.SectionComponent=we,e.SectionContentComponent=De,e.SectionFooterComponent=Ee,e.SectionHeaderComponent=Te,e.SelectComponent=Sn,e.SphericalComponent=Tn,e.SplitComponent=Ke,e.SplitContentComponent=Ge,e.StringInputComponent=Mn,e.StringWidgetComponent=jn,e.TabComponent=Je,e.TabsComponent=Xe,e.TreeComponent=et,e.VectorInputComponent=Ln,e.VectorWidgetComponent=Fn,e.WidgetComponent=Et,e.binding=Re,e.degToRadAdapter=It,e.getColorAdapter=Z,e.getControlValue=K,e.getRawValue=Oe,e.h=ze,e.hsv2rgb=Ht,e.isVnode=Ne,e.labeledFn=Le,e.mapChildren=Pe,e.mountUi=Be,e.radToDegAdapter=Ft,e.redrawUi=He,e.renderChildren=Fe,e.rgb2hsv=Ut,e.setControlValue=q,e.setRawValue=ke,e.uiAngleInput=Mt,e.uiAngleWidget=jt,e.uiBar=L,e.uiBarContent=re,e.uiBarEnd=ne,e.uiBarStart=te,e.uiBitmaskInput=Bn,e.uiBitmaskWidget=Rn,e.uiBoolInput=zt,e.uiBoolWidget=Rt,e.uiButton=rt,e.uiColor=tn,e.uiColorPicker=Zt,e.uiColorPickerWidget=Xt,e.uiColorWidget=en,e.uiDialog=tt,e.uiDivider=at,e.uiFlex=ve,e.uiGraph=_t,e.uiGrid=se,e.uiGroup=he,e.uiImage=wt,e.uiInput=on,e.uiInputWidget=an,e.uiMatrixInput=dn,e.uiMatrixWidget=ln,e.uiPoint=hn,e.uiPoll=Un,e.uiPollWidget=Hn,e.uiScalarInput=Ot,e.uiScalarWidget=Dt,e.uiSection=be,e.uiSectionContent=Ce,e.uiSectionFooter=Se,e.uiSectionHeader=xe,e.uiSelect=xn,e.uiSpherical=wn,e.uiSplit=Ue,e.uiSplitContent=We,e.uiString=An,e.uiStringWidget=kn,e.uiTabs=Ye,e.uiTree=Ze,e.uiVectorInput=Pn,e.uiVectorWidget=Nn,e.uiWidget=J,e.unmountUi=Ve});
33
+ //# sourceMappingURL=tweak-ui.umd.js.map