maquette 4.1.3 → 4.1.4

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.
@@ -4,6 +4,38 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.maquette = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
+ /**
8
+ * Creates a {@link CalculationCache} object, useful for caching {@link VNode} trees.
9
+ * In practice, caching of {@link VNode} trees is not needed, because achieving 60 frames per second is almost never a problem.
10
+ * For more information, see {@link CalculationCache}.
11
+ *
12
+ * @param <Result> The type of the value that is cached.
13
+ */
14
+ var createCache = function () {
15
+ var cachedInputs;
16
+ var cachedOutcome;
17
+ return {
18
+ invalidate: function () {
19
+ cachedOutcome = undefined;
20
+ cachedInputs = undefined;
21
+ },
22
+ result: function (inputs, calculation) {
23
+ if (cachedInputs) {
24
+ for (var i = 0; i < inputs.length; i++) {
25
+ if (cachedInputs[i] !== inputs[i]) {
26
+ cachedOutcome = undefined;
27
+ }
28
+ }
29
+ }
30
+ if (!cachedOutcome) {
31
+ cachedOutcome = calculation();
32
+ cachedInputs = inputs;
33
+ }
34
+ return cachedOutcome;
35
+ },
36
+ };
37
+ };
38
+
7
39
  var NAMESPACE_W3 = "http://www.w3.org/";
8
40
  var NAMESPACE_SVG = "".concat(NAMESPACE_W3, "2000/svg");
9
41
  var NAMESPACE_XLINK = "".concat(NAMESPACE_W3, "1999/xlink");
@@ -65,11 +97,7 @@
65
97
  if (i !== indexToCheck) {
66
98
  var node = childNodes[i];
67
99
  if (same(node, childNode)) {
68
- throw {
69
- error: new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")),
70
- parentNode: parentVNode,
71
- childNode: childNode,
72
- };
100
+ throw Object.assign(new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")), { parentNode: parentVNode, childNode: childNode });
73
101
  }
74
102
  }
75
103
  }
@@ -132,6 +160,7 @@
132
160
  }
133
161
  };
134
162
  var vnodeOnlyProps = [
163
+ "on",
135
164
  "afterCreate",
136
165
  "afterUpdate",
137
166
  "afterRemoved",
@@ -182,19 +211,6 @@
182
211
  }
183
212
  }
184
213
  }
185
- else if (propName === "on" && propValue) {
186
- // object with string keys and function values
187
- for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
188
- var _b = _a[_i], key = _b[0], handler = _b[1];
189
- var listener = typeof handler === "function" ? handler : handler.listener;
190
- if (eventHandlerInterceptor) {
191
- listener = eventHandlerInterceptor(key, listener, domNode, properties);
192
- }
193
- if (listener) {
194
- domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
195
- }
196
- }
197
- }
198
214
  else if (propName !== "key" && propValue !== null && propValue !== undefined) {
199
215
  var type = typeof propValue;
200
216
  if (type === "function") {
@@ -223,6 +239,19 @@
223
239
  }
224
240
  }
225
241
  }
242
+ if (properties.on) {
243
+ // object with string keys and function values
244
+ for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
245
+ var _b = _a[_i], key = _b[0], handler = _b[1];
246
+ var listener = typeof handler === "function" ? handler : handler.listener;
247
+ if (eventHandlerInterceptor) {
248
+ listener = eventHandlerInterceptor(key, listener, domNode, properties);
249
+ }
250
+ if (listener) {
251
+ domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
252
+ }
253
+ }
254
+ }
226
255
  };
227
256
  var addChildren = function (domNode, children, projectionOptions) {
228
257
  if (!children) {
@@ -502,7 +531,7 @@
502
531
  try {
503
532
  parentNode.replaceChild(newTextNode, domNode);
504
533
  }
505
- catch (e) {
534
+ catch (_a) {
506
535
  // Text nodes can be substituted by google translate
507
536
  parentNode.replaceChild(newTextNode, parentNode.childNodes[oldChildren.indexOf(previous)]);
508
537
  }
@@ -585,13 +614,13 @@
585
614
  };
586
615
  var dom = {
587
616
  /**
588
- * Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
589
- * its [[Projection.domNode|domNode]] property.
590
- * This is a low-level method. Users will typically use a [[Projector]] instead.
591
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
617
+ * Creates a real DOM tree from `vnode`. The {@link Projection} object returned will contain the resulting DOM Node in
618
+ * its {@link Projection.domNode | domNode} property.
619
+ * This is a low-level method. Users will typically use a {@link Projector} instead.
620
+ * @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
592
621
  * objects may only be rendered once.
593
622
  * @param projectionOptions - Options to be used to create and update the projection.
594
- * @returns The [[Projection]] which also contains the DOM Node that was created.
623
+ * @returns The {@link Projection} which also contains the DOM Node that was created.
595
624
  */
596
625
  create: function (vnode, projectionOptions) {
597
626
  projectionOptions = applyDefaultProjectionOptions(projectionOptions);
@@ -599,13 +628,13 @@
599
628
  return createProjection(vnode, projectionOptions);
600
629
  },
601
630
  /**
602
- * Appends a new child node to the DOM which is generated from a [[VNode]].
603
- * This is a low-level method. Users will typically use a [[Projector]] instead.
631
+ * Appends a new child node to the DOM which is generated from a {@link VNode}.
632
+ * This is a low-level method. Users will typically use a {@link Projector} instead.
604
633
  * @param parentNode - The parent node for the new child node.
605
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
634
+ * @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
606
635
  * objects may only be rendered once.
607
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
608
- * @returns The [[Projection]] that was created.
636
+ * @param projectionOptions - Options to be used to create and update the {@link Projection}.
637
+ * @returns The {@link Projection} that was created.
609
638
  */
610
639
  append: function (parentNode, vnode, projectionOptions) {
611
640
  projectionOptions = applyDefaultProjectionOptions(projectionOptions);
@@ -613,13 +642,13 @@
613
642
  return createProjection(vnode, projectionOptions);
614
643
  },
615
644
  /**
616
- * Inserts a new DOM node which is generated from a [[VNode]].
617
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
645
+ * Inserts a new DOM node which is generated from a {@link VNode}.
646
+ * This is a low-level method. Users wil typically use a {@link Projector} instead.
618
647
  * @param beforeNode - The node that the DOM Node is inserted before.
619
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
620
- * NOTE: [[VNode]] objects may only be rendered once.
621
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
622
- * @returns The [[Projection]] that was created.
648
+ * @param vnode - The root of the virtual DOM tree that was created using the {@link h} function.
649
+ * NOTE: {@link VNode} objects may only be rendered once.
650
+ * @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
651
+ * @returns The {@link Projection} that was created.
623
652
  */
624
653
  insertBefore: function (beforeNode, vnode, projectionOptions) {
625
654
  projectionOptions = applyDefaultProjectionOptions(projectionOptions);
@@ -627,15 +656,15 @@
627
656
  return createProjection(vnode, projectionOptions);
628
657
  },
629
658
  /**
630
- * Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
659
+ * Merges a new DOM node which is generated from a {@link VNode} with an existing DOM Node.
631
660
  * This means that the virtual DOM and the real DOM will have one overlapping element.
632
- * Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
633
- * This is a low-level method. Users wil typically use a [[Projector]] instead.
661
+ * Therefore the selector for the root {@link VNode} will be ignored, but its properties and children will be applied to the Element provided.
662
+ * This is a low-level method. Users wil typically use a {@link Projector} instead.
634
663
  * @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
635
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
664
+ * @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode} objects
636
665
  * may only be rendered once.
637
- * @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
638
- * @returns The [[Projection]] that was created.
666
+ * @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
667
+ * @returns The {@link Projection} that was created.
639
668
  */
640
669
  merge: function (element, vnode, projectionOptions) {
641
670
  projectionOptions = applyDefaultProjectionOptions(projectionOptions);
@@ -644,13 +673,13 @@
644
673
  return createProjection(vnode, projectionOptions);
645
674
  },
646
675
  /**
647
- * Replaces an existing DOM node with a node generated from a [[VNode]].
648
- * This is a low-level method. Users will typically use a [[Projector]] instead.
649
- * @param element - The node for the [[VNode]] to replace.
650
- * @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
676
+ * Replaces an existing DOM node with a node generated from a {@link VNode}.
677
+ * This is a low-level method. Users will typically use a {@link Projector} instead.
678
+ * @param element - The node for the {@link VNode} to replace.
679
+ * @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
651
680
  * objects may only be rendered once.
652
- * @param projectionOptions - Options to be used to create and update the [[Projection]].
653
- * @returns The [[Projection]] that was created.
681
+ * @param projectionOptions - Options to be used to create and update the {@link Projection}.
682
+ * @returns The {@link Projection} that was created.
654
683
  */
655
684
  replace: function (element, vnode, projectionOptions) {
656
685
  projectionOptions = applyDefaultProjectionOptions(projectionOptions);
@@ -716,6 +745,57 @@
716
745
  };
717
746
  }
718
747
 
748
+ /**
749
+ * Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
750
+ * See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
751
+ *
752
+ * @param <Source> The type of source items. A database-record for instance.
753
+ * @param <Target> The type of target items. A {@link MaquetteComponent} for instance.
754
+ * @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
755
+ * @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
756
+ * to the `callback` argument in `Array.map(callback)`.
757
+ * @param updateResult `function(source, target, index)` that updates a result to an updated source.
758
+ */
759
+ var createMapping = function (getSourceKey, createResult, updateResult) {
760
+ var keys = [];
761
+ var results = [];
762
+ return {
763
+ results: results,
764
+ map: function (newSources) {
765
+ var newKeys = newSources.map(getSourceKey);
766
+ var oldTargets = results.slice();
767
+ var oldIndex = 0;
768
+ for (var i = 0; i < newSources.length; i++) {
769
+ var source = newSources[i];
770
+ var sourceKey = newKeys[i];
771
+ if (sourceKey === keys[oldIndex]) {
772
+ results[i] = oldTargets[oldIndex];
773
+ updateResult(source, oldTargets[oldIndex], i);
774
+ oldIndex++;
775
+ }
776
+ else {
777
+ var found = false;
778
+ for (var j = 1; j < keys.length + 1; j++) {
779
+ var searchIndex = (oldIndex + j) % keys.length;
780
+ if (keys[searchIndex] === sourceKey) {
781
+ results[i] = oldTargets[searchIndex];
782
+ updateResult(newSources[i], oldTargets[searchIndex], i);
783
+ oldIndex = searchIndex + 1;
784
+ found = true;
785
+ break;
786
+ }
787
+ }
788
+ if (!found) {
789
+ results[i] = createResult(source, i);
790
+ }
791
+ }
792
+ }
793
+ results.length = newSources.length;
794
+ keys = newKeys;
795
+ },
796
+ };
797
+ };
798
+
719
799
  var createParentNodePath = function (node, rootNode) {
720
800
  var parentNodePath = [];
721
801
  while (node && node !== rootNode) {
@@ -724,19 +804,12 @@
724
804
  }
725
805
  return parentNodePath;
726
806
  };
727
- var find;
728
- if (Array.prototype.find) {
729
- find = function (items, predicate) { return items.find(predicate); };
730
- }
731
- else {
732
- find = function (items, predicate) { return items.filter(predicate)[0]; };
733
- }
734
807
  var findVNodeByParentNodePath = function (vnode, parentNodePath) {
735
808
  var result = vnode;
736
809
  parentNodePath.forEach(function (node) {
737
810
  result =
738
811
  result && result.children
739
- ? find(result.children, function (child) { return child.domNode === node; })
812
+ ? result.children.find(function (child) { return child.domNode === node; })
740
813
  : undefined;
741
814
  });
742
815
  return result;
@@ -763,9 +836,9 @@
763
836
  }
764
837
  };
765
838
  /**
766
- * Creates a [[Projector]] instance using the provided projectionOptions.
839
+ * Creates a {@link Projector} instance using the provided projectionOptions.
767
840
  *
768
- * For more information, see [[Projector]].
841
+ * For more information, see {@link Projector}.
769
842
  *
770
843
  * @param projectorOptions Options that influence how the DOM is rendered and updated.
771
844
  */
@@ -850,89 +923,6 @@
850
923
  return projector;
851
924
  };
852
925
 
853
- /**
854
- * Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
855
- * In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
856
- * For more information, see [[CalculationCache]].
857
- *
858
- * @param <Result> The type of the value that is cached.
859
- */
860
- var createCache = function () {
861
- var cachedInputs;
862
- var cachedOutcome;
863
- return {
864
- invalidate: function () {
865
- cachedOutcome = undefined;
866
- cachedInputs = undefined;
867
- },
868
- result: function (inputs, calculation) {
869
- if (cachedInputs) {
870
- for (var i = 0; i < inputs.length; i++) {
871
- if (cachedInputs[i] !== inputs[i]) {
872
- cachedOutcome = undefined;
873
- }
874
- }
875
- }
876
- if (!cachedOutcome) {
877
- cachedOutcome = calculation();
878
- cachedInputs = inputs;
879
- }
880
- return cachedOutcome;
881
- },
882
- };
883
- };
884
-
885
- /**
886
- * Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
887
- * See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
888
- *
889
- * @param <Source> The type of source items. A database-record for instance.
890
- * @param <Target> The type of target items. A [[MaquetteComponent]] for instance.
891
- * @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
892
- * @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
893
- * to the `callback` argument in `Array.map(callback)`.
894
- * @param updateResult `function(source, target, index)` that updates a result to an updated source.
895
- */
896
- var createMapping = function (getSourceKey, createResult, updateResult) {
897
- var keys = [];
898
- var results = [];
899
- return {
900
- results: results,
901
- map: function (newSources) {
902
- var newKeys = newSources.map(getSourceKey);
903
- var oldTargets = results.slice();
904
- var oldIndex = 0;
905
- for (var i = 0; i < newSources.length; i++) {
906
- var source = newSources[i];
907
- var sourceKey = newKeys[i];
908
- if (sourceKey === keys[oldIndex]) {
909
- results[i] = oldTargets[oldIndex];
910
- updateResult(source, oldTargets[oldIndex], i);
911
- oldIndex++;
912
- }
913
- else {
914
- var found = false;
915
- for (var j = 1; j < keys.length + 1; j++) {
916
- var searchIndex = (oldIndex + j) % keys.length;
917
- if (keys[searchIndex] === sourceKey) {
918
- results[i] = oldTargets[searchIndex];
919
- updateResult(newSources[i], oldTargets[searchIndex], i);
920
- oldIndex = searchIndex + 1;
921
- found = true;
922
- break;
923
- }
924
- }
925
- if (!found) {
926
- results[i] = createResult(source, i);
927
- }
928
- }
929
- }
930
- results.length = newSources.length;
931
- keys = newKeys;
932
- },
933
- };
934
- };
935
-
936
926
  exports.createCache = createCache;
937
927
  exports.createMapping = createMapping;
938
928
  exports.createProjector = createProjector;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).maquette={})}(this,function(e){"use strict";function l(t,r){var o={};return Object.keys(t).forEach(function(e){o[e]=t[e]}),r&&Object.keys(r).forEach(function(e){o[e]=r[e]}),o}function t(e){(e.children||[]).forEach(t),e.properties&&e.properties.afterRemoved&&e.properties.afterRemoved.call(e.properties.bind||e.properties,e.domNode)}function r(){d=!1,i.forEach(t),i.length=0}function o(e){i.push(e),d||(d=!0,"undefined"!=typeof window&&"requestIdleCallback"in window?window.requestIdleCallback(r,{timeout:16}):setTimeout(r,16))}var n="http://www.w3.org/",S="".concat(n,"2000/svg"),w="".concat(n,"1999/xlink"),v=[],h=function(e,t){return e.vnodeSelector===t.vnodeSelector&&(e.properties&&t.properties?e.properties.key===t.properties.key&&e.properties.bind===t.properties.bind:!e.properties&&!t.properties)},E=function(e){if("string"!=typeof e)throw Error("Style values must be strings")},m=function(e,t,r){if(""!==t.vnodeSelector)for(var o=r;o<e.length;o++)if(h(e[o],t))return o;return-1},g=function(e,t,r,o){var n=e[t];if(""!==n.vnodeSelector){var i=n.properties;if(!(i&&(void 0===i.key?i.bind:i.key)))for(var d=0;d<e.length;d++)if(d!==t){var a=e[d];if(h(a,n))throw{error:Error("".concat(r.vnodeSelector," had a ").concat(n.vnodeSelector," child ").concat("added"===o?o:"removed",", but there is now more than one. You must add unique key properties to make them distinguishable.")),parentNode:r,childNode:n}}}},y=function(e){var t;e.properties&&(t=e.properties.enterAnimation)&&t(e.domNode,e.properties)},i=[],d=!1,N=function(e){var t=e.domNode;if(e.properties){var r=e.properties.exitAnimation;if(r)return t.style.pointerEvents="none",void r(t,function(){t.parentNode&&(t.parentNode.removeChild(t),o(e))},e.properties)}t.parentNode&&(t.parentNode.removeChild(t),o(e))},a=["afterCreate","afterUpdate","afterRemoved","enterAnimation","exitAnimation","updateAnimation"];function k(e){return!a.includes(e)}function f(e,t,r){c(e,t.children,r),t.text&&(e.textContent=t.text),p(e,t.properties,r),t.properties&&t.properties.afterCreate&&t.properties.afterCreate.call(t.properties.bind||t.properties,e,r,t.vnodeSelector,t.properties,t.children)}function s(r,o){return{getLastRender:function(){return r},update:function(e){if(r.vnodeSelector!==e.vnodeSelector)throw Error("The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)");var t=r;x(t,r=e,o,t.domNode.parentNode,[t])},domNode:r.domNode}}function u(e){return l(A,e)}var p=function(e,t,r){if(t)for(var o=r.eventHandlerInterceptor,n=Object.keys(t).filter(k),i=n.length,d=0;d<i;d++){var a,s=n[d],p=t[s];if("className"===s)throw Error('Property "className" is not supported, use "class".');if("class"===s)C(e,p,!0);else if("classes"===s)for(var c=Object.keys(p),l=c.length,f=0;f<l;f++){var u=c[f];p[u]&&e.classList.add(u)}else if("styles"===s)for(var v=Object.keys(p),h=v.length,f=0;f<h;f++){var m=v[f],g=p[m];g&&(E(g),r.styleApplyer(e,m,g))}else if("on"===s&&p)for(var y=0,N=Object.entries(t.on);y<N.length;y++){var b=N[y],x=b[0],b=b[1],A="function"==typeof b?b:b.listener;(A=o?o(x,A,e,t):A)&&e.addEventListener(x,A,"function"==typeof b?void 0:b.options)}else"key"!==s&&null!=p&&("function"==(a=typeof p)?(s.lastIndexOf("on",0)||o&&(p=o(s,p,e,t)),e[s]=p):r.namespace===S?"href"===s?e.setAttributeNS(w,s,p):e.setAttribute(s,p):"string"==a&&"value"!==s&&"innerHTML"!==s?e.setAttribute(s,p):e[s]=p)}},c=function(e,t,r){if(t)for(var o=0,n=t;o<n.length;o++){var i=n[o];b(i,e,void 0,r)}},b=function(e,t,r,o){var n,i=0,d=e.vnodeSelector,a=t.ownerDocument;if(""===d)e.domNode?e.domNode.nodeValue=e.text:(n=e.domNode=a.createTextNode(e.text),void 0!==r?t.insertBefore(n,r):t.appendChild(n));else{for(var s=0;s<=d.length;++s){var p,c=d[0|s]||"";s!==d.length&&"."!=c&&"#"!=c||(c=d[0|i-1]||"",p=d.slice(i,s),"."==c?n.classList.add(p):"#"==c?n.id=p:(void 0!==(o="svg"===p?l(o,{namespace:S}):o).namespace?n=e.domNode=a.createElementNS(o.namespace,p):(n=e.domNode=e.domNode||(null!=(c=e.properties)&&c.is?a.createElement(p,{is:e.properties.is}):a.createElement(p)),"input"===p&&e.properties&&void 0!==e.properties.type&&n.setAttribute("type",e.properties.type)),void 0!==r?t.insertBefore(n,r):n.parentNode!==t&&t.appendChild(n)),i=s+1)}f(n,e,o)}},C=function(t,e,r){e&&e.split(" ").forEach(function(e){e&&t.classList.toggle(e,r)})},x=function(t,e,r,o,n){var i=t.domNode;if(t!==e){var d=!1;if(""===e.vnodeSelector){if(e.text!==t.text){var a=i.ownerDocument.createTextNode(e.text);try{o.replaceChild(a,i)}catch(e){o.replaceChild(a,o.childNodes[n.indexOf(t)])}return e.domNode=a,!0}e.domNode=i}else e.vnodeSelector.lastIndexOf("svg",0)||(r=l(r,{namespace:S})),t.text!==e.text&&(d=!0,void 0===e.text?i.removeChild(i.firstChild):i.textContent=e.text),e.domNode=i,d=function(e,t,r,o,n){if(r===o)return!1;for(var i,d=(r=r||v).length,a=(o=o||v).length,s=0,p=0,c=!1;p<a;){var l=s<d?r[s]:void 0,f=o[p];if(void 0!==l&&h(l,f))c=x(l,f,n,t,r)||c,s++;else{var u=m(r,f,s+1);if(u<0)b(f,t,s<d?r[s].domNode:void 0,n),y(f),g(o,p,e,"added");else{for(i=s;i<u;i++)N(r[i]),g(r,i,e,"removed");c=x(r[u],f,n,t,r)||c,s=u+1}}p++}if(s<d)for(i=s;i<d;i++)N(r[i]),g(r,i,e,"removed");return c}(e,i,t.children,e.children,r)||d,d=function(e,t,r,o){if(r){for(var n=!1,i=Object.keys(r).filter(k),d=i.length,a=0;a<d;a++){var s,p=i[a],c=r[p],l=t[p];if("class"===p)l!==c&&(C(e,l,!1),C(e,c,!0));else if("classes"===p)for(var f=e.classList,u=Object.keys(c),v=u.length,h=0;h<v;h++){var m=u[h],g=!!c[m];g!=!!l[m]&&(n=!0,g?f.add(m):f.remove(m))}else if("styles"===p)for(var y=Object.keys(c),N=y.length,h=0;h<N;h++){var b=y[h],x=c[b];x!==l[b]&&(n=!0,x?(E(x),o.styleApplyer(e,b,x)):o.styleApplyer(e,b,""))}else c||"string"!=typeof l||(c=""),"value"===p?(e[p]!==c&&c!==l&&(e[p]=c),c!==l&&(n=!0)):c===l||"function"==(s=typeof c)&&o.eventHandlerInterceptor||(o.namespace===S?"href"===p?e.setAttributeNS(w,p,c):e.setAttribute(p,c):"string"==s&&"innerHTML"!==p?"role"===p&&""===c?e.removeAttribute(p):e.setAttribute(p,c):e[p]!==c&&(e[p]=c),n=!0)}return n}}(i,t.properties,e.properties,r)||d,e.properties&&e.properties.afterUpdate&&e.properties.afterUpdate.call(e.properties.bind||e.properties,i,r,e.vnodeSelector,e.properties,e.children);d&&e.properties&&e.properties.updateAnimation&&e.properties.updateAnimation(i,e.properties,t.properties)}return!1},A={namespace:void 0,performanceLogger:function(){},eventHandlerInterceptor:void 0,styleApplyer:function(e,t,r){"-"==(t[0]||"")?e.style.setProperty(t,r):e.style[t]=r}},O={create:function(e,t){return t=u(t),b(e,document.createElement("div"),void 0,t),s(e,t)},append:function(e,t,r){return r=u(r),b(t,e,void 0,r),s(t,r)},insertBefore:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),s(t,r)},merge:function(e,t,r){return r=u(r),f(t.domNode=e,t,r),s(t,r)},replace:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),e.parentNode.removeChild(e),s(t,r)}},j=Array.prototype.find?function(e,t){return e.find(t)}:function(e,t){return e.filter(t)[0]};e.createCache=function(){var o,n;return{invalidate:function(){o=n=void 0},result:function(e,t){if(o)for(var r=0;r<e.length;r++)o[r]!==e[r]&&(n=void 0);return n||(n=t(),o=e),n}}},e.createMapping=function(c,l,f){var u=[],v=[];return{results:v,map:function(e){for(var t=e.map(c),r=v.slice(),o=0,n=0;n<e.length;n++){var i=e[n],d=t[n];if(d===u[o])v[n]=r[o],f(i,r[o],n),o++;else{for(var a=!1,s=1;s<u.length+1;s++){var p=(o+s)%u.length;if(u[p]===d){v[n]=r[p],f(e[n],r[p],n),o=1+p,a=!0;break}}a||(v[n]=l(i,n))}}v.length=e.length,u=t}}},e.createProjector=function(e){function r(e,t,r){var i,d,a;function n(e){a("domEvent",e);var t,r,o=i,n=function(e,t){for(var r=[];e&&e!==t;)r.push(e),e=e.parentNode;return r}(e.currentTarget,o.domNode),o=(n.reverse(),o=o.getLastRender(),r=o,n.forEach(function(t){r=r&&r.children?j(r.children,function(e){return e.domNode===t}):void 0}),r);return d.scheduleRender(),o&&(t=(null!=(n=null!=(n=o.properties["on".concat(e.type)])?n:o.properties.on[e.type].listener)?n:o.properties.on[e.type]).apply(o.properties.bind||this,arguments)),a("domEventProcessed",e),t}s.eventHandlerInterceptor=(d=f,a=p,function(e,t,r,o){return n}),i=e(t,r(),s),c.push(i),l.push(r)}function t(){if(o=void 0,n){n=!1,p("renderStart",void 0);for(var e=0;e<c.length;e++){var t=l[e]();p("rendered",void 0),c[e].update(t),p("patched",void 0)}p("renderDone",void 0),n=!0}}var o,s=u(e),p=s.performanceLogger,n=!0,i=!1,c=[],l=[],f={renderNow:t,scheduleRender:function(){o||i||(o=requestAnimationFrame(t))},stop:function(){o&&(cancelAnimationFrame(o),o=void 0),i=!0},resume:function(){n=!(i=!1),f.scheduleRender()},append:function(e,t){r(O.append,e,t)},insertBefore:function(e,t){r(O.insertBefore,e,t)},merge:function(e,t){r(O.merge,e,t)},replace:function(e,t){r(O.replace,e,t)},detach:function(e){for(var t=0;t<l.length;t++)if(l[t]===e)return l.splice(t,1),c.splice(t,1)[0];throw Error("renderFunction was not found")}};return f},e.dom=O,e.h=function(e,t,r){if(Array.isArray(t))r=t,t=void 0;else if(t&&("string"==typeof t||t.vnodeSelector)||r&&("string"==typeof r||r.vnodeSelector))throw Error("h called with invalid arguments");var o,n;return r&&1===r.length&&"string"==typeof r[0]?o=r[0]:r&&(function e(t,r,o){for(var n=0,i=r.length;n<i;n++){var d=r[n];Array.isArray(d)?e(t,d,o):null!=d&&!1!==d&&("string"==typeof d&&(d={vnodeSelector:"",properties:void 0,children:void 0,text:d.toString(),domNode:null}),o.push(d))}}(e,r,n=[]),0===n.length)&&(n=void 0),{vnodeSelector:e,properties:t,children:n,text:""===o?void 0:o,domNode:null}}});
1
+ ((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).maquette={})})(this,function(e){function l(t,r){var o={};return Object.keys(t).forEach(function(e){o[e]=t[e]}),r&&Object.keys(r).forEach(function(e){o[e]=r[e]}),o}var t="http://www.w3.org/",S="".concat(t,"2000/svg"),w="".concat(t,"1999/xlink"),v=[],h=function(e,t){return e.vnodeSelector===t.vnodeSelector&&(e.properties&&t.properties?e.properties.key===t.properties.key&&e.properties.bind===t.properties.bind:!e.properties&&!t.properties)},E=function(e){if("string"!=typeof e)throw Error("Style values must be strings")},m=function(e,t,r){if(""!==t.vnodeSelector)for(var o=r;o<e.length;o++)if(h(e[o],t))return o;return-1},g=function(e,t,r,o){var n=e[t];if(""!==n.vnodeSelector){var i=n.properties;if(!(i&&(void 0===i.key?i.bind:i.key)))for(var d=0;d<e.length;d++)if(d!==t){var a=e[d];if(h(a,n))throw Object.assign(Error("".concat(r.vnodeSelector," had a ").concat(n.vnodeSelector," child ").concat("added"===o?o:"removed",", but there is now more than one. You must add unique key properties to make them distinguishable.")),{parentNode:r,childNode:n})}}},y=function(e){var t;e.properties&&(t=e.properties.enterAnimation)&&t(e.domNode,e.properties)},r=[],o=!1,n=function(e){(e.children||[]).forEach(n),e.properties&&e.properties.afterRemoved&&e.properties.afterRemoved.call(e.properties.bind||e.properties,e.domNode)},i=function(){o=!1,r.forEach(n),r.length=0},d=function(e){r.push(e),o||(o=!0,"undefined"!=typeof window&&"requestIdleCallback"in window?window.requestIdleCallback(i,{timeout:16}):setTimeout(i,16))},N=function(e){var t=e.domNode;if(e.properties){var r=e.properties.exitAnimation;if(r)return t.style.pointerEvents="none",void r(t,function(){t.parentNode&&(t.parentNode.removeChild(t),d(e))},e.properties)}t.parentNode&&(t.parentNode.removeChild(t),d(e))},a=["on","afterCreate","afterUpdate","afterRemoved","enterAnimation","exitAnimation","updateAnimation"];function k(e){return!a.includes(e)}function f(e,t,r){c(e,t.children,r),t.text&&(e.textContent=t.text),p(e,t.properties,r),t.properties&&t.properties.afterCreate&&t.properties.afterCreate.call(t.properties.bind||t.properties,e,r,t.vnodeSelector,t.properties,t.children)}function s(r,o){return{getLastRender:function(){return r},update:function(e){if(r.vnodeSelector!==e.vnodeSelector)throw Error("The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)");var t=r;x(t,r=e,o,t.domNode.parentNode,[t])},domNode:r.domNode}}function u(e){return l(A,e)}var p=function(e,t,r){if(t){for(var o=r.eventHandlerInterceptor,n=Object.keys(t).filter(k),i=n.length,d=0;d<i;d++){var a,s=n[d],p=t[s];if("className"===s)throw Error('Property "className" is not supported, use "class".');if("class"===s)C(e,p,!0);else if("classes"===s)for(var c=Object.keys(p),l=c.length,f=0;f<l;f++){var u=c[f];p[u]&&e.classList.add(u)}else if("styles"===s)for(var v=Object.keys(p),h=v.length,f=0;f<h;f++){var m=v[f],g=p[m];g&&(E(g),r.styleApplyer(e,m,g))}else"key"!==s&&null!=p&&("function"==(a=typeof p)?(s.lastIndexOf("on",0)||o&&(p=o(s,p,e,t)),e[s]=p):r.namespace===S?"href"===s?e.setAttributeNS(w,s,p):e.setAttribute(s,p):"string"==a&&"value"!==s&&"innerHTML"!==s?e.setAttribute(s,p):e[s]=p)}if(t.on)for(var y=0,N=Object.entries(t.on);y<N.length;y++){var b=N[y],x=b[0],b=b[1],A="function"==typeof b?b:b.listener;(A=o?o(x,A,e,t):A)&&e.addEventListener(x,A,"function"==typeof b?void 0:b.options)}}},c=function(e,t,r){if(t)for(var o=0,n=t;o<n.length;o++){var i=n[o];b(i,e,void 0,r)}},b=function(e,t,r,o){var n,i=0,d=e.vnodeSelector,a=t.ownerDocument;if(""===d)e.domNode?e.domNode.nodeValue=e.text:(n=e.domNode=a.createTextNode(e.text),void 0!==r?t.insertBefore(n,r):t.appendChild(n));else{for(var s=0;s<=d.length;++s){var p,c=d[0|s]||"";s!==d.length&&"."!=c&&"#"!=c||(c=d[0|i-1]||"",p=d.slice(i,s),"."==c?n.classList.add(p):"#"==c?n.id=p:(void 0!==(o="svg"===p?l(o,{namespace:S}):o).namespace?n=e.domNode=a.createElementNS(o.namespace,p):(n=e.domNode=e.domNode||(null!=(c=e.properties)&&c.is?a.createElement(p,{is:e.properties.is}):a.createElement(p)),"input"===p&&e.properties&&void 0!==e.properties.type&&n.setAttribute("type",e.properties.type)),void 0!==r?t.insertBefore(n,r):n.parentNode!==t&&t.appendChild(n)),i=s+1)}f(n,e,o)}},C=function(t,e,r){e&&e.split(" ").forEach(function(e){e&&t.classList.toggle(e,r)})},x=function(t,e,r,o,n){var i=t.domNode;if(t!==e){var d=!1;if(""===e.vnodeSelector){if(e.text!==t.text){var a=i.ownerDocument.createTextNode(e.text);try{o.replaceChild(a,i)}catch(e){o.replaceChild(a,o.childNodes[n.indexOf(t)])}return e.domNode=a,!0}e.domNode=i}else e.vnodeSelector.lastIndexOf("svg",0)||(r=l(r,{namespace:S})),t.text!==e.text&&(d=!0,void 0===e.text?i.removeChild(i.firstChild):i.textContent=e.text),e.domNode=i,d=((e,t,r,o,n)=>{if(r===o)return!1;for(var i,d=(r=r||v).length,a=(o=o||v).length,s=0,p=0,c=!1;p<a;){var l=s<d?r[s]:void 0,f=o[p];if(void 0!==l&&h(l,f))c=x(l,f,n,t,r)||c,s++;else{var u=m(r,f,s+1);if(u<0)b(f,t,s<d?r[s].domNode:void 0,n),y(f),g(o,p,e,"added");else{for(i=s;i<u;i++)N(r[i]),g(r,i,e,"removed");c=x(r[u],f,n,t,r)||c,s=u+1}}p++}if(s<d)for(i=s;i<d;i++)N(r[i]),g(r,i,e,"removed");return c})(e,i,t.children,e.children,r)||d,d=((e,t,r,o)=>{if(r){for(var n=!1,i=Object.keys(r).filter(k),d=i.length,a=0;a<d;a++){var s,p=i[a],c=r[p],l=t[p];if("class"===p)l!==c&&(C(e,l,!1),C(e,c,!0));else if("classes"===p)for(var f=e.classList,u=Object.keys(c),v=u.length,h=0;h<v;h++){var m=u[h],g=!!c[m];g!=!!l[m]&&(n=!0,g?f.add(m):f.remove(m))}else if("styles"===p)for(var y=Object.keys(c),N=y.length,h=0;h<N;h++){var b=y[h],x=c[b];x!==l[b]&&(n=!0,x?(E(x),o.styleApplyer(e,b,x)):o.styleApplyer(e,b,""))}else c||"string"!=typeof l||(c=""),"value"===p?(e[p]!==c&&c!==l&&(e[p]=c),c!==l&&(n=!0)):c===l||"function"==(s=typeof c)&&o.eventHandlerInterceptor||(o.namespace===S?"href"===p?e.setAttributeNS(w,p,c):e.setAttribute(p,c):"string"==s&&"innerHTML"!==p?"role"===p&&""===c?e.removeAttribute(p):e.setAttribute(p,c):e[p]!==c&&(e[p]=c),n=!0)}return n}})(i,t.properties,e.properties,r)||d,e.properties&&e.properties.afterUpdate&&e.properties.afterUpdate.call(e.properties.bind||e.properties,i,r,e.vnodeSelector,e.properties,e.children);d&&e.properties&&e.properties.updateAnimation&&e.properties.updateAnimation(i,e.properties,t.properties)}return!1},A={namespace:void 0,performanceLogger:function(){},eventHandlerInterceptor:void 0,styleApplyer:function(e,t,r){"-"==(t[0]||"")?e.style.setProperty(t,r):e.style[t]=r}},O={create:function(e,t){return t=u(t),b(e,document.createElement("div"),void 0,t),s(e,t)},append:function(e,t,r){return r=u(r),b(t,e,void 0,r),s(t,r)},insertBefore:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),s(t,r)},merge:function(e,t,r){return r=u(r),f(t.domNode=e,t,r),s(t,r)},replace:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),e.parentNode.removeChild(e),s(t,r)}};e.createCache=function(){var o,n;return{invalidate:function(){o=n=void 0},result:function(e,t){if(o)for(var r=0;r<e.length;r++)o[r]!==e[r]&&(n=void 0);return n||(n=t(),o=e),n}}},e.createMapping=function(c,l,f){var u=[],v=[];return{results:v,map:function(e){for(var t=e.map(c),r=v.slice(),o=0,n=0;n<e.length;n++){var i=e[n],d=t[n];if(d===u[o])v[n]=r[o],f(i,r[o],n),o++;else{for(var a=!1,s=1;s<u.length+1;s++){var p=(o+s)%u.length;if(u[p]===d){v[n]=r[p],f(e[n],r[p],n),o=1+p,a=!0;break}}a||(v[n]=l(i,n))}}v.length=e.length,u=t}}},e.createProjector=function(e){function r(e,t,r){var i,d,a;function n(e){a("domEvent",e);var t,r,o=i,n=((e,t)=>{for(var r=[];e&&e!==t;)r.push(e),e=e.parentNode;return r})(e.currentTarget,o.domNode),o=(n.reverse(),o=o.getLastRender(),r=o,n.forEach(function(t){r=r&&r.children?r.children.find(function(e){return e.domNode===t}):void 0}),r);return d.scheduleRender(),o&&(t=(null!=(n=null!=(n=o.properties["on".concat(e.type)])?n:o.properties.on[e.type].listener)?n:o.properties.on[e.type]).apply(o.properties.bind||this,arguments)),a("domEventProcessed",e),t}s.eventHandlerInterceptor=(d=f,a=p,function(e,t,r,o){return n}),i=e(t,r(),s),c.push(i),l.push(r)}function t(){if(o=void 0,n){n=!1,p("renderStart",void 0);for(var e=0;e<c.length;e++){var t=l[e]();p("rendered",void 0),c[e].update(t),p("patched",void 0)}p("renderDone",void 0),n=!0}}var o,s=u(e),p=s.performanceLogger,n=!0,i=!1,c=[],l=[],f={renderNow:t,scheduleRender:function(){o||i||(o=requestAnimationFrame(t))},stop:function(){o&&(cancelAnimationFrame(o),o=void 0),i=!0},resume:function(){n=!(i=!1),f.scheduleRender()},append:function(e,t){r(O.append,e,t)},insertBefore:function(e,t){r(O.insertBefore,e,t)},merge:function(e,t){r(O.merge,e,t)},replace:function(e,t){r(O.replace,e,t)},detach:function(e){for(var t=0;t<l.length;t++)if(l[t]===e)return l.splice(t,1),c.splice(t,1)[0];throw Error("renderFunction was not found")}};return f},e.dom=O,e.h=function(e,t,r){if(Array.isArray(t))r=t,t=void 0;else if(t&&("string"==typeof t||t.vnodeSelector)||r&&("string"==typeof r||r.vnodeSelector))throw Error("h called with invalid arguments");var o,n;return r&&1===r.length&&"string"==typeof r[0]?o=r[0]:r&&(function e(t,r,o){for(var n=0,i=r.length;n<i;n++){var d=r[n];Array.isArray(d)?e(t,d,o):null!=d&&!1!==d&&("string"==typeof d&&(d={vnodeSelector:"",properties:void 0,children:void 0,text:d.toString(),domNode:null}),o.push(d))}}(e,r,n=[]),0===n.length)&&(n=void 0),{vnodeSelector:e,properties:t,children:n,text:""===o?void 0:o,domNode:null}}});
@@ -59,11 +59,7 @@ var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, oper
59
59
  if (i !== indexToCheck) {
60
60
  var node = childNodes[i];
61
61
  if (same(node, childNode)) {
62
- throw {
63
- error: new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")),
64
- parentNode: parentVNode,
65
- childNode: childNode,
66
- };
62
+ throw Object.assign(new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")), { parentNode: parentVNode, childNode: childNode });
67
63
  }
68
64
  }
69
65
  }
@@ -126,6 +122,7 @@ var nodeToRemove = function (vNode) {
126
122
  }
127
123
  };
128
124
  var vnodeOnlyProps = [
125
+ "on",
129
126
  "afterCreate",
130
127
  "afterUpdate",
131
128
  "afterRemoved",
@@ -176,19 +173,6 @@ var setProperties = function (domNode, properties, projectionOptions) {
176
173
  }
177
174
  }
178
175
  }
179
- else if (propName === "on" && propValue) {
180
- // object with string keys and function values
181
- for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
182
- var _b = _a[_i], key = _b[0], handler = _b[1];
183
- var listener = typeof handler === "function" ? handler : handler.listener;
184
- if (eventHandlerInterceptor) {
185
- listener = eventHandlerInterceptor(key, listener, domNode, properties);
186
- }
187
- if (listener) {
188
- domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
189
- }
190
- }
191
- }
192
176
  else if (propName !== "key" && propValue !== null && propValue !== undefined) {
193
177
  var type = typeof propValue;
194
178
  if (type === "function") {
@@ -217,6 +201,19 @@ var setProperties = function (domNode, properties, projectionOptions) {
217
201
  }
218
202
  }
219
203
  }
204
+ if (properties.on) {
205
+ // object with string keys and function values
206
+ for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
207
+ var _b = _a[_i], key = _b[0], handler = _b[1];
208
+ var listener = typeof handler === "function" ? handler : handler.listener;
209
+ if (eventHandlerInterceptor) {
210
+ listener = eventHandlerInterceptor(key, listener, domNode, properties);
211
+ }
212
+ if (listener) {
213
+ domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
214
+ }
215
+ }
216
+ }
220
217
  };
221
218
  var addChildren = function (domNode, children, projectionOptions) {
222
219
  if (!children) {
@@ -496,7 +493,7 @@ updateDom = function (previous, vnode, projectionOptions, parentNode, oldChildre
496
493
  try {
497
494
  parentNode.replaceChild(newTextNode, domNode);
498
495
  }
499
- catch (e) {
496
+ catch (_a) {
500
497
  // Text nodes can be substituted by google translate
501
498
  parentNode.replaceChild(newTextNode, parentNode.childNodes[oldChildren.indexOf(previous)]);
502
499
  }