-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimply.min.js
2459 lines (2007 loc) · 77.6 KB
/
simply.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 8);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* unused harmony export NameOrCtorDef */
/**
* Copyright 2016 The Incremental DOM Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @typedef {string|!Function} */
let NameOrCtorDef;
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getData; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return initData; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return importNode; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__types_js__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__util_js__ = __webpack_require__(2);
/**
* Copyright 2015 The Incremental DOM Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Keeps track of information needed to perform diffs for a given DOM node.
* @param {NameOrCtorDef} nameOrCtor
* @param {?string=} key
* @param {*=} typeId
* @constructor
*/
function NodeData(nameOrCtor, key, typeId) {
/**
* An array of attribute name/value pairs, used for quickly diffing the
* incomming attributes to see if the DOM node's attributes need to be
* updated.
* @const {Array<*>}
*/
this.attrsArr = [];
/**
* Whether or not the statics have been applied for the node yet.
* {boolean}
*/
this.staticsApplied = false;
/**
* The key used to identify this node, used to preserve DOM nodes when they
* move within their parent.
* @type {?string|undefined}
*/
this.key = key;
/**
* Keeps track of children within this node by their key.
* {!Object<string, !Element>}
*/
this.keyMap = Object(__WEBPACK_IMPORTED_MODULE_1__util_js__["a" /* createMap */])();
/**
* Whether or the associated node is, or contains, a focused Element.
* @type {boolean}
*/
this.focused = false;
/**
* The nodeName or contructor for the Node.
* @const {NameOrCtorDef}
*/
this.nameOrCtor = nameOrCtor;
/**
* @type {?string}
*/
this.text = null;
/**
* @const
*/
this.typeId = typeId;
}
/**
* Initializes a NodeData object for a Node.
*
* @param {Node} node The node to initialize data for.
* @param {NameOrCtorDef} nameOrCtor The nodeName or constructor for the Node.
* @param {?string=} key The key that identifies the node.
* @param {*=} typeId The type identifier for the Node.
* @return {!NodeData} The newly initialized data object
*/
const initData = function(node, nameOrCtor, key, typeId) {
const data = new NodeData(nameOrCtor, key, typeId);
node['__incrementalDOMData'] = data;
return data;
};
/**
* Retrieves the NodeData object for a Node, creating it if necessary.
*
* @param {?Node} node The Node to retrieve the data for.
* @return {!NodeData} The NodeData for this Node.
*/
const getData = function(node) {
importNode(node);
return node['__incrementalDOMData'];
};
/**
* Imports node and its subtree, initializing caches.
*
* @param {?Node} node The Node to import.
*/
const importNode = function(node) {
if (node['__incrementalDOMData']) {
return;
}
const isElement = node.nodeType === 1;
const nodeName = isElement ? node.localName : node.nodeName;
const key = isElement ? node.getAttribute('key') : null;
const typeId = node['typeId'];
const data = initData(node, nodeName, key, typeId);
if (key) {
getData(node.parentNode).keyMap[key] = node;
}
if (isElement) {
const attributes = node.attributes;
const attrsArr = data.attrsArr;
for (let i = 0; i < attributes.length; i += 1) {
const attr = attributes[i];
const name = attr.name;
const value = attr.value;
attrsArr.push(name);
attrsArr.push(value);
}
}
for (let child = node.firstChild; child; child = child.nextSibling) {
importNode(child);
}
};
/** */
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return createMap; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return has; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return truncateArray; });
/**
* Copyright 2015 The Incremental DOM Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A cached reference to the hasOwnProperty function.
*/
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* A constructor function that will create blank objects.
* @constructor
*/
function Blank() {}
Blank.prototype = Object.create(null);
/**
* Used to prevent property collisions between our "map" and its prototype.
* @param {!Object<string, *>} map The map to check.
* @param {string} property The property to check.
* @return {boolean} Whether map has property.
*/
const has = function(map, property) {
return hasOwnProperty.call(map, property);
};
/**
* Creates an map object without a prototype.
* @return {!Object}
*/
const createMap = function() {
return new Blank();
};
/**
* Truncates an array, removing items up until length.
* @param {!Array<*>} arr The array to truncate.
* @param {number} length The new length of the array.
*/
const truncateArray = function(arr, length) {
while (arr.length > length) {
arr.pop();
}
};
/** */
/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "i", function() { return text; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return patchInner; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return patchOuter; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return open; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return close; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return currentElement; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return currentPointer; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return skip; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return skipNode; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__types_js__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__nodes_js__ = __webpack_require__(12);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__node_data_js__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__assertions_js__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__dom_util_js__ = __webpack_require__(13);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__global_js__ = __webpack_require__(5);
/**
* Copyright 2015 The Incremental DOM Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @type {?Node} */
let currentNode = null;
/** @type {?Node} */
let currentParent = null;
/** @type {?Document} */
let doc = null;
/**
* @param {!Array<Node>} focusPath The nodes to mark.
* @param {boolean} focused Whether or not they are focused.
*/
const markFocused = function(focusPath, focused) {
for (let i = 0; i < focusPath.length; i += 1) {
Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(focusPath[i]).focused = focused;
}
};
/**
* Returns a patcher function that sets up and restores a patch context,
* running the run function with the provided data.
* @param {function((!Element|!DocumentFragment),!function(T),T=): ?Node} run
* @return {function((!Element|!DocumentFragment),!function(T),T=): ?Node}
* @template T
*/
const patchFactory = function(run) {
/**
* TODO(moz): These annotations won't be necessary once we switch to Closure
* Compiler's new type inference. Remove these once the switch is done.
*
* @param {(!Element|!DocumentFragment)} node
* @param {!function(T)} fn
* @param {T=} data
* @return {?Node} node
* @template T
*/
const f = function(node, fn, data) {
const prevDoc = doc;
const prevCurrentNode = currentNode;
const prevCurrentParent = currentParent;
let previousInAttributes = false;
let previousInSkip = false;
doc = node.ownerDocument;
currentParent = node.parentNode;
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
previousInAttributes = Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["k" /* setInAttributes */])(false);
previousInSkip = Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["l" /* setInSkip */])(false);
}
const focusPath = Object(__WEBPACK_IMPORTED_MODULE_4__dom_util_js__["a" /* getFocusedPath */])(node, currentParent);
markFocused(focusPath, true);
const retVal = run(node, fn, data);
markFocused(focusPath, false);
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["j" /* assertVirtualAttributesClosed */])();
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["k" /* setInAttributes */])(previousInAttributes);
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["l" /* setInSkip */])(previousInSkip);
}
doc = prevDoc;
currentNode = prevCurrentNode;
currentParent = prevCurrentParent;
return retVal;
};
return f;
};
/**
* Patches the document starting at node with the provided function. This
* function may be called during an existing patch operation.
* @param {!Element|!DocumentFragment} node The Element or Documen to patch.
* @param {!function(T)} fn A function containing open/close/etc. calls that
* describe the DOM.
* @param {T=} data An argument passed to fn to represent DOM state.
* @return {!Node} The patched node.
* @template T
*/
const patchInner = patchFactory(function(node, fn, data) {
currentNode = node;
enterNode();
fn(data);
exitNode();
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["e" /* assertNoUnclosedTags */])(currentNode, node);
}
return node;
});
/**
* Patches an Element with the the provided function. Exactly one top level
* element call should be made corresponding to `node`.
* @param {!Element} node The Element where the patch should start.
* @param {!function(T)} fn A function containing open/close/etc. calls that
* describe the DOM. This should have at most one top level element call.
* @param {T=} data An argument passed to fn to represent DOM state.
* @return {?Node} The node if it was updated, its replacedment or null if it
* was removed.
* @template T
*/
const patchOuter = patchFactory(function(node, fn, data) {
let startNode = /** @type {!Element} */({ nextSibling: node });
let expectedNextNode = null;
let expectedPrevNode = null;
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["i" /* assertPatchOuterHasParentNode */])(currentParent);
expectedNextNode = node.nextSibling;
expectedPrevNode = node.previousSibling;
}
currentNode = startNode;
fn(data);
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["h" /* assertPatchElementNoExtras */])(startNode, currentNode, expectedNextNode,
expectedPrevNode);
}
if (currentParent) {
clearUnvisitedDOM(currentParent, getNextNode(), node.nextSibling);
}
return (startNode === currentNode) ? null : currentNode;
});
/**
* Checks whether or not the current node matches the specified nameOrCtor and
* key.
*
* @param {!Node} matchNode A node to match the data to.
* @param {NameOrCtorDef} nameOrCtor The name or constructor to check for.
* @param {?string=} key An optional key that identifies a node.
* @param {*=} typeId An type identifier that avoids reuse between elements that
* would otherwise match.
* @return {boolean} True if the node matches, false otherwise.
*/
const matches = function(matchNode, nameOrCtor, key, typeId) {
const data = Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(matchNode);
// Key check is done using double equals as we want to treat a null key the
// same as undefined. This should be okay as the only values allowed are
// strings, null and undefined so the == semantics are not too weird.
return nameOrCtor === data.nameOrCtor &&
typeId === data.typeId &&
key == data.key;
};
/**
* Aligns the virtual Node definition with the actual DOM, moving the
* corresponding DOM node to the correct location or creating it if necessary.
* @param {NameOrCtorDef} nameOrCtor The name or constructor for the Node.
* @param {?string=} key The key used to identify the Node..
* @param {*=} typeId An type identifier that avoids reuse between elements that
* would otherwise match.
*/
const alignWithDOM = function(nameOrCtor, key, typeId) {
if (currentNode && matches(currentNode, nameOrCtor, key, typeId)) {
return;
}
const parentData = Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(currentParent);
const keyMap = parentData.keyMap;
let node;
// Check to see if the node has moved within the parent.
if (key) {
const keyNode = keyMap[key];
if (keyNode) {
if (matches(keyNode, nameOrCtor, key, typeId)) {
node = keyNode;
} else {
// When the keyNode gets removed later, make sure we do not remove the
// new node from the map.
Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(keyNode).key = null;
}
}
}
// Create the node if it doesn't exist.
if (!node) {
if (nameOrCtor === '#text') {
node = Object(__WEBPACK_IMPORTED_MODULE_1__nodes_js__["b" /* createText */])(doc);
} else {
node = Object(__WEBPACK_IMPORTED_MODULE_1__nodes_js__["a" /* createElement */])(doc, currentParent, nameOrCtor, key, typeId);
}
if (key) {
keyMap[key] = node;
}
}
// Mark element. This is to be able to determine whether
// this element is fully initiated on creation or if there
// are still changes coming
node.$iDOMCreated = true;
// Re-order the node into the right position, preserving focus if either
// node or currentNode are focused by making sure that they are not detached
// from the DOM.
if (Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(node).focused) {
// Move everything else before the node.
Object(__WEBPACK_IMPORTED_MODULE_4__dom_util_js__["b" /* moveBefore */])(currentParent, node, currentNode);
} else {
currentParent.insertBefore(node, currentNode);
}
currentNode = node;
};
/**
* Clears out any unvisited Nodes in a given range.
* @param {?Node} parentNode
* @param {?Node} startNode The node to start clearing from, inclusive.
* @param {?Node} endNode The node to clear until, exclusive.
*/
const clearUnvisitedDOM = function(parentNode, startNode, endNode) {
const data = Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(parentNode);
const keyMap = data.keyMap;
let child = startNode;
while (child !== endNode) {
const next = child.nextSibling;
const key = Object(__WEBPACK_IMPORTED_MODULE_2__node_data_js__["a" /* getData */])(child).key;
parentNode.removeChild(child);
if (key) {
delete keyMap[key];
}
child = next;
}
};
/**
* Changes to the first child of the current node.
*/
const enterNode = function() {
currentParent = currentNode;
currentNode = null;
};
/**
* @return {?Node} The next Node to be patched.
*/
const getNextNode = function() {
if (currentNode) {
return currentNode.nextSibling;
} else {
return currentParent.firstChild;
}
};
/**
* Changes to the next sibling of the current node.
*/
const nextNode = function() {
currentNode = getNextNode();
};
/**
* Changes to the parent of the current node, removing any unvisited children.
*/
const exitNode = function() {
if (currentParent && !currentParent.$shadyDom) {
clearUnvisitedDOM(currentParent, getNextNode(), null);
}
currentNode = currentParent;
currentParent = currentParent.parentNode;
};
/**
* Makes sure that the current node is an Element with a matching nameOrCtor and
* key.
*
* @param {NameOrCtorDef} nameOrCtor The tag or constructor for the Element.
* @param {?string=} key The key used to identify this element. This can be an
* empty string, but performance may be better if a unique value is used
* when iterating over an array of items.
* @param {*=} typeId An type identifier that avoids reuse between elements that
* would otherwise match.
* @return {!Element} The corresponding Element.
*/
const open = function(nameOrCtor, key, typeId) {
nextNode();
alignWithDOM(nameOrCtor, key, typeId);
enterNode();
return /** @type {!Element} */(currentParent);
};
/**
* Closes the currently open Element, removing any unvisited children if
* necessary.
*
* @return {!Element} The corresponding Element.
*/
const close = function() {
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["l" /* setInSkip */])(false);
}
exitNode();
return /** @type {!Element} */(currentNode);
};
/**
* Makes sure the current node is a Text node and creates a Text node if it is
* not.
*
* @return {!Text} The corresponding Text Node.
*/
const text = function() {
nextNode();
alignWithDOM('#text', null);
return /** @type {!Text} */(currentNode);
};
/**
* Gets the current Element being patched.
* @return {!Element}
*/
const currentElement = function() {
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["c" /* assertInPatch */])('currentElement', doc);
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["f" /* assertNotInAttributes */])('currentElement');
}
return /** @type {!Element} */(currentParent);
};
/**
* @return {Node} The Node that will be evaluated for the next instruction.
*/
const currentPointer = function() {
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["c" /* assertInPatch */])('currentPointer', doc);
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["f" /* assertNotInAttributes */])('currentPointer');
}
return getNextNode();
};
/**
* Skips the children in a subtree, allowing an Element to be closed without
* clearing out the children.
*/
const skip = function() {
if (__WEBPACK_IMPORTED_MODULE_5__global_js__["a" /* global */].DEBUG) {
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["d" /* assertNoChildrenDeclaredYet */])('skip', currentNode);
Object(__WEBPACK_IMPORTED_MODULE_3__assertions_js__["l" /* setInSkip */])(true);
}
currentNode = currentParent.lastChild;
};
/**
* Skips the next Node to be patched, moving the pointer forward to the next
* sibling of the current pointer.
*/
const skipNode = nextNode;
/** */
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return assertInPatch; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return assertNoUnclosedTags; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return assertNotInAttributes; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return assertInAttributes; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return assertCloseMatchesOpenTag; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "j", function() { return assertVirtualAttributesClosed; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return assertNoChildrenDeclaredYet; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return assertNotInSkip; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return assertPatchElementNoExtras; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "i", function() { return assertPatchOuterHasParentNode; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "k", function() { return setInAttributes; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "l", function() { return setInSkip; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__types_js__ = __webpack_require__(0);
/**
* Copyright 2015 The Incremental DOM Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Keeps track whether or not we are in an attributes declaration (after
* elementOpenStart, but before elementOpenEnd).
* @type {boolean}
*/
let inAttributes = false;
/**
* Keeps track whether or not we are in an element that should not have its
* children cleared.
* @type {boolean}
*/
let inSkip = false;
/**
* Makes sure that there is a current patch context.
* @param {string} functionName
* @param {*} context
*/
const assertInPatch = function(functionName, context) {
if (!context) {
throw new Error('Cannot call ' + functionName + '() unless in patch.');
}
};
/**
* Makes sure that a patch closes every node that it opened.
* @param {?Node} openElement
* @param {!Node|!DocumentFragment} root
*/
const assertNoUnclosedTags = function(openElement, root) {
if (openElement === root) {
return;
}
let currentElement = openElement;
const openTags = [];
while (currentElement && currentElement !== root) {
openTags.push(currentElement.nodeName.toLowerCase());
currentElement = currentElement.parentNode;
}
throw new Error('One or more tags were not closed:\n' +
openTags.join('\n'));
};
/**
* Makes sure that node being outer patched has a parent node.
* @param {?Node} parent
*/
const assertPatchOuterHasParentNode = function(parent) {
if (!parent) {
throw new Error('patchOuter requires the node have a parent.');
}
};
/**
* Makes sure that the caller is not where attributes are expected.
* @param {string} functionName
*/
const assertNotInAttributes = function(functionName) {
if (inAttributes) {
throw new Error(functionName + '() can not be called between ' +
'elementOpenStart() and elementOpenEnd().');
}
};
/**
* Makes sure that the caller is not inside an element that has declared skip.
* @param {string} functionName
*/
const assertNotInSkip = function(functionName) {
if (inSkip) {
throw new Error(functionName + '() may not be called inside an element ' +
'that has called skip().');
}
};
/**
* Makes sure that the caller is where attributes are expected.
* @param {string} functionName
*/
const assertInAttributes = function(functionName) {
if (!inAttributes) {
throw new Error(functionName + '() can only be called after calling ' +
'elementOpenStart().');
}
};
/**
* Makes sure the patch closes virtual attributes call
*/
const assertVirtualAttributesClosed = function() {
if (inAttributes) {
throw new Error('elementOpenEnd() must be called after calling ' +
'elementOpenStart().');
}
};
/**
* Makes sure that tags are correctly nested.
* @param {NameOrCtorDef} currentNameOrCtor
* @param {NameOrCtorDef} nameOrCtor
*/
const assertCloseMatchesOpenTag = function(currentNameOrCtor, nameOrCtor) {
if (currentNameOrCtor !== nameOrCtor) {
throw new Error('Received a call to close "' + nameOrCtor + '" but "' +
currentNameOrCtor + '" was open.');
}
};
/**
* Makes sure that no children elements have been declared yet in the current
* element.
* @param {string} functionName
* @param {?Node} previousNode
*/
const assertNoChildrenDeclaredYet = function(functionName, previousNode) {
if (previousNode !== null) {
throw new Error(functionName + '() must come before any child ' +
'declarations inside the current element.');
}
};
/**
* Checks that a call to patchOuter actually patched the element.
* @param {?Node} startNode The value for the currentNode when the patch
* started.
* @param {?Node} currentNode The currentNode when the patch finished.
* @param {?Node} expectedNextNode The Node that is expected to follow the
* currentNode after the patch;
* @param {?Node} expectedPrevNode The Node that is expected to preceed the
* currentNode after the patch.
*/
const assertPatchElementNoExtras = function(
startNode,
currentNode,
expectedNextNode,
expectedPrevNode) {
const wasUpdated = currentNode.nextSibling === expectedNextNode &&
currentNode.previousSibling === expectedPrevNode;
const wasChanged = currentNode.nextSibling === startNode.nextSibling &&
currentNode.previousSibling === expectedPrevNode;
const wasRemoved = currentNode === startNode;
if (!wasUpdated && !wasChanged && !wasRemoved) {
throw new Error('There must be exactly one top level call corresponding ' +
'to the patched element.');
}
};
/**
* Updates the state of being in an attribute declaration.
* @param {boolean} value
* @return {boolean} the previous value.
*/
const setInAttributes = function(value) {
const previous = inAttributes;
inAttributes = value;
return previous;
};
/**
* Updates the state of being in a skip element.
* @param {boolean} value
* @return {boolean} the previous value.
*/
const setInSkip = function(value) {
const previous = inSkip;
inSkip = value;
return previous;
};
/** */
/***/ }),
/* 5 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return global; });
/**
* Copyright 2017 The Incremental DOM Authors. All Rights Reserved.
*