1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function createElement(tagName, options) {
|
6 | return document.createElement(tagName, options);
|
7 | }
|
8 | function createElementNS(namespaceURI, qualifiedName, options) {
|
9 | return document.createElementNS(namespaceURI, qualifiedName, options);
|
10 | }
|
11 | function createDocumentFragment() {
|
12 | return document.createDocumentFragment();
|
13 | }
|
14 | function createTextNode(text) {
|
15 | return document.createTextNode(text);
|
16 | }
|
17 | function createComment(text) {
|
18 | return document.createComment(text);
|
19 | }
|
20 | function insertBefore(parentNode, newNode, referenceNode) {
|
21 | parentNode.insertBefore(newNode, referenceNode);
|
22 | }
|
23 | function removeChild(node, child) {
|
24 | node.removeChild(child);
|
25 | }
|
26 | function appendChild(node, child) {
|
27 | node.appendChild(child);
|
28 | }
|
29 | function parentNode(node) {
|
30 | return node.parentNode;
|
31 | }
|
32 | function nextSibling(node) {
|
33 | return node.nextSibling;
|
34 | }
|
35 | function tagName(elm) {
|
36 | return elm.tagName;
|
37 | }
|
38 | function setTextContent(node, text) {
|
39 | node.textContent = text;
|
40 | }
|
41 | function getTextContent(node) {
|
42 | return node.textContent;
|
43 | }
|
44 | function isElement$1(node) {
|
45 | return node.nodeType === 1;
|
46 | }
|
47 | function isText(node) {
|
48 | return node.nodeType === 3;
|
49 | }
|
50 | function isComment(node) {
|
51 | return node.nodeType === 8;
|
52 | }
|
53 | function isDocumentFragment$1(node) {
|
54 | return node.nodeType === 11;
|
55 | }
|
56 | const htmlDomApi = {
|
57 | createElement,
|
58 | createElementNS,
|
59 | createTextNode,
|
60 | createDocumentFragment,
|
61 | createComment,
|
62 | insertBefore,
|
63 | removeChild,
|
64 | appendChild,
|
65 | parentNode,
|
66 | nextSibling,
|
67 | tagName,
|
68 | setTextContent,
|
69 | getTextContent,
|
70 | isElement: isElement$1,
|
71 | isText,
|
72 | isComment,
|
73 | isDocumentFragment: isDocumentFragment$1,
|
74 | };
|
75 |
|
76 | function vnode(sel, data, children, text, elm) {
|
77 | const key = data === undefined ? undefined : data.key;
|
78 | return { sel, data, children, text, elm, key };
|
79 | }
|
80 |
|
81 | const array = Array.isArray;
|
82 | function primitive(s) {
|
83 | return typeof s === "string" ||
|
84 | typeof s === "number" ||
|
85 | s instanceof String ||
|
86 | s instanceof Number;
|
87 | }
|
88 |
|
89 | function isUndef(s) {
|
90 | return s === undefined;
|
91 | }
|
92 | function isDef(s) {
|
93 | return s !== undefined;
|
94 | }
|
95 | const emptyNode = vnode("", {}, [], undefined, undefined);
|
96 | function sameVnode(vnode1, vnode2) {
|
97 | var _a, _b;
|
98 | const isSameKey = vnode1.key === vnode2.key;
|
99 | const isSameIs = ((_a = vnode1.data) === null || _a === void 0 ? void 0 : _a.is) === ((_b = vnode2.data) === null || _b === void 0 ? void 0 : _b.is);
|
100 | const isSameSel = vnode1.sel === vnode2.sel;
|
101 | return isSameSel && isSameKey && isSameIs;
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 | function documentFragmentIsNotSupported() {
|
107 | throw new Error("The document fragment is not supported on this platform.");
|
108 | }
|
109 | function isElement(api, vnode) {
|
110 | return api.isElement(vnode);
|
111 | }
|
112 | function isDocumentFragment(api, vnode) {
|
113 | return api.isDocumentFragment(vnode);
|
114 | }
|
115 | function createKeyToOldIdx(children, beginIdx, endIdx) {
|
116 | var _a;
|
117 | const map = {};
|
118 | for (let i = beginIdx; i <= endIdx; ++i) {
|
119 | const key = (_a = children[i]) === null || _a === void 0 ? void 0 : _a.key;
|
120 | if (key !== undefined) {
|
121 | map[key] = i;
|
122 | }
|
123 | }
|
124 | return map;
|
125 | }
|
126 | const hooks = [
|
127 | "create",
|
128 | "update",
|
129 | "remove",
|
130 | "destroy",
|
131 | "pre",
|
132 | "post",
|
133 | ];
|
134 | function init$1(modules, domApi, options) {
|
135 | const cbs = {
|
136 | create: [],
|
137 | update: [],
|
138 | remove: [],
|
139 | destroy: [],
|
140 | pre: [],
|
141 | post: [],
|
142 | };
|
143 | const api = domApi !== undefined ? domApi : htmlDomApi;
|
144 | for (const hook of hooks) {
|
145 | for (const module of modules) {
|
146 | const currentHook = module[hook];
|
147 | if (currentHook !== undefined) {
|
148 | cbs[hook].push(currentHook);
|
149 | }
|
150 | }
|
151 | }
|
152 | function emptyNodeAt(elm) {
|
153 | const id = elm.id ? "#" + elm.id : "";
|
154 |
|
155 |
|
156 | const classes = elm.getAttribute("class");
|
157 | const c = classes ? "." + classes.split(" ").join(".") : "";
|
158 | return vnode(api.tagName(elm).toLowerCase() + id + c, {}, [], undefined, elm);
|
159 | }
|
160 | function emptyDocumentFragmentAt(frag) {
|
161 | return vnode(undefined, {}, [], undefined, frag);
|
162 | }
|
163 | function createRmCb(childElm, listeners) {
|
164 | return function rmCb() {
|
165 | if (--listeners === 0) {
|
166 | const parent = api.parentNode(childElm);
|
167 | api.removeChild(parent, childElm);
|
168 | }
|
169 | };
|
170 | }
|
171 | function createElm(vnode, insertedVnodeQueue) {
|
172 | var _a, _b, _c, _d;
|
173 | let i;
|
174 | let data = vnode.data;
|
175 | if (data !== undefined) {
|
176 | const init = (_a = data.hook) === null || _a === void 0 ? void 0 : _a.init;
|
177 | if (isDef(init)) {
|
178 | init(vnode);
|
179 | data = vnode.data;
|
180 | }
|
181 | }
|
182 | const children = vnode.children;
|
183 | const sel = vnode.sel;
|
184 | if (sel === "!") {
|
185 | if (isUndef(vnode.text)) {
|
186 | vnode.text = "";
|
187 | }
|
188 | vnode.elm = api.createComment(vnode.text);
|
189 | }
|
190 | else if (sel !== undefined) {
|
191 |
|
192 | const hashIdx = sel.indexOf("#");
|
193 | const dotIdx = sel.indexOf(".", hashIdx);
|
194 | const hash = hashIdx > 0 ? hashIdx : sel.length;
|
195 | const dot = dotIdx > 0 ? dotIdx : sel.length;
|
196 | const tag = hashIdx !== -1 || dotIdx !== -1
|
197 | ? sel.slice(0, Math.min(hash, dot))
|
198 | : sel;
|
199 | const elm = (vnode.elm =
|
200 | isDef(data) && isDef((i = data.ns))
|
201 | ? api.createElementNS(i, tag, data)
|
202 | : api.createElement(tag, data));
|
203 | if (hash < dot)
|
204 | elm.setAttribute("id", sel.slice(hash + 1, dot));
|
205 | if (dotIdx > 0)
|
206 | elm.setAttribute("class", sel.slice(dot + 1).replace(/\./g, " "));
|
207 | for (i = 0; i < cbs.create.length; ++i)
|
208 | cbs.create[i](emptyNode, vnode);
|
209 | if (array(children)) {
|
210 | for (i = 0; i < children.length; ++i) {
|
211 | const ch = children[i];
|
212 | if (ch != null) {
|
213 | api.appendChild(elm, createElm(ch, insertedVnodeQueue));
|
214 | }
|
215 | }
|
216 | }
|
217 | else if (primitive(vnode.text)) {
|
218 | api.appendChild(elm, api.createTextNode(vnode.text));
|
219 | }
|
220 | const hook = vnode.data.hook;
|
221 | if (isDef(hook)) {
|
222 | (_b = hook.create) === null || _b === void 0 ? void 0 : _b.call(hook, emptyNode, vnode);
|
223 | if (hook.insert) {
|
224 | insertedVnodeQueue.push(vnode);
|
225 | }
|
226 | }
|
227 | }
|
228 | else if (((_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.fragments) && vnode.children) {
|
229 | const children = vnode.children;
|
230 | vnode.elm = ((_d = api.createDocumentFragment) !== null && _d !== void 0 ? _d : documentFragmentIsNotSupported)();
|
231 | for (i = 0; i < cbs.create.length; ++i)
|
232 | cbs.create[i](emptyNode, vnode);
|
233 | for (i = 0; i < children.length; ++i) {
|
234 | const ch = children[i];
|
235 | if (ch != null) {
|
236 | api.appendChild(vnode.elm, createElm(ch, insertedVnodeQueue));
|
237 | }
|
238 | }
|
239 | }
|
240 | else {
|
241 | vnode.elm = api.createTextNode(vnode.text);
|
242 | }
|
243 | return vnode.elm;
|
244 | }
|
245 | function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
|
246 | for (; startIdx <= endIdx; ++startIdx) {
|
247 | const ch = vnodes[startIdx];
|
248 | if (ch != null) {
|
249 | api.insertBefore(parentElm, createElm(ch, insertedVnodeQueue), before);
|
250 | }
|
251 | }
|
252 | }
|
253 | function invokeDestroyHook(vnode) {
|
254 | var _a, _b;
|
255 | const data = vnode.data;
|
256 | if (data !== undefined) {
|
257 | (_b = (_a = data === null || data === void 0 ? void 0 : data.hook) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a, vnode);
|
258 | for (let i = 0; i < cbs.destroy.length; ++i)
|
259 | cbs.destroy[i](vnode);
|
260 | if (vnode.children !== undefined) {
|
261 | for (let j = 0; j < vnode.children.length; ++j) {
|
262 | const child = vnode.children[j];
|
263 | if (child != null && typeof child !== "string") {
|
264 | invokeDestroyHook(child);
|
265 | }
|
266 | }
|
267 | }
|
268 | }
|
269 | }
|
270 | function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
|
271 | var _a, _b;
|
272 | for (; startIdx <= endIdx; ++startIdx) {
|
273 | let listeners;
|
274 | let rm;
|
275 | const ch = vnodes[startIdx];
|
276 | if (ch != null) {
|
277 | if (isDef(ch.sel)) {
|
278 | invokeDestroyHook(ch);
|
279 | listeners = cbs.remove.length + 1;
|
280 | rm = createRmCb(ch.elm, listeners);
|
281 | for (let i = 0; i < cbs.remove.length; ++i)
|
282 | cbs.remove[i](ch, rm);
|
283 | const removeHook = (_b = (_a = ch === null || ch === void 0 ? void 0 : ch.data) === null || _a === void 0 ? void 0 : _a.hook) === null || _b === void 0 ? void 0 : _b.remove;
|
284 | if (isDef(removeHook)) {
|
285 | removeHook(ch, rm);
|
286 | }
|
287 | else {
|
288 | rm();
|
289 | }
|
290 | }
|
291 | else {
|
292 |
|
293 | api.removeChild(parentElm, ch.elm);
|
294 | }
|
295 | }
|
296 | }
|
297 | }
|
298 | function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
|
299 | let oldStartIdx = 0;
|
300 | let newStartIdx = 0;
|
301 | let oldEndIdx = oldCh.length - 1;
|
302 | let oldStartVnode = oldCh[0];
|
303 | let oldEndVnode = oldCh[oldEndIdx];
|
304 | let newEndIdx = newCh.length - 1;
|
305 | let newStartVnode = newCh[0];
|
306 | let newEndVnode = newCh[newEndIdx];
|
307 | let oldKeyToIdx;
|
308 | let idxInOld;
|
309 | let elmToMove;
|
310 | let before;
|
311 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
312 | if (oldStartVnode == null) {
|
313 | oldStartVnode = oldCh[++oldStartIdx];
|
314 | }
|
315 | else if (oldEndVnode == null) {
|
316 | oldEndVnode = oldCh[--oldEndIdx];
|
317 | }
|
318 | else if (newStartVnode == null) {
|
319 | newStartVnode = newCh[++newStartIdx];
|
320 | }
|
321 | else if (newEndVnode == null) {
|
322 | newEndVnode = newCh[--newEndIdx];
|
323 | }
|
324 | else if (sameVnode(oldStartVnode, newStartVnode)) {
|
325 | patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
|
326 | oldStartVnode = oldCh[++oldStartIdx];
|
327 | newStartVnode = newCh[++newStartIdx];
|
328 | }
|
329 | else if (sameVnode(oldEndVnode, newEndVnode)) {
|
330 | patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
|
331 | oldEndVnode = oldCh[--oldEndIdx];
|
332 | newEndVnode = newCh[--newEndIdx];
|
333 | }
|
334 | else if (sameVnode(oldStartVnode, newEndVnode)) {
|
335 |
|
336 | patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
|
337 | api.insertBefore(parentElm, oldStartVnode.elm, api.nextSibling(oldEndVnode.elm));
|
338 | oldStartVnode = oldCh[++oldStartIdx];
|
339 | newEndVnode = newCh[--newEndIdx];
|
340 | }
|
341 | else if (sameVnode(oldEndVnode, newStartVnode)) {
|
342 |
|
343 | patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
|
344 | api.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
|
345 | oldEndVnode = oldCh[--oldEndIdx];
|
346 | newStartVnode = newCh[++newStartIdx];
|
347 | }
|
348 | else {
|
349 | if (oldKeyToIdx === undefined) {
|
350 | oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
|
351 | }
|
352 | idxInOld = oldKeyToIdx[newStartVnode.key];
|
353 | if (isUndef(idxInOld)) {
|
354 |
|
355 | api.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
|
356 | }
|
357 | else {
|
358 | elmToMove = oldCh[idxInOld];
|
359 | if (elmToMove.sel !== newStartVnode.sel) {
|
360 | api.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
|
361 | }
|
362 | else {
|
363 | patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
|
364 | oldCh[idxInOld] = undefined;
|
365 | api.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
|
366 | }
|
367 | }
|
368 | newStartVnode = newCh[++newStartIdx];
|
369 | }
|
370 | }
|
371 | if (newStartIdx <= newEndIdx) {
|
372 | before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
|
373 | addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
|
374 | }
|
375 | if (oldStartIdx <= oldEndIdx) {
|
376 | removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
|
377 | }
|
378 | }
|
379 | function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
|
380 | var _a, _b, _c, _d, _e;
|
381 | const hook = (_a = vnode.data) === null || _a === void 0 ? void 0 : _a.hook;
|
382 | (_b = hook === null || hook === void 0 ? void 0 : hook.prepatch) === null || _b === void 0 ? void 0 : _b.call(hook, oldVnode, vnode);
|
383 | const elm = (vnode.elm = oldVnode.elm);
|
384 | const oldCh = oldVnode.children;
|
385 | const ch = vnode.children;
|
386 | if (oldVnode === vnode)
|
387 | return;
|
388 | if (vnode.data !== undefined) {
|
389 | for (let i = 0; i < cbs.update.length; ++i)
|
390 | cbs.update[i](oldVnode, vnode);
|
391 | (_d = (_c = vnode.data.hook) === null || _c === void 0 ? void 0 : _c.update) === null || _d === void 0 ? void 0 : _d.call(_c, oldVnode, vnode);
|
392 | }
|
393 | if (isUndef(vnode.text)) {
|
394 | if (isDef(oldCh) && isDef(ch)) {
|
395 | if (oldCh !== ch)
|
396 | updateChildren(elm, oldCh, ch, insertedVnodeQueue);
|
397 | }
|
398 | else if (isDef(ch)) {
|
399 | if (isDef(oldVnode.text))
|
400 | api.setTextContent(elm, "");
|
401 | addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
|
402 | }
|
403 | else if (isDef(oldCh)) {
|
404 | removeVnodes(elm, oldCh, 0, oldCh.length - 1);
|
405 | }
|
406 | else if (isDef(oldVnode.text)) {
|
407 | api.setTextContent(elm, "");
|
408 | }
|
409 | }
|
410 | else if (oldVnode.text !== vnode.text) {
|
411 | if (isDef(oldCh)) {
|
412 | removeVnodes(elm, oldCh, 0, oldCh.length - 1);
|
413 | }
|
414 | api.setTextContent(elm, vnode.text);
|
415 | }
|
416 | (_e = hook === null || hook === void 0 ? void 0 : hook.postpatch) === null || _e === void 0 ? void 0 : _e.call(hook, oldVnode, vnode);
|
417 | }
|
418 | return function patch(oldVnode, vnode) {
|
419 | let i, elm, parent;
|
420 | const insertedVnodeQueue = [];
|
421 | for (i = 0; i < cbs.pre.length; ++i)
|
422 | cbs.pre[i]();
|
423 | if (isElement(api, oldVnode)) {
|
424 | oldVnode = emptyNodeAt(oldVnode);
|
425 | }
|
426 | else if (isDocumentFragment(api, oldVnode)) {
|
427 | oldVnode = emptyDocumentFragmentAt(oldVnode);
|
428 | }
|
429 | if (sameVnode(oldVnode, vnode)) {
|
430 | patchVnode(oldVnode, vnode, insertedVnodeQueue);
|
431 | }
|
432 | else {
|
433 | elm = oldVnode.elm;
|
434 | parent = api.parentNode(elm);
|
435 | createElm(vnode, insertedVnodeQueue);
|
436 | if (parent !== null) {
|
437 | api.insertBefore(parent, vnode.elm, api.nextSibling(elm));
|
438 | removeVnodes(parent, [oldVnode], 0, 0);
|
439 | }
|
440 | }
|
441 | for (i = 0; i < insertedVnodeQueue.length; ++i) {
|
442 | insertedVnodeQueue[i].data.hook.insert(insertedVnodeQueue[i]);
|
443 | }
|
444 | for (i = 0; i < cbs.post.length; ++i)
|
445 | cbs.post[i]();
|
446 | return vnode;
|
447 | };
|
448 | }
|
449 |
|
450 | function addNS(data, children, sel) {
|
451 | data.ns = "http://www.w3.org/2000/svg";
|
452 | if (sel !== "foreignObject" && children !== undefined) {
|
453 | for (let i = 0; i < children.length; ++i) {
|
454 | const child = children[i];
|
455 | if (typeof child === "string")
|
456 | continue;
|
457 | const childData = child.data;
|
458 | if (childData !== undefined) {
|
459 | addNS(childData, child.children, child.sel);
|
460 | }
|
461 | }
|
462 | }
|
463 | }
|
464 | function h(sel, b, c) {
|
465 | let data = {};
|
466 | let children;
|
467 | let text;
|
468 | let i;
|
469 | if (c !== undefined) {
|
470 | if (b !== null) {
|
471 | data = b;
|
472 | }
|
473 | if (array(c)) {
|
474 | children = c;
|
475 | }
|
476 | else if (primitive(c)) {
|
477 | text = c.toString();
|
478 | }
|
479 | else if (c && c.sel) {
|
480 | children = [c];
|
481 | }
|
482 | }
|
483 | else if (b !== undefined && b !== null) {
|
484 | if (array(b)) {
|
485 | children = b;
|
486 | }
|
487 | else if (primitive(b)) {
|
488 | text = b.toString();
|
489 | }
|
490 | else if (b && b.sel) {
|
491 | children = [b];
|
492 | }
|
493 | else {
|
494 | data = b;
|
495 | }
|
496 | }
|
497 | if (children !== undefined) {
|
498 | for (i = 0; i < children.length; ++i) {
|
499 | if (primitive(children[i]))
|
500 | children[i] = vnode(undefined, undefined, undefined, children[i], undefined);
|
501 | }
|
502 | }
|
503 | if (sel[0] === "s" &&
|
504 | sel[1] === "v" &&
|
505 | sel[2] === "g" &&
|
506 | (sel.length === 3 || sel[3] === "." || sel[3] === "#")) {
|
507 | addNS(data, children, sel);
|
508 | }
|
509 | return vnode(sel, data, children, text, undefined);
|
510 | }
|
511 |
|
512 |
|
513 |
|
514 | function fragment(children) {
|
515 | let c;
|
516 | let text;
|
517 | if (array(children)) {
|
518 | c = children;
|
519 | }
|
520 | else if (primitive(c)) {
|
521 | text = children;
|
522 | }
|
523 | else if (c && c.sel) {
|
524 | c = [children];
|
525 | }
|
526 | if (c !== undefined) {
|
527 | for (let i = 0; i < c.length; ++i) {
|
528 | if (primitive(c[i]))
|
529 | c[i] = vnode(undefined, undefined, undefined, c[i], undefined);
|
530 | }
|
531 | }
|
532 | return vnode(undefined, {}, c, text, undefined);
|
533 | }
|
534 |
|
535 | function copyToThunk(vnode, thunk) {
|
536 | var _a;
|
537 | const ns = (_a = thunk.data) === null || _a === void 0 ? void 0 : _a.ns;
|
538 | vnode.data.fn = thunk.data.fn;
|
539 | vnode.data.args = thunk.data.args;
|
540 | thunk.data = vnode.data;
|
541 | thunk.children = vnode.children;
|
542 | thunk.text = vnode.text;
|
543 | thunk.elm = vnode.elm;
|
544 | if (ns)
|
545 | addNS(thunk.data, thunk.children, thunk.sel);
|
546 | }
|
547 | function init(thunk) {
|
548 | const cur = thunk.data;
|
549 | const vnode = cur.fn(...cur.args);
|
550 | copyToThunk(vnode, thunk);
|
551 | }
|
552 | function prepatch(oldVnode, thunk) {
|
553 | let i;
|
554 | const old = oldVnode.data;
|
555 | const cur = thunk.data;
|
556 | const oldArgs = old.args;
|
557 | const args = cur.args;
|
558 | if (old.fn !== cur.fn || oldArgs.length !== args.length) {
|
559 | copyToThunk(cur.fn(...args), thunk);
|
560 | return;
|
561 | }
|
562 | for (i = 0; i < args.length; ++i) {
|
563 | if (oldArgs[i] !== args[i]) {
|
564 | copyToThunk(cur.fn(...args), thunk);
|
565 | return;
|
566 | }
|
567 | }
|
568 | copyToThunk(oldVnode, thunk);
|
569 | }
|
570 | const thunk = function thunk(sel, key, fn, args) {
|
571 | if (args === undefined) {
|
572 | args = fn;
|
573 | fn = key;
|
574 | key = undefined;
|
575 | }
|
576 | return h(sel, {
|
577 | key: key,
|
578 | hook: { init, prepatch },
|
579 | fn: fn,
|
580 | args: args,
|
581 | });
|
582 | };
|
583 |
|
584 | function pre(vnode, newVnode) {
|
585 | const attachData = vnode.data.attachData;
|
586 |
|
587 | newVnode.data.attachData.placeholder = attachData.placeholder;
|
588 | newVnode.data.attachData.real = attachData.real;
|
589 |
|
590 | vnode.elm = vnode.data.attachData.real;
|
591 | }
|
592 | function post(_, vnode) {
|
593 |
|
594 | vnode.elm = vnode.data.attachData.placeholder;
|
595 | }
|
596 | function destroy(vnode) {
|
597 |
|
598 | if (vnode.elm !== undefined) {
|
599 | vnode.elm.parentNode.removeChild(vnode.elm);
|
600 | }
|
601 |
|
602 | vnode.elm = vnode.data.attachData.real;
|
603 | }
|
604 | function create(_, vnode) {
|
605 | const real = vnode.elm;
|
606 | const attachData = vnode.data.attachData;
|
607 | const placeholder = document.createElement("span");
|
608 |
|
609 |
|
610 | vnode.elm = placeholder;
|
611 | attachData.target.appendChild(real);
|
612 | attachData.real = real;
|
613 | attachData.placeholder = placeholder;
|
614 | }
|
615 | function attachTo(target, vnode) {
|
616 | if (vnode.data === undefined)
|
617 | vnode.data = {};
|
618 | if (vnode.data.hook === undefined)
|
619 | vnode.data.hook = {};
|
620 | const data = vnode.data;
|
621 | const hook = vnode.data.hook;
|
622 | data.attachData = { target: target, placeholder: undefined, real: undefined };
|
623 | hook.create = create;
|
624 | hook.prepatch = pre;
|
625 | hook.postpatch = post;
|
626 | hook.destroy = destroy;
|
627 | return vnode;
|
628 | }
|
629 |
|
630 | function toVNode(node, domApi) {
|
631 | const api = domApi !== undefined ? domApi : htmlDomApi;
|
632 | let text;
|
633 | if (api.isElement(node)) {
|
634 | const id = node.id ? "#" + node.id : "";
|
635 | const cn = node.getAttribute("class");
|
636 | const c = cn ? "." + cn.split(" ").join(".") : "";
|
637 | const sel = api.tagName(node).toLowerCase() + id + c;
|
638 | const attrs = {};
|
639 | const children = [];
|
640 | let name;
|
641 | let i, n;
|
642 | const elmAttrs = node.attributes;
|
643 | const elmChildren = node.childNodes;
|
644 | for (i = 0, n = elmAttrs.length; i < n; i++) {
|
645 | name = elmAttrs[i].nodeName;
|
646 | if (name !== "id" && name !== "class") {
|
647 | attrs[name] = elmAttrs[i].nodeValue;
|
648 | }
|
649 | }
|
650 | for (i = 0, n = elmChildren.length; i < n; i++) {
|
651 | children.push(toVNode(elmChildren[i], domApi));
|
652 | }
|
653 | const data = { attrs };
|
654 | if (sel[0] === "s" &&
|
655 | sel[1] === "v" &&
|
656 | sel[2] === "g" &&
|
657 | (sel.length === 3 || sel[3] === "." || sel[3] === "#")) {
|
658 | addNS(data, children, sel);
|
659 | }
|
660 | return vnode(sel, data, children, undefined, node);
|
661 | }
|
662 | else if (api.isText(node)) {
|
663 | text = api.getTextContent(node);
|
664 | return vnode(undefined, undefined, undefined, text, node);
|
665 | }
|
666 | else if (api.isComment(node)) {
|
667 | text = api.getTextContent(node);
|
668 | return vnode("!", {}, [], text, node);
|
669 | }
|
670 | else {
|
671 | return vnode("", {}, [], undefined, node);
|
672 | }
|
673 | }
|
674 |
|
675 | const xlinkNS = "http://www.w3.org/1999/xlink";
|
676 | const xmlNS = "http://www.w3.org/XML/1998/namespace";
|
677 | const colonChar = 58;
|
678 | const xChar = 120;
|
679 | function updateAttrs(oldVnode, vnode) {
|
680 | let key;
|
681 | const elm = vnode.elm;
|
682 | let oldAttrs = oldVnode.data.attrs;
|
683 | let attrs = vnode.data.attrs;
|
684 | if (!oldAttrs && !attrs)
|
685 | return;
|
686 | if (oldAttrs === attrs)
|
687 | return;
|
688 | oldAttrs = oldAttrs || {};
|
689 | attrs = attrs || {};
|
690 |
|
691 | for (key in attrs) {
|
692 | const cur = attrs[key];
|
693 | const old = oldAttrs[key];
|
694 | if (old !== cur) {
|
695 | if (cur === true) {
|
696 | elm.setAttribute(key, "");
|
697 | }
|
698 | else if (cur === false) {
|
699 | elm.removeAttribute(key);
|
700 | }
|
701 | else {
|
702 | if (key.charCodeAt(0) !== xChar) {
|
703 | elm.setAttribute(key, cur);
|
704 | }
|
705 | else if (key.charCodeAt(3) === colonChar) {
|
706 |
|
707 | elm.setAttributeNS(xmlNS, key, cur);
|
708 | }
|
709 | else if (key.charCodeAt(5) === colonChar) {
|
710 |
|
711 | elm.setAttributeNS(xlinkNS, key, cur);
|
712 | }
|
713 | else {
|
714 | elm.setAttribute(key, cur);
|
715 | }
|
716 | }
|
717 | }
|
718 | }
|
719 |
|
720 |
|
721 |
|
722 | for (key in oldAttrs) {
|
723 | if (!(key in attrs)) {
|
724 | elm.removeAttribute(key);
|
725 | }
|
726 | }
|
727 | }
|
728 | const attributesModule = {
|
729 | create: updateAttrs,
|
730 | update: updateAttrs,
|
731 | };
|
732 |
|
733 | function updateClass(oldVnode, vnode) {
|
734 | let cur;
|
735 | let name;
|
736 | const elm = vnode.elm;
|
737 | let oldClass = oldVnode.data.class;
|
738 | let klass = vnode.data.class;
|
739 | if (!oldClass && !klass)
|
740 | return;
|
741 | if (oldClass === klass)
|
742 | return;
|
743 | oldClass = oldClass || {};
|
744 | klass = klass || {};
|
745 | for (name in oldClass) {
|
746 | if (oldClass[name] && !Object.prototype.hasOwnProperty.call(klass, name)) {
|
747 |
|
748 | elm.classList.remove(name);
|
749 | }
|
750 | }
|
751 | for (name in klass) {
|
752 | cur = klass[name];
|
753 | if (cur !== oldClass[name]) {
|
754 | elm.classList[cur ? "add" : "remove"](name);
|
755 | }
|
756 | }
|
757 | }
|
758 | const classModule = { create: updateClass, update: updateClass };
|
759 |
|
760 | const CAPS_REGEX = /[A-Z]/g;
|
761 | function updateDataset(oldVnode, vnode) {
|
762 | const elm = vnode.elm;
|
763 | let oldDataset = oldVnode.data.dataset;
|
764 | let dataset = vnode.data.dataset;
|
765 | let key;
|
766 | if (!oldDataset && !dataset)
|
767 | return;
|
768 | if (oldDataset === dataset)
|
769 | return;
|
770 | oldDataset = oldDataset || {};
|
771 | dataset = dataset || {};
|
772 | const d = elm.dataset;
|
773 | for (key in oldDataset) {
|
774 | if (!dataset[key]) {
|
775 | if (d) {
|
776 | if (key in d) {
|
777 | delete d[key];
|
778 | }
|
779 | }
|
780 | else {
|
781 | elm.removeAttribute("data-" + key.replace(CAPS_REGEX, "-$&").toLowerCase());
|
782 | }
|
783 | }
|
784 | }
|
785 | for (key in dataset) {
|
786 | if (oldDataset[key] !== dataset[key]) {
|
787 | if (d) {
|
788 | d[key] = dataset[key];
|
789 | }
|
790 | else {
|
791 | elm.setAttribute("data-" + key.replace(CAPS_REGEX, "-$&").toLowerCase(), dataset[key]);
|
792 | }
|
793 | }
|
794 | }
|
795 | }
|
796 | const datasetModule = {
|
797 | create: updateDataset,
|
798 | update: updateDataset,
|
799 | };
|
800 |
|
801 | function invokeHandler(handler, vnode, event) {
|
802 | if (typeof handler === "function") {
|
803 |
|
804 | handler.call(vnode, event, vnode);
|
805 | }
|
806 | else if (typeof handler === "object") {
|
807 |
|
808 | for (let i = 0; i < handler.length; i++) {
|
809 | invokeHandler(handler[i], vnode, event);
|
810 | }
|
811 | }
|
812 | }
|
813 | function handleEvent(event, vnode) {
|
814 | const name = event.type;
|
815 | const on = vnode.data.on;
|
816 |
|
817 | if (on && on[name]) {
|
818 | invokeHandler(on[name], vnode, event);
|
819 | }
|
820 | }
|
821 | function createListener() {
|
822 | return function handler(event) {
|
823 | handleEvent(event, handler.vnode);
|
824 | };
|
825 | }
|
826 | function updateEventListeners(oldVnode, vnode) {
|
827 | const oldOn = oldVnode.data.on;
|
828 | const oldListener = oldVnode.listener;
|
829 | const oldElm = oldVnode.elm;
|
830 | const on = vnode && vnode.data.on;
|
831 | const elm = (vnode && vnode.elm);
|
832 | let name;
|
833 |
|
834 | if (oldOn === on) {
|
835 | return;
|
836 | }
|
837 |
|
838 | if (oldOn && oldListener) {
|
839 |
|
840 | if (!on) {
|
841 | for (name in oldOn) {
|
842 |
|
843 | oldElm.removeEventListener(name, oldListener, false);
|
844 | }
|
845 | }
|
846 | else {
|
847 | for (name in oldOn) {
|
848 |
|
849 | if (!on[name]) {
|
850 | oldElm.removeEventListener(name, oldListener, false);
|
851 | }
|
852 | }
|
853 | }
|
854 | }
|
855 |
|
856 | if (on) {
|
857 |
|
858 | const listener = (vnode.listener =
|
859 | oldVnode.listener || createListener());
|
860 |
|
861 | listener.vnode = vnode;
|
862 |
|
863 | if (!oldOn) {
|
864 | for (name in on) {
|
865 |
|
866 | elm.addEventListener(name, listener, false);
|
867 | }
|
868 | }
|
869 | else {
|
870 | for (name in on) {
|
871 |
|
872 | if (!oldOn[name]) {
|
873 | elm.addEventListener(name, listener, false);
|
874 | }
|
875 | }
|
876 | }
|
877 | }
|
878 | }
|
879 | const eventListenersModule = {
|
880 | create: updateEventListeners,
|
881 | update: updateEventListeners,
|
882 | destroy: updateEventListeners,
|
883 | };
|
884 |
|
885 | function updateProps(oldVnode, vnode) {
|
886 | let key;
|
887 | let cur;
|
888 | let old;
|
889 | const elm = vnode.elm;
|
890 | let oldProps = oldVnode.data.props;
|
891 | let props = vnode.data.props;
|
892 | if (!oldProps && !props)
|
893 | return;
|
894 | if (oldProps === props)
|
895 | return;
|
896 | oldProps = oldProps || {};
|
897 | props = props || {};
|
898 | for (key in props) {
|
899 | cur = props[key];
|
900 | old = oldProps[key];
|
901 | if (old !== cur && (key !== "value" || elm[key] !== cur)) {
|
902 | elm[key] = cur;
|
903 | }
|
904 | }
|
905 | }
|
906 | const propsModule = { create: updateProps, update: updateProps };
|
907 |
|
908 |
|
909 | const raf = (typeof window !== "undefined" &&
|
910 | window.requestAnimationFrame.bind(window)) ||
|
911 | setTimeout;
|
912 | const nextFrame = function (fn) {
|
913 | raf(function () {
|
914 | raf(fn);
|
915 | });
|
916 | };
|
917 | let reflowForced = false;
|
918 | function setNextFrame(obj, prop, val) {
|
919 | nextFrame(function () {
|
920 | obj[prop] = val;
|
921 | });
|
922 | }
|
923 | function updateStyle(oldVnode, vnode) {
|
924 | let cur;
|
925 | let name;
|
926 | const elm = vnode.elm;
|
927 | let oldStyle = oldVnode.data.style;
|
928 | let style = vnode.data.style;
|
929 | if (!oldStyle && !style)
|
930 | return;
|
931 | if (oldStyle === style)
|
932 | return;
|
933 | oldStyle = oldStyle || {};
|
934 | style = style || {};
|
935 | const oldHasDel = "delayed" in oldStyle;
|
936 | for (name in oldStyle) {
|
937 | if (!style[name]) {
|
938 | if (name[0] === "-" && name[1] === "-") {
|
939 | elm.style.removeProperty(name);
|
940 | }
|
941 | else {
|
942 | elm.style[name] = "";
|
943 | }
|
944 | }
|
945 | }
|
946 | for (name in style) {
|
947 | cur = style[name];
|
948 | if (name === "delayed" && style.delayed) {
|
949 | for (const name2 in style.delayed) {
|
950 | cur = style.delayed[name2];
|
951 | if (!oldHasDel || cur !== oldStyle.delayed[name2]) {
|
952 | setNextFrame(elm.style, name2, cur);
|
953 | }
|
954 | }
|
955 | }
|
956 | else if (name !== "remove" && cur !== oldStyle[name]) {
|
957 | if (name[0] === "-" && name[1] === "-") {
|
958 | elm.style.setProperty(name, cur);
|
959 | }
|
960 | else {
|
961 | elm.style[name] = cur;
|
962 | }
|
963 | }
|
964 | }
|
965 | }
|
966 | function applyDestroyStyle(vnode) {
|
967 | let style;
|
968 | let name;
|
969 | const elm = vnode.elm;
|
970 | const s = vnode.data.style;
|
971 | if (!s || !(style = s.destroy))
|
972 | return;
|
973 | for (name in style) {
|
974 | elm.style[name] = style[name];
|
975 | }
|
976 | }
|
977 | function applyRemoveStyle(vnode, rm) {
|
978 | const s = vnode.data.style;
|
979 | if (!s || !s.remove) {
|
980 | rm();
|
981 | return;
|
982 | }
|
983 | if (!reflowForced) {
|
984 |
|
985 | vnode.elm.offsetLeft;
|
986 | reflowForced = true;
|
987 | }
|
988 | let name;
|
989 | const elm = vnode.elm;
|
990 | let i = 0;
|
991 | const style = s.remove;
|
992 | let amount = 0;
|
993 | const applied = [];
|
994 | for (name in style) {
|
995 | applied.push(name);
|
996 | elm.style[name] = style[name];
|
997 | }
|
998 | const compStyle = getComputedStyle(elm);
|
999 | const props = compStyle["transition-property"].split(", ");
|
1000 | for (; i < props.length; ++i) {
|
1001 | if (applied.indexOf(props[i]) !== -1)
|
1002 | amount++;
|
1003 | }
|
1004 | elm.addEventListener("transitionend", function (ev) {
|
1005 | if (ev.target === elm)
|
1006 | --amount;
|
1007 | if (amount === 0)
|
1008 | rm();
|
1009 | });
|
1010 | }
|
1011 | function forceReflow() {
|
1012 | reflowForced = false;
|
1013 | }
|
1014 | const styleModule = {
|
1015 | pre: forceReflow,
|
1016 | create: updateStyle,
|
1017 | update: updateStyle,
|
1018 | destroy: applyDestroyStyle,
|
1019 | remove: applyRemoveStyle,
|
1020 | };
|
1021 |
|
1022 |
|
1023 | function Fragment(data, ...children) {
|
1024 | const flatChildren = flattenAndFilter(children, []);
|
1025 | if (flatChildren.length === 1 &&
|
1026 | !flatChildren[0].sel &&
|
1027 | flatChildren[0].text) {
|
1028 |
|
1029 | return vnode(undefined, undefined, undefined, flatChildren[0].text, undefined);
|
1030 | }
|
1031 | else {
|
1032 | return vnode(undefined, data !== null && data !== void 0 ? data : {}, flatChildren, undefined, undefined);
|
1033 | }
|
1034 | }
|
1035 | function flattenAndFilter(children, flattened) {
|
1036 | for (const child of children) {
|
1037 |
|
1038 | if (child !== undefined &&
|
1039 | child !== null &&
|
1040 | child !== false &&
|
1041 | child !== "") {
|
1042 | if (Array.isArray(child)) {
|
1043 | flattenAndFilter(child, flattened);
|
1044 | }
|
1045 | else if (typeof child === "string" ||
|
1046 | typeof child === "number" ||
|
1047 | typeof child === "boolean") {
|
1048 | flattened.push(vnode(undefined, undefined, undefined, String(child), undefined));
|
1049 | }
|
1050 | else {
|
1051 | flattened.push(child);
|
1052 | }
|
1053 | }
|
1054 | }
|
1055 | return flattened;
|
1056 | }
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 | function jsx(tag, data, ...children) {
|
1062 | const flatChildren = flattenAndFilter(children, []);
|
1063 | if (typeof tag === "function") {
|
1064 |
|
1065 | return tag(data, flatChildren);
|
1066 | }
|
1067 | else {
|
1068 | if (flatChildren.length === 1 &&
|
1069 | !flatChildren[0].sel &&
|
1070 | flatChildren[0].text) {
|
1071 |
|
1072 | return h(tag, data, flatChildren[0].text);
|
1073 | }
|
1074 | else {
|
1075 | return h(tag, data, flatChildren);
|
1076 | }
|
1077 | }
|
1078 | }
|
1079 | (function (jsx) {
|
1080 | })(jsx || (jsx = {}));
|
1081 |
|
1082 | exports.Fragment = Fragment;
|
1083 | exports.array = array;
|
1084 | exports.attachTo = attachTo;
|
1085 | exports.attributesModule = attributesModule;
|
1086 | exports.classModule = classModule;
|
1087 | exports.datasetModule = datasetModule;
|
1088 | exports.eventListenersModule = eventListenersModule;
|
1089 | exports.fragment = fragment;
|
1090 | exports.h = h;
|
1091 | exports.htmlDomApi = htmlDomApi;
|
1092 | exports.init = init$1;
|
1093 | exports.jsx = jsx;
|
1094 | exports.primitive = primitive;
|
1095 | exports.propsModule = propsModule;
|
1096 | exports.styleModule = styleModule;
|
1097 | exports.thunk = thunk;
|
1098 | exports.toVNode = toVNode;
|
1099 | exports.vnode = vnode;
|