${data}
` 861 | 862 | 863 | var mapTemplate = function mapTemplate(type, template) { 864 | var text = instrument(template, prefix, type === 'svg'); 865 | var content = createFragment(text, type); // once instrumented and reproduced as fragment, it's crawled 866 | // to find out where each update is in the fragment tree 867 | 868 | var tw = createWalker(content); 869 | var nodes = []; 870 | var length = template.length - 1; 871 | var i = 0; // updates are searched via unique names, linearly increased across the tree 872 | // 873 | 874 | var search = "".concat(prefix).concat(i); 875 | 876 | while (i < length) { 877 | var node = tw.nextNode(); // if not all updates are bound but there's nothing else to crawl 878 | // it means that there is something wrong with the template. 879 | 880 | if (!node) throw "bad template: ".concat(text); // if the current node is a comment, and it contains isµX 881 | // it means the update should take care of any content 882 | 883 | if (node.nodeType === 8) { 884 | // The only comments to be considered are those 885 | // which content is exactly the same as the searched one. 886 | if (node.data === search) { 887 | nodes.push({ 888 | type: 'node', 889 | path: createPath(node) 890 | }); 891 | search = "".concat(prefix).concat(++i); 892 | } 893 | } else { 894 | // if the node is not a comment, loop through all its attributes 895 | // named isµX and relate attribute updates to this node and the 896 | // attribute name, retrieved through node.getAttribute("isµX") 897 | // the isµX attribute will be removed as irrelevant for the layout 898 | // let svg = -1; 899 | while (node.hasAttribute(search)) { 900 | nodes.push({ 901 | type: 'attr', 902 | path: createPath(node), 903 | name: node.getAttribute(search) //svg: svg < 0 ? (svg = ('ownerSVGElement' in node ? 1 : 0)) : svg 904 | 905 | }); 906 | node.removeAttribute(search); 907 | search = "".concat(prefix).concat(++i); 908 | } // if the node was a style, textarea, or others, check its content 909 | // and if it is then update tex-only this node 910 | 911 | 912 | if (textOnly.test(node.tagName) && node.textContent.trim() === "")) { 913 | node.textContent = ''; 914 | nodes.push({ 915 | type: 'text', 916 | path: createPath(node) 917 | }); 918 | search = "".concat(prefix).concat(++i); 919 | } 920 | } 921 | } // once all nodes to update, or their attributes, are known, the content 922 | // will be cloned in the future to represent the template, and all updates 923 | // related to such content retrieved right away without needing to re-crawl 924 | // the exact same template, and its content, more than once. 925 | 926 | 927 | return { 928 | content: content, 929 | nodes: nodes 930 | }; 931 | }; // if a template is unknown, perform the previous mapping, otherwise grab 932 | // its details such as the fragment with all nodes, and updates info. 933 | 934 | 935 | var mapUpdates = function mapUpdates(type, template) { 936 | var _ref = cache$2.get(template) || cache$2.set(template, mapTemplate(type, template)), 937 | content = _ref.content, 938 | nodes = _ref.nodes; // clone deeply the fragment 939 | 940 | 941 | var fragment = importNode.call(document, content, true); // and relate an update handler per each node that needs one 942 | 943 | var updates = nodes.map(handlers, fragment); // return the fragment and all updates to use within its nodes 944 | 945 | return { 946 | content: fragment, 947 | updates: updates 948 | }; 949 | }; // as html and svg can be nested calls, but no parent node is known 950 | // until rendered somewhere, the unroll operation is needed to 951 | // discover what to do with each interpolation, which will result 952 | // into an update operation. 953 | 954 | 955 | var unroll = function unroll(info, _ref2) { 956 | var type = _ref2.type, 957 | template = _ref2.template, 958 | values = _ref2.values; 959 | var length = values.length; // interpolations can contain holes and arrays, so these need 960 | // to be recursively discovered 961 | 962 | unrollValues(info, values, length); 963 | var entry = info.entry; // if the cache entry is either null or different from the template 964 | // and the type this unroll should resolve, create a new entry 965 | // assigning a new content fragment and the list of updates. 966 | 967 | if (!entry || entry.template !== template || entry.type !== type) info.entry = entry = createEntry(type, template); 968 | var _entry = entry, 969 | content = _entry.content, 970 | updates = _entry.updates, 971 | wire = _entry.wire; // even if the fragment and its nodes is not live yet, 972 | // it is already possible to update via interpolations values. 973 | 974 | for (var i = 0; i < length; i++) { 975 | updates[i](values[i]); 976 | } // if the entry was new, or representing a different template or type, 977 | // create a new persistent entity to use during diffing. 978 | // This is simply a DOM node, when the template has a single container, 979 | // as in ``, or a "wire" in `` and similar cases. 980 | 981 | 982 | return wire || (entry.wire = persistent(content)); 983 | }; // the stack retains, per each interpolation value, the cache 984 | // related to each interpolation value, or null, if the render 985 | // was conditional and the value is not special (Array or Hole) 986 | 987 | var unrollValues = function unrollValues(_ref3, values, length) { 988 | var stack = _ref3.stack; 989 | 990 | for (var i = 0; i < length; i++) { 991 | var hole = values[i]; // each Hole gets unrolled and re-assigned as value 992 | // so that domdiff will deal with a node/wire, not with a hole 993 | 994 | if (hole instanceof Hole) values[i] = unroll(stack[i] || (stack[i] = createCache()), hole); // arrays are recursively resolved so that each entry will contain 995 | // also a DOM node or a wire, hence it can be diffed if/when needed 996 | else if (isArray(hole)) unrollValues(stack[i] || (stack[i] = createCache()), hole, hole.length); // if the value is nothing special, the stack doesn't need to retain data 997 | // this is useful also to cleanup previously retained data, if the value 998 | // was a Hole, or an Array, but not anymore, i.e.: 999 | // const update = content => html`1?n-1:0),a=1;a