diff --git a/CHANGELOG.md b/CHANGELOG.md index 751e43e..ed9c7d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 0.7.4 -`improve` improve cache handler which gains overall performance up to 20%
+`improve` inherit cache from factory
`improve` add fast path within reconciliation
+`improve` indices requires no sync anymore
+`change` remove dom indices, method access by index is now recommended (access by node is still supported but has extra costs, prevent looping via method access by node)
+`new` method ___dispatch___ to call/invoke an event handler manually
`fix` external/internal stores
## 0.7.3 diff --git a/README.md b/README.md index a269fab..e9575af 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,11 @@ __Demo:__ #### How to learn Mikado? -Thanks to the reversed engineering Mikado provides you one of the most simple to learn idiomatic style which are based on living standards. You do not have to learn a new language, you just need some basic skills you already have. __It will take 3 minutes to become productive.__ Don't let confuse you about the size of this documentation, because it will show you a lot of in-depth details, which are just missing in most of other framework documentations. You will do not need this details to start with. But when you would like to know more you have a chance to go deeper. +Thanks to the reversed engineering Mikado provides you one of the most simple to learn idiomatic style which are based on living standards. You do not have to learn a new language, you just need some basic skills you already have. __It will take 3 minutes to become productive.__ Don't let confuse you about the size of this documentation, because it will show you a lot of in-depth details, which are just missing in most of other framework documentations. You will do not need this details to start with. But when you would like to know more you get a chance to go deeper. Also all compiled dist files will work out of the box, no TypeScript, no Webpack, no module loader, no anything external is required. You can start out of the box seamlessly. No pain you might know from other frameworks. -Checklist for new developers (the most simple example, takes 3 minutes): +Guide for new developers (the most simple example, just takes 3 minutes): - Load this bundle through a script tag resource - Provide a basic template as native HTML5 template - Compile the template, create Mikado instance by passing the root node and the compiled template @@ -93,10 +93,12 @@ Checklist for new developers (the most simple example, takes 3 minutes): - Manipulate Views - Caching Helpers 14. DOM State Caching -15. Storage - - Loose Option +15. Stores: + - Internal Store + - Loose Store - Extern/Custom Store - - Export / Import Views + - Reactive Store + - Export / Import Stores 16. State 17. Callbacks 18. Transport / Load Templates @@ -407,16 +409,16 @@ Values represents operations per second, each benchmark task has to process a da 2.8 27 18745 - 6030 + 8124 92669 - 45868 + 49554 299140 35254 27563 31265 - 25182 - 993 - 59354 + 25276 + 994 + 60020 @@ -432,7 +434,7 @@ Values represents operations per second, each benchmark task has to process a da 7443 2302 15982 - 200 + 196 3099 @@ -449,7 +451,7 @@ Values represents operations per second, each benchmark task has to process a da 6614 2004 12622 - 178 + 175 2639 @@ -466,7 +468,7 @@ Values represents operations per second, each benchmark task has to process a da 2049 1464 24931 - 218 + 214 1385 @@ -482,7 +484,7 @@ Values represents operations per second, each benchmark task has to process a da 1769 1186 27131 - 162 + 157 1232 @@ -498,7 +500,7 @@ Values represents operations per second, each benchmark task has to process a da 1560 1187 23713 - 168 + 165 1093 @@ -515,7 +517,7 @@ Values represents operations per second, each benchmark task has to process a da 1577 1096 18047 - 164 + 161 1043 @@ -532,7 +534,7 @@ Values represents operations per second, each benchmark task has to process a da 1129 860 5520 - 89 + 86 784 @@ -549,7 +551,7 @@ Values represents operations per second, each benchmark task has to process a da 864 603 11765 - 160 + 158 715 @@ -566,7 +568,7 @@ Values represents operations per second, each benchmark task has to process a da 761 550 4964 - 82 + 80 538 @@ -583,7 +585,7 @@ Values represents operations per second, each benchmark task has to process a da 298 212 1944 - 38 + 37 223 @@ -609,6 +611,10 @@ The file size and memory gets less relevance. The maximum possible ___index___ i Read more about this test and also show ranking table for "non-keyed" and "data-driven" here. +##### Worst Case Scenario + +Mikado has no specific worst case scenario. The replace test could be named like this, but that is always the worst case scenario for every lib. This test simply couldn't use most of the runtime optimizations. + ## API Overview @@ -627,6 +633,10 @@ Global methods (not included in mikado.light.js): - Mikado.__compile__(\) - Mikado.__load__(url, \) - Mikado.__unload__(template) +- mikado.__route__(name, handler) +- mikado.__listen__(event) +- mikado.__unlisten__(event) +- mikado.__dispatch__(name, \, \, \) Instance methods: - view.__init__(\, \) @@ -657,10 +667,13 @@ Instance methods (not included in mikado.light.js): - view.__import__() - view.__export__() - view.__load__(url, \) - -DOM manipulation helpers (optional, not included in mikado.light.js): +- view.__route__(name, handler) - view.__listen__(event) - view.__unlisten__(event) +- view.__dispatch__(name, \, \, \) + +DOM manipulation helpers (optional, not included in mikado.light.js): + - view.__move__(node | index, index) - view.__shift__(node | index, index) - view.__up__(node | index) @@ -738,13 +751,13 @@ Global helpers (optional, not included in mikado.light.js): store - Passed data for rendering are also stored and synchronized along the virtual dom. You can re-render the full state at any time, without passing the data.
Notice: When passing an external reference of an existing Array-like object to the field "store" the store will perform all modifications directly to this reference (read more about "Extern Storage"). + Passed data for rendering are also stored and synchronized along the virtual dom. You can re-render the full state at any time, without passing the data.
Notice: When passing an external reference of an existing Array-like object to the field "store" the store will perform all modifications directly to this reference (read more about "External Store"). false loose - When storage is enabled this flag removes also data whenever a corresponding dom element was removed. + When store is enabled this flag removes also data whenever a corresponding dom element was removed. false @@ -1293,6 +1306,19 @@ Same way you could also unregister events: Mikado.unlisten("click"); ``` + +#### Dispatch Event Handler + +Manually dispatch an event: +```js +view.dispatch("handler"); +``` + +Manually dispatch an event and pass parameters: +```js +view.dispatch("handler", target, event, self); +``` + ## Keyed/Non-Keyed Modes @@ -1517,7 +1543,7 @@ view.destroy(); ## Render Templates -> When using an internal storage (not external), every render task also updates the storage data. +> When using an internal store (not external), every render task also updates the stored data. Render a template incrementally through a set of data items: ```js @@ -1732,7 +1758,9 @@ var name = view.template; ## Manipulate Views -Manual changes on the DOM may require re-syncing. To prevent re-syncing Mikado provides you several helper functions to manipulate the dom and also keep them in sync. Using the helper function also grants you a maximum performance. +Manual changes on the DOM may require re-syncing. To prevent re-syncing by applying manual changes Mikado provides you several optional helper functions to manipulate the dom and also keep them in sync. Using the helper function also grants you a maximum performance. + +> All helpers could be used by index or by node as passed parameters. Move a data item/node to a specific index: @@ -1781,6 +1809,12 @@ Swap two data items/nodes: view.swap(node_a, node_b); ``` +#### Some notes about helpers + +Those helpers are just missing in most of other libs, although there are so useful. It is just a pain when you want to apply a simple transformation but the lib forces you to run through the whole roundtrip. Super-advanced-fine-grained reconciliation isn't the holy grail, it is just for your laziness. Luckily Mikado provides you the most effective reconcile today, so that shouldn't be a problem. + +Let's come to the most absurd part. Especially data-driven reconciliation often becomes absolutely nonsense when you dealing with __internal data__ and you start to apply changes by hand like `data.push(item)` instead of simply doing this `view.add(item)`, or `var data = store(); data[0] = item; store(data);` instead of simply doing this `view.replace(0, item)`, the latter does not need reconciliation at all and performs faster by a huge factor and also it says what it does. Now take the helper methods and imagine you would apply them via data-driven. You will end up by start coding creepy things like `data.splice(index_a, 0, data.splice(index_b, 1)[0])`. Please do me the favor, use that helpers and don't pain yourself as well as your applications performance. Your users will thank you. + ## DOM State Caching @@ -1977,14 +2011,22 @@ view.sort(function(data_a, data_b){ --> -## Storage +## Stores + +Mikado provides 4 different type of stores. It is very useful to understand how they are handled. -Enable internal storage by passing the options during initialization: +#### 1. Internal Store + +An internal store gets updated automatically by Mikado. This comes with a small extra cost. Use this store when you need a reference to the data store as an array of items which are currently rendered. + +> When internal store is used, this store gets automatically updated by any of Mikados methods e.g. render/update/add/append/remove. + +Enable internal store by passing the options during initialization: ```js var view = new Mikado(template, { store: true }); ``` -Whenever you call the ___.render()___ function along with passed data, this data will keep in cache (internal storage). Mikado will handle those data for you. +Whenever you call the ___.render()___ function along with passed data, this data will updated (add/remove/change) to the internal store. ```js view.render(data); ``` @@ -2025,9 +2067,11 @@ view.store = store = []; ``` -#### Loose Option +#### 2. Loose Store (Default) + +When ___loose___ is enabled Mikado will use a data-to-dom binding strategy rather than keeping data separated from rendered elements/templates. This performs slightly faster and has lower memory footprint but you will also loose any data at the moment when the corresponding dom element was also removed from the screen (render stack). In most situation this is the expected behavior, but it depends on your application. -When ___loose___ is enabled Mikado will use a data-to-dom binding strategy rather than keeping data separated from rendered elements/templates. This performs generally faster and has lower memory footprint but you will also loose any data at the moment when the corresponding dom element was also removed from the screen (render stack). In most situation this shouldn't be an issue, but it depends on your application. +Initialize a loose store: ```js var view = new Mikado(template, { store: true, loose: true }); ``` @@ -2041,27 +2085,43 @@ var item = view.data(node); ``` -#### Extern/Custom Store +#### 3. External/Custom Store + +External stores differs from the other ones. An external store assumes to get updated from the outside and will not changed by Mikado. That means that you have to apply all changes to the external store before rendering. Use this store when: + +- you like to use data-driven style +- you need sharing the data store to your application functions or libs +- you like to make the data store immutable for Mikado + +> When external store is used, this store gets __not__ updated by any of Mikados methods e.g. render/update/add/append/remove. + +There is one exception: when you use proxy (observable attributes), the external store will replaced by the proxyfied reference once (otherwise the proxy feature becomes useless). You can also pass an reference to an external store. This store must be an Array-like type. ```js var MyStore = [ /* Item Data */ ]; ``` -Pass in the external storage when initializing: +Pass in the external store when initializing: ```js var view = new Mikado(root, template, { - store: MyStore, - loose: false, - persist: false + store: MyStore }); ``` +#### 4. Reactive Store (Observable Array) + +This is also an external store with all its attributes described above. Additionally this store reacts when indices gets changed (applies changes to DOM automatically). That makes reconciliation unnecessary but also has a noticeable extra cost for all other kind of updates. The main reason why this store is slower in the benchmark by a large margin is, that this store cannot apply a bulk of updates through a loop. It reacts at the moment the data was assigned/removed from an index. Still, this store could perform faster than all other ones depending on your application / current view. + +The reactive store could also be used in a combination with the proxy feature. Using both provides you a complete reactive store where you do not need calling any of Mikados methods anymore like render/reconcile/update/add/append/remove. All this methods gets redundant, because the view is completely synchronized along the whole state of your store. This combination and how they are integrated in Mikado are unique. The "repaint" test from the benchmark ist just an empty function call and performs astronomical. + +Read the documentation about this kind of store here. + #### Export / Import Views -You can export the data of a view to the local storage. +You can export the data of a view to the local store. ```js view.export(); ``` @@ -2585,7 +2645,7 @@ __Template markup__: > The expression for an observable property has to start with: `{{=` -Using proxy requires using one of the 3 storage strategies. +Using proxy requires using one of the 3 store strategies. __1. Use with internal store:__ ```js @@ -2906,7 +2966,7 @@ view.destroy(/* unload? */ true); Mikado comes with its own new diffing algorithm which gains performance of reconcile/re-arrangement. The algorithm is based on a concept "Longest Distance" which was invented by me, the author of this library. I also discovered two other concepts from scratch from where I have also implemented the "3-Way-Splice", but longest distance has slightly better overall performance. Although by a very small margin. Theoretically the splice concept has some advantages but it isn't that easy to make them capable. -Mikados reconcile provides you one of the most effective diffing today. +Mikados reconcile provides you the most effective diffing today (you can take the row "order" from the benchmark as a reference). ## Concept of Shared Pools diff --git a/bench/README.md b/bench/README.md index 691debd..689d5f1 100644 --- a/bench/README.md +++ b/bench/README.md @@ -30,8 +30,233 @@ There are 3 kinds of test scenarios: Weather a library provides optimizations to one of these modes or not, it is fair to compare each of them in a different scenario. +When the option "keep best run" is enabled it will replace the better result with the old one (separately for each test). When disabled, it will summarize the results for each test. + #### Keyed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LibraryKBRAMCreateReplaceUpdateOrderRepaintAppendRemoveToggleClearIndexScore
mikado2.82718745812492669495542991403525427563312652527699460020
inferno8.4311754724549352666055132374432302159821963099
mithril9.6263637612459942674997112066142004126221752639
domc4.539310781059108211291101112820491464249312141385
innerhtml0494102999999387688593517691186271311571232
surplus15.862697585784985484687815601187237131651093
sinuous7.565084280981282482081315771096180471611043
jquery31.36848097077036436526981129860552086784
redom2.9109044944145045145246886460311765158715
lit-html17.31179441411409413409431761550496480538
ractive68.24684165156158158159166298212194437223
knockout24.82657916768686884130103116246175
+ +#### Recycle (Non-Keyed) + @@ -55,16 +280,16 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + - + - - + + @@ -80,7 +305,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -97,7 +322,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -114,7 +339,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -131,7 +356,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -148,7 +373,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -164,7 +389,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -180,7 +405,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -197,7 +422,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -214,7 +439,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -231,7 +456,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -253,229 +478,6 @@ Weather a library provides optimizations to one of these modes or not, it is fai
2.8 25 1843260147822 903354695148761 284969 34245 27452 30704 256749871804599418232
22497 4617 25167493478 5271
8317 1645 5021235224 2607
7366 2345 16151200198 1272
7191 2011 12604198193 1200
6620 1530 12348232226 1167
1636 1186 27371159157 791
1540 1155 25324171169 740
2970 616 17688682 716
1609 1075 16384157155 678
1136 872 55318886 503
-#### Recycle (Non-Keyed) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LibraryKBRAMCreateReplaceUpdateOrderRepaintAppendRemoveToggleClearIndexScore
mikado2.82718745603092669458682991403525427563312652518299359354
inferno8.4311754724549352666055132374432302159822003099
mithril9.6263637612459942674997112066142004126221782639
domc4.539310781059108211291101112820491464249312181385
innerhtml0494102999999387688593517691186271311621232
surplus15.862697585784985484687815601187237131681093
sinuous7.565084280981282482081315771096180471641043
jquery31.36848097077036436526981129860552089784
redom2.9109044944145045145246886460311765160715
lit-html17.31179441411409413409431761550496482538
ractive68.24684165156158158159166298212194438223
knockout24.82657916768686884130103116246175
- #### Data-Driven (Internal) @@ -500,8 +502,8 @@ Weather a library provides optimizations to one of these modes or not, it is fai - - + + @@ -510,7 +512,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -526,7 +528,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -543,7 +545,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -560,7 +562,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -577,7 +579,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -594,7 +596,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -610,7 +612,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -626,7 +628,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -643,7 +645,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -660,7 +662,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + @@ -677,7 +679,7 @@ Weather a library provides optimizations to one of these modes or not, it is fai - + diff --git a/bench/bench.js b/bench/bench.js index dfdf1f0..ec8d4de 100644 --- a/bench/bench.js +++ b/bench/bench.js @@ -55,7 +55,7 @@ if(params["duration"] && (params["duration"].indexOf("run-") !== -1)){ } else{ - duration = parseFloat(params["duration"] || "3") * 1000; + duration = parseFloat(params["duration"] || "5") * 1000; } const hidden = params["hidden"] !== "false"; @@ -391,7 +391,7 @@ window.onload = function(){ item.test || (item.test = suite[lib]); } - setTimeout(perform, 500); + setTimeout(perform, 200); } }; @@ -554,7 +554,7 @@ function perform(){ status = false; } - let loops = 0, now = perf.now(); + let loops = 0, now = 0; if(status){ @@ -567,10 +567,15 @@ function perform(){ // return; // } - const end = now + duration; + const end = perf.now() + duration; for(let start, mem_start, mem; now < end; loops++){ + if(runs && (runs === loops)){ + + break; + } + if(test.start) test.start(loops); if(!internal && test.prepare) test.prepare(loops); @@ -580,15 +585,10 @@ function perform(){ test.fn(clone); now = perf.now(); mem = perf.memory.usedJSHeapSize - mem_start; - elapsed += now - start; + elapsed += (now - start); if(mem > 0) memory += mem; if(test.end) test.end(loops); - - if(runs && (runs === loops + 1)){ - - break; - } } if(test.complete) test.complete(); @@ -602,16 +602,16 @@ function perform(){ if(window === window.top){ - result.nodeValue = (str_results += (status ? test.name.padEnd(12) + String(Math.floor(1000 / elapsed * loops)).padStart(8) + " op/s, Memory:\t" + (memory ? Math.floor(memory / loops) : "-") : "- failed -") + "\n") + (current < queue.length ? "running..." : ""); + result.nodeValue = (str_results += (status ? test.name.padEnd(12) + String(Math.floor(1000 / elapsed * loops)).padStart(8) + " op/s, Memory:\t" + (memory ? Math.ceil(memory / loops) : "-") : "- failed -") + "\n") + (current < queue.length ? "running..." : ""); } else{ - window.top.postMessage(test.name + "," + (status ? Math.floor(1000 / elapsed * loops) : 0) + "," + (status ? Math.floor(memory / loops) : 0), location.protocol + "//" + location.hostname) //"https://nextapps-de.github.io" "https://raw.githack.com" + window.top.postMessage(test.name + "," + (status ? Math.floor(1000 / elapsed * loops) : 0) + "," + (status ? Math.ceil(memory / loops) : 0), location.protocol + "//" + location.hostname) //"https://nextapps-de.github.io" "https://raw.githack.com" } if(current < queue.length){ - setTimeout(perform, 500); + setTimeout(perform, 200); } else{ diff --git a/bench/index.html b/bench/index.html index 356599b..ddd9e9d 100644 --- a/bench/index.html +++ b/bench/index.html @@ -33,7 +33,7 @@

Benchmark of Web Templating Engines (Stress Test)

mikado 2.8 15174816015180557789 71626 45370 29487730799 25028 10004792248211
14914 3703 22609422405 13764
18119 3034 15289368364 3311
13561 3480 20871321317 2564
6100 2363 14419191188 2173
6664 1964 12248173171 1870
1675 1167 20810139135 957
1112 856 55538885 636
865 566 11737159158 604
800 554 50278179 444
320 191 10565756 195
- + @@ -48,29 +48,30 @@

Benchmark of Web Templating Engines (Stress Test)

Duration: Repeat: - @@ -82,7 +83,7 @@

Benchmark of Web Templating Engines (Stress Test)

- keep best run + keep best run
diff --git a/bench/main.js b/bench/main.js index d358707..951f495 100644 --- a/bench/main.js +++ b/bench/main.js @@ -7,12 +7,15 @@ const mikado = Mikado(document.getElementById("result"), "row", options); const list = Mikado(document.getElementById("lib"), "lib", options); + const modes = window.location.hash.indexOf("modes") !== -1; let strict; - let modes = window.location.hash.indexOf("modes") !== -1; let internal; let keyed; + let keep; + let repeat; + let index = -1; - const lib = shuffle(modes ? [ + let lib = shuffle(modes ? [ "mikado-cross-shared", "mikado-exclusive", "mikado-keyed", "mikado-keyed-shared", "mikado-non-keyed", "mikado-proxy", @@ -42,8 +45,6 @@ init(window.location.hash); - let index = -1; - document.getElementById("mode").options[keyed ? 1 : internal ? 2 : 0].selected = true; if(modes){ @@ -56,8 +57,9 @@ if(target.value === "Start"){ index = -1; + repeat = document.getElementById("repeat").value; target.value = "Stop"; - setTimeout(runner, 100); + setTimeout(runner, 200); } else{ @@ -81,7 +83,7 @@ "remove", "toggle", "clear" ]; - let current = new Array(lib.length); + const current = new Array(lib.length); let size = { @@ -131,10 +133,12 @@ function runner(){ const duration = document.getElementById("duration").value; + keep = document.getElementById("keep").checked; index++; - current[index][test[2]] = "run..."; - mikado.update(mikado.node(index), current[index]); + const tmp = Object.assign({}, current[index]); + tmp[test[2]] = "run..."; + mikado.update(mikado.node(index), tmp); iframe.src = "test/" + lib[index].toLowerCase() + "/" + (keyed ? "keyed.html" : strict ? "strict.html" : internal ? "internal.html" : "") + ("?duration=" + duration); } @@ -239,12 +243,43 @@ if(event.origin === location.protocol + "//" + location.hostname){ // "https://nextapps-de.github.io" "https://raw.githack.com" + //console.log(event.data); + const parts = event.data.split(","); - current[index][parts[0]] = parseInt(parts[1], 10); - current[index]["memory"] += parseInt(parts[2], 10); + let tmp = parseInt(parts[1], 10); + + if(keep){ + + if(!current[index][parts[0]] || (tmp > current[index][parts[0]])){ + + current[index][parts[0]] = tmp; + } + } + else{ + + if(current[index][parts[0]]){ + + current[index][parts[0]] += tmp; + } + else{ + + current[index][parts[0]] = tmp; + } + } - if(!current[index][parts[0]]){ + tmp = parseInt(parts[2], 10); + + if(current[index]["memory"]){ + + current[index]["memory"] += tmp; + } + else{ + + current[index]["memory"] = tmp; + } + + if((repeat === 1) && (!current[index][parts[0]])){ current[index][parts[0]] = "-failed-"; } @@ -253,7 +288,8 @@ if(index < lib.length - 1){ - setTimeout(runner, 200); + mikado.update(index, current[index]); + setTimeout(runner, 50); } else{ @@ -264,16 +300,30 @@ return b["score"] - a["score"]; }); + for(let i = 0; i < lib.length; i++){ + + lib[i] = current[i]["name"]; + } + mikado.render(current); - return; + + if(--repeat > 0){ + + index = -1; + setTimeout(runner, 50); + } + else{ + + Mikado.dispatch("start", document.getElementById("start")); + } } } else{ - current[index][test[test.indexOf(parts[0]) + 1]] = "run..."; + const tmp = Object.assign({}, current[index]); + tmp[test[test.indexOf(parts[0]) + 1]] = "run..."; + mikado.update(index, tmp); } - - mikado.refresh(index); } } }; diff --git a/bench/test/mikado/dist/mikado.light.js b/bench/test/mikado/dist/mikado.light.js index 8397283..d4c283f 100644 --- a/bench/test/mikado/dist/mikado.light.js +++ b/bench/test/mikado/dist/mikado.light.js @@ -1,24 +1,25 @@ /**! - * Mikado.js v0.7.4 (Light) + * Mikado.js v0.7.42 (Light) * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Licence: Apache-2.0 * https://github.com/nextapps-de/mikado */ -(function(){'use strict';var p;var w={},z={},B={},C={},D={};function E(a,b,c){if(!(this instanceof E))return new E(a,b,c);a.nodeType||(c=b,b=a,a=null);a?this.mount(a):(this.b=this.f=null,this.length=0);this.init(b,c)}var F=E.register=function(a,b){b||(b=a,a=b.n);z[a]=b;return E};E.prototype.mount=function(a){if(this.b!==a){this.key&&this.b&&(this.b._o=this.l,this.l=a._o||{});this.b=a;G(this);var b;if(!(b=a._d)){b=a.children;for(var c=b.length,e=Array(c),f=0,d;fg?k:g,t=0,x=this.key;for(c||(c=0);c=k)){k++;h=k>g?k:g;var n=1;this.add(q,b,c,null,1);continue}var r=f[c],y=r._k;if(y===l){n&&(r._i=c);e&&this.update(r,q,b,c);continue}for(var u=void 0,A=void 0,v=c+1;v=A?(m=f[u-1],this.b.insertBefore(m,r),m._i=c,e&&this.update(m,q,b,c),u===A?(1k?k:n)-1),n=1,t--,c--);m=1;break}}m||(this.remove(c,1,0,1),n=1,k--,h=k>g?k:g,c--)}return this};function J(a,b,c,e){var f=e||a[b];e&&b++;if(bc;b--)a[b]=a[b-1];a[c]=f} -p.add=function(a,b,c,e,f){if(!e)if("number"===typeof b){c=b;b=null;var d=1}else if(c||0===c)d=1;c=e||d?c:this.length;a=this.create(a,b,c);a._i=c;if(d){if(this.b.insertBefore(a,this.f[c]||null),J(this.f,this.length-1,c,a),this.length++,!f)for(;++ca&&(a=f+a-1));if(!f||a>=f)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);if(!a&&b>=f){var d=this.f;b=d.length;this.b.textContent="";this.b._d=this.f=c?Array(c):[];f=0}else d=this.f.splice(a,b),f-=b;this.length=f;if(!e&&a"===q?h=h.firstElementChild:"+"===q?h=h.nextElementSibling:"|"===q&&(h=h.firstChild),e[m]=h)}}f[k]=h}return b._p=f}var L; -function H(a,b,c,e,f){if(!c){var d=B[b.n+(a.cache?"$":"")];if(d)return a.v=d.v,a.o=d.o,a.g=d.g,d.node}d=document.createElement(b.t||"div");c||(c=0,e="&",L="",a.g=[],d._p=f=[],a.cache&&(d.$={}));var g=b.s,k=b.i,h=b.x,t=b.h,x=b.a,m=b.c,q=b.j,l=a.g.length,n=0,r="";q&&(r+=";"+q,-1",l=0;l",f));c||(!a.o&&L&&(a.v=Function("p","s","data","index","view", -'"use strict";var self,v'+L)),B[b.n+(a.cache?"$":"")]={v:a.v,o:a.o,g:a.g,node:d});return d}function M(a,b,c){L=1g?l:g,r=0,x=this.key;for(c||(c=0);c=l,n=void 0,t=void 0,y=void 0;if(!h&&(n=f[c],t=m[x],y=n._k,y===t)){d&&this.update(n,m,b,c);continue}if(d&&(h||!e[t])){h||!this.u?(l++,k=l>g?l:g,this.add(m,b,c)):this.replace(n,m,b,c);continue}for(var u=h=void 0,w=c+1;w=u?(p=f[h-1],this.b.insertBefore(p,n||null),d&&this.update(p, +m,b,c),h===u?(1l?l:m)-1),r--,c--);p=1;break}}p||(this.remove(c),l--,k=l>g?l:g,c--)}return this};function I(a,b,c,d){var f=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=f} +q.add=function(a,b,c,d){if(!d)if("number"===typeof b){c=b;b=null;var f=1}else if(c||0===c)f=1;c=d||f?c:this.length;a=this.create(a,b,c);f?(this.b.insertBefore(a,this.f[c]||null),I(this.f,this.length-1,c,a),this.length++):(d?this.b.replaceChild(a,d):(this.b.appendChild(a),this.length++),this.f[c]=a);return this};q.clear=function(){this.length&&this.remove(0,this.length);return this};q.destroy=function(a){a&&this.unload();this.length=0;this.f=this.b=this.v=this.g=this.w=this.A=this.l=null}; +q.append=function(a,b,c){if("number"===typeof b){c=b;b=null;var d=1}else d=c||0===c;for(var f=a.length,e=0;ea&&(a=d+a-1));if(!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;!a&&b>=d?(a=this.f,b=a.length,this.b.textContent="",this.b._d=this.f=c?Array(c):[],d=0):(a=this.f.splice(a,b),d-=b);this.length=d;if(this.m&&!this.u&&1"===m?k=k.firstElementChild:"+"===m?k=k.nextElementSibling:"|"===m&&(k=k.firstChild),d[p]=k)}}f[l]=k}return b._p=f}var K; +function G(a,b,c,d,f){if(!c){var e=A[b.n+(a.cache?"$":"")];if(e)return a.w=e.w,a.o=e.o,a.g=e.g,e.node}e=document.createElement(b.t||"div");c||(c=0,d="&",K="",a.g=[],e._p=f=[],a.cache&&(e.$={}));var g=b.s,l=b.i,k=b.x,r=b.h,x=b.a,p=b.c,m=b.j,h=a.g.length,n=0,t="";m&&(t+=";"+m,-1",h=0;h",f),e.appendChild(d);c||(!a.o&&K&&(a.w=Function("p","s","data","index", +"view",'"use strict";var self,v'+K)),A[b.n+(a.cache?"$":"")]={w:a.w,o:a.o,g:a.g,node:e});return e}function L(a,b,c){K=1Math.abs(G-b)&&50>Math.abs(H-c)&&D.call(this,a,"tap")},ha=function(a){ea(a,a.touches)};aa=function(a){l(a,B?"pointerdown":"touchstart",ha,!1);l(a,B?"pointerup":"touchend",fa,!1)}} -F.listen=F.prototype.listen=function(a,b){E[a]||(l(1,a,D,b||!0),E[a]=1);return this};F.unlisten=F.prototype.unlisten=function(a,b){E[a]&&(l(0,a,D,b||!0),E[a]=0);return this};k=F.prototype;k.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=a._i;0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; -k.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;var e=0>b;if(e&&d||!e&&db;e--)d=this.b[e]=this.b[e- -1],d._i=e,this.store&&(this.store[e]=this.store[e-1]);else for(e=d;eb&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};k.after=function(a,b){"number"!==typeof a&&(a=a._i);"number"!==typeof b&&(b=b._i);b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; -k.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;if("number"===typeof b){var e=b;b=this.b[b]}else e=b._i;if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),a._i=e,b._i=d,this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= -a)}return this};var I={};function ia(a){return I[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ja(a,b){J(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ka(a,b){b=(a._c||(a._c=a.className)).replace(I[b]||ia(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function J(a,b){return!!(a._c||(a._c=a.className)).match(I[b]||ia(b))}function la(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var ma=window.localStorage;F.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.v.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.v.add(c,a,this.view);P=!1;return b};k.push=function(a){P=!0;this.v.add(a,this.view);this.v.proxy||(this[this.length]=a);L&&this.length++;P=!1};k.unshift=function(a){P=!0;this.v.add(a,0,this.view);this.D.unshift(a);P=!1}; -k.pop=function(){P=!0;this.v.remove(this.length-1);var a=this.D.pop();P=!1;return a};k.shift=function(){P=!0;this.v.remove(0);var a=this.D.shift();P=!1;return a};k.concat=function(a){for(var b=a.length,c=0;cg?h:g,n=0,y=this.key;for(c||(c=0);c=h)){h++;m=h>g?h:g;var u=1;this.add(p,b,c,null,1);continue}var t=e[c],A=t._k;if(A===w){u&&(t._i=c);d&&this.update(t,p,b,c);continue}for(var v=void 0,z=void 0,q=c+1;q=z?(r=e[v-1],this.root.insertBefore(r,t),r._i=c,d&&this.update(r,p,b,c),v===z?(1h?h:u)-1),u=1,n--,c--);r=1;break}}r||(this.remove(c,1,0,1),u=1,h--,m=h>g?h:g,c--)}this.store&&!this.K&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} -k.add=function(a,b,c,d,e){if(!d)if("number"===typeof b){c=b;b=null;var f=1}else if(c||0===c)f=1;c=d||f?c:this.length;b=this.create(a,b,c);var g;this.proxy&&(this.w&&this.B&&b._m===a?g=1:a._y||(a=ra(a,b._p||V(this,b),this.proxy)));g||(this.store?f&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));b._i=c;if(f){if(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++,!e)for(;++ca&&(a=e+a-1));if(!e||a>=e)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);if(!a&&b>=e){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.A||this.o))for(b=0;b"===p?m=m.firstElementChild:"+"===p?m=m.nextElementSibling:"|"===p&&(m=m.firstChild),d[r]=m)}}e[h]=m}return b._p=e}var X; -function U(a,b,c,d,e){if(!c){var f=R[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.w=f.w,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[],a.cache&&(f.$={}));var g=b.s,h=b.i,m=b.x,n=b.h,y=b.a,r=b.e,p=b.c,w=b.j,u=a.u.length,t=0,A=0,v="";w&&(v+=";"+w,-1",C=0;C",e))}b.f&&(X+="}else "+(1Math.abs(H-b)&&50>Math.abs(I-c)&&D.call(this,a,"tap")},fa=function(a){da(a,a.touches)};aa=function(a){l(a,B?"pointerdown":"touchstart",fa,!1);l(a,B?"pointerup":"touchend",ea,!1)}}G.listen=G.prototype.listen=function(a,b){F[a]||(l(1,a,D,b||!0),F[a]=1);return this};G.unlisten=G.prototype.unlisten=function(a,b){F[a]&&(l(0,a,D,b||!0),F[a]=0);return this};k=G.prototype;k.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=this.index(a);0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; +k.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);var e=0>b;if(e&&d||!e&&db;d--)this.b[d]= +this.b[d-1],this.store&&(this.store[d]=this.store[d-1]);else for(;db&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};k.after=function(a,b){"number"!==typeof a&&(a=this.index(a));"number"!==typeof b&&(b=this.index(b));b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; +k.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);if("number"===typeof b){var e=b;b=this.b[b]}else e=this.index(b);if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= +a)}return this};var J={};function ha(a){return J[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ia(a,b){K(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ja(a,b){b=(a._c||(a._c=a.className)).replace(J[b]||ha(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function K(a,b){return!!(a._c||(a._c=a.className)).match(J[b]||ha(b))}function ka(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var la=window.localStorage;G.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.w.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.w.add(c,a,this.view);Q=!1;return b};k.push=function(a){Q=!0;this.w.add(a,this.view);this.w.proxy||(this[this.length]=a);M&&this.length++;Q=!1};k.unshift=function(a){Q=!0;this.w.add(a,0,this.view);this.D.unshift(a);Q=!1}; +k.pop=function(){Q=!0;this.w.remove(this.length-1);var a=this.D.pop();Q=!1;return a};k.shift=function(){Q=!0;this.w.remove(0);var a=this.D.shift();Q=!1;return a};k.concat=function(a){for(var b=a.length,c=0;ch?m:h,y=0,v=this.key;e&&(this.store=0);for(c||(c=0);c=m,t=void 0,A=void 0,w=void 0;if(!q&&(t=f[c],A=r[v],w=t._k,w===A)){d&&this.update(t,r,b,c);continue}if(d&&(q||!g[A])){q||!this.v?(m++,n=m>h?m:h,this.add(r,b,c)):this.replace(t,r,b,c);continue}for(var z=q=void 0,u=c+1;u=z?(p=f[q- +1],this.root.insertBefore(p,t||null),d&&this.update(p,r,b,c),q===z?(1m?m:r)-1),y--,c--);p=1;break}}p||(this.remove(c),m--,n=m>h?m:h,c--)}e&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} +k.add=function(a,b,c,d){if(!d)if("number"===typeof b){c=b;b=null;var e=1}else if(c||0===c)e=1;c=d||e?c:this.length;b=this.create(a,b,c);var f;this.proxy&&(this.A&&this.B&&b._m===a?f=1:a._y||(a=qa(a,b._p||Aa(this,b),this.proxy)));f||(this.store?e&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));e?(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++):(d?this.root.replaceChild(b,d):(this.root.appendChild(b),this.length++), +this.b[c]=b);var g;(g=this.J)&&(g=g.insert)&&g(b);return this};k.clear=function(a){this.length&&this.remove(0,this.length);if(a){S[this.l+(this.cache?"$":"")]=null;if(this.key)if(this.length){a=Object.keys(this.g);for(var b=0,c=a.length,d=void 0;ba&&(a=d+a-1));if(!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;if(!a&&b>=d){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.v||this.o))for(b=0;b"===p?m=m.firstElementChild:"+"===p?m=m.nextElementSibling:"|"===p&&(m=m.firstChild),d[v]=m)}}e[h]=m}return b._p=e}var X; +function V(a,b,c,d,e){if(!c){var f=S[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.A=f.A,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[]);var g=b.s,h=b.i,m=b.x,n=b.h,y=b.a,v=b.e,p=b.c,r=b.j,q=a.u.length,t=0,A=0,w="";r&&(w+=";"+r,-1",w=0;w",e);f.appendChild(d)}b.f&&(X+="}else "+(1h.length&&h.unshift("value"),g=h[0],h="{{=="+h[1]+"}}"),Da[g.substring(2)]&&-1!==h.indexOf("{{")&&(g=g.substring(2)),Da[g]?Z(c.e||(c.e={}),g,h):Z(c.a||(c.a={}),g,h))}}a=a.childNodes;if(d=a.length){for(f=e=0;fBenchmark: mikado-0.7.0 (recycle)
const mikado = new Mikado(root, template, { "store": false, - "reuse": true, "pool": false, - "keep": true, - "cache": true + "keep": true }); suite["mikado"] = function(items){ diff --git a/bench/test/mikado/internal.html b/bench/test/mikado/internal.html index 8069598..cf4ee43 100644 --- a/bench/test/mikado/internal.html +++ b/bench/test/mikado/internal.html @@ -21,10 +21,8 @@

Benchmark: mikado-0.7.0 (data-driven)


const mikado = new Mikado(root, template, { "store": store(), - "reuse": true, "pool": false, - "keep": true, - "cache": true + "keep": true }); suite["mikado"] = function(items){ diff --git a/bench/test/mikado/keyed.html b/bench/test/mikado/keyed.html index 1de4a8b..8b16d0b 100644 --- a/bench/test/mikado/keyed.html +++ b/bench/test/mikado/keyed.html @@ -19,8 +19,7 @@

Benchmark: mikado-0.7.0 (keyed)


"store": false, "reuse": false, "pool": false, - "keep": true, - "cache": true + "keep": true }); suite["mikado"] = function(items){ diff --git a/dist/mikado.debug.js b/dist/mikado.debug.js index dbced24..1f2c7f3 100644 --- a/dist/mikado.debug.js +++ b/dist/mikado.debug.js @@ -1,5 +1,5 @@ /**! - * Mikado.js v0.7.4 + * Mikado.js v0.7.42 * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Licence: Apache-2.0 @@ -156,6 +156,10 @@ if (SUPPORT_EVENTS) { listener[id] = fn; return this; }; + Mikado$$module$tmp$mikado["dispatch"] = Mikado$$module$tmp$mikado.prototype.dispatch = function(id, target, event, event_target) { + listener[id](target, event, event_target); + return this; + }; var touch_x; var touch_y; var register_tap; @@ -201,8 +205,6 @@ if (SUPPORT_EVENTS) { var module$tmp$event = {}; if (SUPPORT_HELPERS) { var update = function(dom, store, a, b, index_b, index_a) { - a["_idx"] = index_b; - b["_idx"] = index_a; dom[index_a] = b; dom[index_b] = a; if (SUPPORT_STORAGE && store) { @@ -218,7 +220,7 @@ if (SUPPORT_HELPERS) { index = node; node = this.dom[index]; } else { - index = node["_idx"]; + index = this.index(node); } if (position < 0) { position = this.length + position - 1; @@ -239,7 +241,7 @@ if (SUPPORT_HELPERS) { index = a; a = this.dom[a]; } else { - index = a["_idx"]; + index = this.index(a); } var up = offset < 0; if (up && index || !up && index < this.length - 1) { @@ -260,7 +262,6 @@ if (SUPPORT_HELPERS) { if (up) { for (var i = index; i > pos; i--) { current = this.dom[i] = this.dom[i - 1]; - current["_idx"] = i; if (SUPPORT_STORAGE && this.store) { this.store[i] = this.store[i - 1]; } @@ -268,14 +269,12 @@ if (SUPPORT_HELPERS) { } else { for (var i$2 = index; i$2 < pos; i$2++) { current = this.dom[i$2] = this.dom[i$2 + 1]; - current["_idx"] = i$2; if (SUPPORT_STORAGE && this.store) { this.store[i$2] = this.store[i$2 + 1]; } } } current = this.dom[pos] = tmp$1; - current["_idx"] = pos; if (SUPPORT_STORAGE && this.store) { this.store[pos] = tmp_store; } @@ -315,10 +314,10 @@ if (SUPPORT_HELPERS) { if (SUPPORT_HELPERS === true || SUPPORT_HELPERS && SUPPORT_HELPERS.indexOf("before") !== -1) { Mikado$$module$tmp$mikado.prototype.before = function(tmp_a, tmp_b) { if (typeof tmp_a !== "number") { - tmp_a = tmp_a["_idx"]; + tmp_a = this.index(tmp_a); } if (typeof tmp_b !== "number") { - tmp_b = tmp_b["_idx"]; + tmp_b = this.index(tmp_b); } if (tmp_b !== tmp_a + 1) { if (tmp_b < 0) { @@ -338,10 +337,10 @@ if (SUPPORT_HELPERS) { if (SUPPORT_HELPERS === true || SUPPORT_HELPERS && SUPPORT_HELPERS.indexOf("after") !== -1) { Mikado$$module$tmp$mikado.prototype.after = function(tmp_a, tmp_b) { if (typeof tmp_a !== "number") { - tmp_a = tmp_a["_idx"]; + tmp_a = this.index(tmp_a); } if (typeof tmp_b !== "number") { - tmp_b = tmp_b["_idx"]; + tmp_b = this.index(tmp_b); } if (tmp_b !== tmp_a - 1) { if (tmp_b < 0) { @@ -367,13 +366,13 @@ if (SUPPORT_HELPERS) { tmp_a = a; a = this.dom[a]; } else { - tmp_a = a["_idx"]; + tmp_a = this.index(a); } if (typeof b === "number") { tmp_b = b; b = this.dom[b]; } else { - tmp_b = b["_idx"]; + tmp_b = this.index(b); } if (SUPPORT_STORAGE && this.reuse && (this.store || this.loose)) { var tmp = this.store ? this.store[tmp_a] : a["_data"]; @@ -385,8 +384,6 @@ if (SUPPORT_HELPERS) { if (no_predecessor && tmp_b + 1 !== tmp_a) { this.root.insertBefore(b, this.dom[tmp_a + 1] || null); } - a["_idx"] = tmp_b; - b["_idx"] = tmp_a; this.dom[tmp_a] = b; this.dom[tmp_b] = a; if (SUPPORT_STORAGE && this.store && !this.extern) { @@ -938,7 +935,12 @@ if (SUPPORT_POOLS && (SUPPORT_HELPERS === true || SUPPORT_HELPERS && SUPPORT_HEL }; } Mikado$$module$tmp$mikado.prototype.index = function(node) { - return node["_idx"]; + for (var i = 0, length = this.length; i < length; i++) { + if (this.dom[i] === node) { + return i; + } + } + return -1; }; Mikado$$module$tmp$mikado.prototype.node = function(index) { return this.dom[index]; @@ -946,7 +948,7 @@ Mikado$$module$tmp$mikado.prototype.node = function(index) { if (SUPPORT_STORAGE) { Mikado$$module$tmp$mikado.prototype.data = function(index) { var get_by_node = typeof index === "object"; - return this.store ? this.store[get_by_node ? index["_idx"] : index] : (get_by_node ? index : this.dom[index])["_data"]; + return this.store ? this.store[get_by_node ? this.index(index) : index] : (get_by_node ? index : this.dom[index])["_data"]; }; if (SUPPORT_HELPERS === true || SUPPORT_HELPERS && SUPPORT_HELPERS.indexOf("find") !== -1) { Mikado$$module$tmp$mikado.prototype.find = function(data) { @@ -1113,7 +1115,6 @@ function collection_to_array$$module$tmp$mikado(collection) { var array = new Array(length); for (var i = 0, node = undefined; i < length; i++) { node = collection[i]; - node["_idx"] = i; array[i] = node; } return array; @@ -1151,6 +1152,9 @@ Mikado$$module$tmp$mikado.prototype.create = function(data, view, index) { } else { factory = 1; node = this.factory; + if (SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && node && this.cache) { + node["_cache"] = {}; + } } } if (!SUPPORT_STORAGE || !SUPPORT_REACTIVE || !found || !this.stealth || this.observe) { @@ -1158,8 +1162,8 @@ Mikado$$module$tmp$mikado.prototype.create = function(data, view, index) { } if (factory) { node = this.factory.cloneNode(true); - if (SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS) { - node["_cache"] = Object.assign({}, this.factory["_cache"]); + if (SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && this.cache) { + node["_cache"] = this.factory["_cache"]; } var tmp; if (SUPPORT_CALLBACKS && (tmp = this.on) && (tmp = tmp["create"])) { @@ -1210,12 +1214,7 @@ if (SUPPORT_STORAGE) { if (typeof index === "number") { node = this.dom[index]; } else { - if (index && typeof(tmp = index["_idx"]) === "number") { - node = index; - index = tmp; - } else { - view = index; - } + view = index; } if (node) { return this.apply(node, null, view, index); @@ -1328,34 +1327,43 @@ Mikado$$module$tmp$mikado.prototype.render = function(data, view, callback, skip return this; }; Mikado$$module$tmp$mikado.prototype.reconcile = function(b, view, x, render) { + var store = SUPPORT_STORAGE && this.store && !this.extern; var a = this.dom; var keys = this.live; var end_b = b.length; var end_a = a.length; var max_end = end_a > end_b ? end_a : end_b; var shift = 0; - var has_update; var key = this.key; + if (store) { + this.store = 0; + } for (x || (x = 0); x < max_end; x++) { var found = undefined; if (x < end_b) { var b_x = b[x]; - var b_x_key = b_x[key]; - if (render && (!keys[b_x_key] || x >= end_a)) { - end_a++; - max_end = end_a > end_b ? end_a : end_b; - has_update = 1; - this.add(b_x, view, x, null, 1); - continue; - } - var a_x = a[x]; - var a_x_key = a_x["_key"]; - if (a_x_key === b_x_key) { - if (has_update) { - a_x["_idx"] = x; + var ended = x >= end_a; + var a_x = undefined; + var b_x_key = undefined; + var a_x_key = undefined; + if (!ended) { + a_x = a[x]; + b_x_key = b_x[key]; + a_x_key = a_x["_key"]; + if (a_x_key === b_x_key) { + if (render) { + this.update(a_x, b_x, view, x); + } + continue; } - if (render) { - this.update(a_x, b_x, view, x); + } + if (render && (ended || !keys[b_x_key])) { + if (ended || !this.key_pool) { + end_a++; + max_end = end_a > end_b ? end_a : end_b; + this.add(b_x, view, x); + } else { + this.replace(a_x, b_x, view, x); } continue; } @@ -1371,31 +1379,24 @@ Mikado$$module$tmp$mikado.prototype.reconcile = function(b, view, x, render) { if (idx_a && idx_b) { if (idx_a >= idx_b) { var tmp_a = a[idx_a - 1]; - this.root.insertBefore(tmp_a, a_x); - tmp_a["_idx"] = x; + insertBefore$$module$tmp$mikado(this.root, tmp_a, a_x); if (render) { this.update(tmp_a, b_x, view, x); } if (idx_a === idx_b) { if (y - x > 1) { - this.root.insertBefore(a_x, a[idx_a] || null); + insertBefore$$module$tmp$mikado(this.root, a_x, a[idx_a]); } - a_x["_idx"] = y; a[x] = a[y]; a[y] = a_x; - if (render) { - this.update(a_x, b[y], view, y); - } } else { splice$$module$tmp$mikado(a, idx_a - 1, x); shift++; - has_update = 1; } } else { var index = idx_b - 1 + shift; - this.root.insertBefore(a_x, a[index] || null); + insertBefore$$module$tmp$mikado(this.root, a_x, a[index]); splice$$module$tmp$mikado(a, x, (index > end_a ? end_a : index) - 1); - has_update = 1; shift--; x--; } @@ -1405,18 +1406,23 @@ Mikado$$module$tmp$mikado.prototype.reconcile = function(b, view, x, render) { } } if (!found) { - this.remove(x, 1, 0, 1); - has_update = 1; + this.remove(x); end_a--; max_end = end_a > end_b ? end_a : end_b; x--; } } - if (SUPPORT_STORAGE && this.store && !this.extern) { + if (store) { this.store = b; } return this; }; +function insertBefore$$module$tmp$mikado(root, a, b) { + root.insertBefore(a, b || null); +} +function appendChild$$module$tmp$mikado(root, child) { + root.appendChild(child); +} function splice$$module$tmp$mikado(arr, pos_old, pos_new, insert) { var tmp = insert || arr[pos_old]; if (insert) { @@ -1433,7 +1439,7 @@ function splice$$module$tmp$mikado(arr, pos_old, pos_new, insert) { } arr[pos_new] = tmp; } -Mikado$$module$tmp$mikado.prototype.add = function(data, view, index, _replace_node, _skip_indexing) { +Mikado$$module$tmp$mikado.prototype.add = function(data, view, index, _replace_node) { var has_index; if (!_replace_node) { if (typeof view === "number") { @@ -1477,21 +1483,15 @@ Mikado$$module$tmp$mikado.prototype.add = function(data, view, index, _replace_n } } } - node["_idx"] = length; if (has_index) { - this.root.insertBefore(node, this.dom[length] || null); + insertBefore$$module$tmp$mikado(this.root, node, this.dom[length]); splice$$module$tmp$mikado(this.dom, this.length - 1, length, node); this.length++; - if (!_skip_indexing) { - for (; ++length < this.length;) { - this.dom[length]["_idx"] = length; - } - } } else { if (_replace_node) { this.root.replaceChild(node, _replace_node); } else { - this.root.appendChild(node); + appendChild$$module$tmp$mikado(this.root, node); this.length++; } this.dom[length] = node; @@ -1516,13 +1516,7 @@ Mikado$$module$tmp$mikado.prototype.destroy = function(unload) { this.unload(); } this.length = 0; - this.dom = null; - this.root = null; - this.template = null; - this.vpath = null; - this.update_path = null; - this.factory = null; - this.live = null; + this.dom = this.root = this.template = this.vpath = this.update_path = this.factory = this.live = null; if (SUPPORT_STORAGE) { this.store = null; } @@ -1554,11 +1548,11 @@ Mikado$$module$tmp$mikado.prototype.append = function(data, view, index) { } return this; }; -Mikado$$module$tmp$mikado.prototype.remove = function(index, count, resize, _skip_indexing) { +Mikado$$module$tmp$mikado.prototype.remove = function(index, count, resize) { var length = this.length; if (index) { if (typeof index === "object") { - index = index["_idx"]; + index = this.index(index); } else { if (index < 0) { index = length + index - 1; @@ -1568,14 +1562,16 @@ Mikado$$module$tmp$mikado.prototype.remove = function(index, count, resize, _ski if (!length || index >= length) { return this; } - if (count < 0) { - index -= count + 1; - if (index < 0) { - index = 0; + if (count) { + if (count < 0) { + index -= count + 1; + if (index < 0) { + index = 0; + } + count *= -1; } - count *= -1; } else { - count || (count = 1); + count = 1; } var nodes; if (!index && count >= length) { @@ -1606,11 +1602,6 @@ Mikado$$module$tmp$mikado.prototype.remove = function(index, count, resize, _ski } } this.length = length; - if (!_skip_indexing && index < length) { - for (; index < length; index++) { - this.dom[index]["_idx"] = index; - } - } if (SUPPORT_POOLS && this.tpl_pool && !this.key_pool && count > 1) { reverse$$module$tmp$mikado(nodes); } @@ -1649,7 +1640,7 @@ Mikado$$module$tmp$mikado.prototype.replace = function(node, data, view, index) index = node; node = this.dom[index]; } else { - index = node["_idx"]; + index = this.index(node); } } this.add(data, view, index, node); @@ -1671,7 +1662,7 @@ Mikado$$module$tmp$mikado.prototype.update = function(node, data, view, index) { index = node; node = this.dom[node]; } else { - index = node["_idx"]; + index = this.index(node); } } if (SUPPORT_STORAGE) { @@ -1773,7 +1764,7 @@ Mikado$$module$tmp$mikado.prototype.parse = function(tpl, index, path, dom_path) tmp_fn$$module$tmp$mikado = ""; this.vpath = []; node["_path"] = dom_path = []; - if (SUPPORT_CACHE && this.cache) { + if (SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && this.cache) { node["_cache"] = {}; } root_node$$module$tmp$mikado = node; @@ -1906,7 +1897,7 @@ Mikado$$module$tmp$mikado.prototype.parse = function(tpl, index, path, dom_path) path_length--; } } - node.appendChild(text_node); + appendChild$$module$tmp$mikado(node, text_node); } else { if (html) { if (typeof html === "object") { @@ -1952,13 +1943,13 @@ Mikado$$module$tmp$mikado.prototype.parse = function(tpl, index, path, dom_path) if (SUPPORT_TEMPLATE_EXTENSION && (include = current["+"])) { current = templates$$module$tmp$mikado[include]; } - node.appendChild(this.parse(current, index + i$14 + 1, path + tmp$13, dom_path)); + appendChild$$module$tmp$mikado(node, this.parse(current, index + i$14 + 1, path + tmp$13, dom_path)); } } else { if (SUPPORT_TEMPLATE_EXTENSION && (include = child["+"])) { child = templates$$module$tmp$mikado[include]; } - node.appendChild(this.parse(child, index + 1, path + ">", dom_path)); + appendChild$$module$tmp$mikado(node, this.parse(child, index + 1, path + ">", dom_path)); } } if (SUPPORT_TEMPLATE_EXTENSION && tpl["f"]) { @@ -2084,6 +2075,7 @@ Mikado$$module$tmp$mikado.prototype.cancel; Mikado$$module$tmp$mikado.prototype.append; Mikado$$module$tmp$mikado.prototype.add; Mikado$$module$tmp$mikado.prototype.route; +Mikado$$module$tmp$mikado.prototype.dispatch; Mikado$$module$tmp$mikado.prototype.listen; Mikado$$module$tmp$mikado.prototype.unlisten; Mikado$$module$tmp$mikado.prototype.export; diff --git a/dist/mikado.es5.js b/dist/mikado.es5.js index 860db0e..925010e 100644 --- a/dist/mikado.es5.js +++ b/dist/mikado.es5.js @@ -1,57 +1,57 @@ /**! - * Mikado.js v0.7.4 (ES5) + * Mikado.js v0.7.42 (ES5) * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Licence: Apache-2.0 * https://github.com/nextapps-de/mikado */ -(function(){'use strict';var k;Object.assign||(Object.assign=function(){for(var a=arguments,b=a.length,c=a[0],d=1,e,f,g;dMath.abs(G-b)&&50>Math.abs(H-c)&&D.call(this,a,"tap")},ha=function(a){ea(a,a.touches)};aa=function(a){l(a,B?"pointerdown":"touchstart",ha,!1);l(a,B?"pointerup":"touchend",fa,!1)}} -F.listen=F.prototype.listen=function(a,b){E[a]||(l(1,a,D,b||!0),E[a]=1);return this};F.unlisten=F.prototype.unlisten=function(a,b){E[a]&&(l(0,a,D,b||!0),E[a]=0);return this};k=F.prototype;k.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=a._i;0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; -k.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;var e=0>b;if(e&&d||!e&&db;e--)d=this.b[e]=this.b[e- -1],d._i=e,this.store&&(this.store[e]=this.store[e-1]);else for(e=d;eb&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};k.after=function(a,b){"number"!==typeof a&&(a=a._i);"number"!==typeof b&&(b=b._i);b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; -k.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;if("number"===typeof b){var e=b;b=this.b[b]}else e=b._i;if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),a._i=e,b._i=d,this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= -a)}return this};var I={};function ia(a){return I[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ja(a,b){J(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ka(a,b){b=(a._c||(a._c=a.className)).replace(I[b]||ia(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function J(a,b){return!!(a._c||(a._c=a.className)).match(I[b]||ia(b))}function la(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var ma=window.localStorage;F.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.v.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.v.add(c,a,this.view);P=!1;return b};k.push=function(a){P=!0;this.v.add(a,this.view);this.v.proxy||(this[this.length]=a);L&&this.length++;P=!1};k.unshift=function(a){P=!0;this.v.add(a,0,this.view);this.D.unshift(a);P=!1}; -k.pop=function(){P=!0;this.v.remove(this.length-1);var a=this.D.pop();P=!1;return a};k.shift=function(){P=!0;this.v.remove(0);var a=this.D.shift();P=!1;return a};k.concat=function(a){for(var b=a.length,c=0;cg?h:g,n=0,y=this.key;for(c||(c=0);c=h)){h++;m=h>g?h:g;var u=1;this.add(p,b,c,null,1);continue}var t=e[c],A=t._k;if(A===w){u&&(t._i=c);d&&this.update(t,p,b,c);continue}for(var v=void 0,z=void 0,q=c+1;q=z?(r=e[v-1],this.root.insertBefore(r,t),r._i=c,d&&this.update(r,p,b,c),v===z?(1h?h:u)-1),u=1,n--,c--);r=1;break}}r||(this.remove(c,1,0,1),u=1,h--,m=h>g?h:g,c--)}this.store&&!this.K&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} -k.add=function(a,b,c,d,e){if(!d)if("number"===typeof b){c=b;b=null;var f=1}else if(c||0===c)f=1;c=d||f?c:this.length;b=this.create(a,b,c);var g;this.proxy&&(this.w&&this.B&&b._m===a?g=1:a._y||(a=ra(a,b._p||V(this,b),this.proxy)));g||(this.store?f&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));b._i=c;if(f){if(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++,!e)for(;++ca&&(a=e+a-1));if(!e||a>=e)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);if(!a&&b>=e){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.A||this.o))for(b=0;b"===p?m=m.firstElementChild:"+"===p?m=m.nextElementSibling:"|"===p&&(m=m.firstChild),d[r]=m)}}e[h]=m}return b._p=e}var X; -function U(a,b,c,d,e){if(!c){var f=R[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.w=f.w,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[],a.cache&&(f.$={}));var g=b.s,h=b.i,m=b.x,n=b.h,y=b.a,r=b.e,p=b.c,w=b.j,u=a.u.length,t=0,A=0,v="";w&&(v+=";"+w,-1",C=0;C",e))}b.f&&(X+="}else "+(1Math.abs(H-b)&&50>Math.abs(I-c)&&D.call(this,a,"tap")},fa=function(a){da(a,a.touches)};aa=function(a){m(a,B?"pointerdown":"touchstart",fa,!1);m(a,B?"pointerup":"touchend",ea,!1)}}G.listen=G.prototype.listen=function(a,b){F[a]||(m(1,a,D,b||!0),F[a]=1);return this};G.unlisten=G.prototype.unlisten=function(a,b){F[a]&&(m(0,a,D,b||!0),F[a]=0);return this};l=G.prototype;l.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=this.index(a);0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; +l.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);var e=0>b;if(e&&d||!e&&db;d--)this.b[d]= +this.b[d-1],this.store&&(this.store[d]=this.store[d-1]);else for(;db&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};l.after=function(a,b){"number"!==typeof a&&(a=this.index(a));"number"!==typeof b&&(b=this.index(b));b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; +l.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);if("number"===typeof b){var e=b;b=this.b[b]}else e=this.index(b);if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= +a)}return this};var J={};function ha(a){return J[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ia(a,b){K(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ja(a,b){b=(a._c||(a._c=a.className)).replace(J[b]||ha(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function K(a,b){return!!(a._c||(a._c=a.className)).match(J[b]||ha(b))}function ka(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var la=window.localStorage;G.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.w.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.w.add(c,a,this.view);Q=!1;return b};l.push=function(a){Q=!0;this.w.add(a,this.view);this.w.proxy||(this[this.length]=a);M&&this.length++;Q=!1};l.unshift=function(a){Q=!0;this.w.add(a,0,this.view);this.D.unshift(a);Q=!1}; +l.pop=function(){Q=!0;this.w.remove(this.length-1);var a=this.D.pop();Q=!1;return a};l.shift=function(){Q=!0;this.w.remove(0);var a=this.D.shift();Q=!1;return a};l.concat=function(a){for(var b=a.length,c=0;ch?k:h,y=0,v=this.key;e&&(this.store=0);for(c||(c=0);c=k,t=void 0,A=void 0,w=void 0;if(!q&&(t=f[c],A=r[v],w=t._k,w===A)){d&&this.update(t,r,b,c);continue}if(d&&(q||!g[A])){q||!this.v?(k++,n=k>h?k:h,this.add(r,b,c)):this.replace(t,r,b,c);continue}for(var z=q=void 0,u=c+1;u=z?(p=f[q- +1],this.root.insertBefore(p,t||null),d&&this.update(p,r,b,c),q===z?(1k?k:r)-1),y--,c--);p=1;break}}p||(this.remove(c),k--,n=k>h?k:h,c--)}e&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} +l.add=function(a,b,c,d){if(!d)if("number"===typeof b){c=b;b=null;var e=1}else if(c||0===c)e=1;c=d||e?c:this.length;b=this.create(a,b,c);var f;this.proxy&&(this.A&&this.B&&b._m===a?f=1:a._y||(a=qa(a,b._p||Aa(this,b),this.proxy)));f||(this.store?e&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));e?(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++):(d?this.root.replaceChild(b,d):(this.root.appendChild(b),this.length++), +this.b[c]=b);var g;(g=this.J)&&(g=g.insert)&&g(b);return this};l.clear=function(a){this.length&&this.remove(0,this.length);if(a){S[this.l+(this.cache?"$":"")]=null;if(this.key)if(this.length){a=Object.keys(this.g);for(var b=0,c=a.length,d=void 0;ba&&(a=d+a-1));if(!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;if(!a&&b>=d){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.v||this.o))for(b=0;b"===p?k=k.firstElementChild:"+"===p?k=k.nextElementSibling:"|"===p&&(k=k.firstChild),d[v]=k)}}e[h]=k}return b._p=e}var X; +function V(a,b,c,d,e){if(!c){var f=S[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.A=f.A,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[]);var g=b.s,h=b.i,k=b.x,n=b.h,y=b.a,v=b.e,p=b.c,r=b.j,q=a.u.length,t=0,A=0,w="";r&&(w+=";"+r,-1",w=0;w",e);f.appendChild(d)}b.f&&(X+="}else "+(1h.length&&h.unshift("value"),g=h[0],h="{{=="+h[1]+"}}"),Da[g.substring(2)]&&-1!==h.indexOf("{{")&&(g=g.substring(2)),Da[g]?Z(c.e||(c.e={}),g,h):Z(c.a||(c.a={}),g,h))}}a=a.childNodes;if(d=a.length){for(f=e=0;fg?k:g,t=0,x=this.key;for(c||(c=0);c=k)){k++;h=k>g?k:g;var n=1;this.add(q,b,c,null,1);continue}var r=f[c],y=r._k;if(y===l){n&&(r._i=c);e&&this.update(r,q,b,c);continue}for(var u=void 0,A=void 0,v=c+1;v=A?(m=f[u-1],this.b.insertBefore(m,r),m._i=c,e&&this.update(m,q,b,c),u===A?(1k?k:n)-1),n=1,t--,c--);m=1;break}}m||(this.remove(c,1,0,1),n=1,k--,h=k>g?k:g,c--)}return this};function J(a,b,c,e){var f=e||a[b];e&&b++;if(bc;b--)a[b]=a[b-1];a[c]=f} -p.add=function(a,b,c,e,f){if(!e)if("number"===typeof b){c=b;b=null;var d=1}else if(c||0===c)d=1;c=e||d?c:this.length;a=this.create(a,b,c);a._i=c;if(d){if(this.b.insertBefore(a,this.f[c]||null),J(this.f,this.length-1,c,a),this.length++,!f)for(;++ca&&(a=f+a-1));if(!f||a>=f)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);if(!a&&b>=f){var d=this.f;b=d.length;this.b.textContent="";this.b._d=this.f=c?Array(c):[];f=0}else d=this.f.splice(a,b),f-=b;this.length=f;if(!e&&a"===q?h=h.firstElementChild:"+"===q?h=h.nextElementSibling:"|"===q&&(h=h.firstChild),e[m]=h)}}f[k]=h}return b._p=f}var L; -function H(a,b,c,e,f){if(!c){var d=B[b.n+(a.cache?"$":"")];if(d)return a.v=d.v,a.o=d.o,a.g=d.g,d.node}d=document.createElement(b.t||"div");c||(c=0,e="&",L="",a.g=[],d._p=f=[],a.cache&&(d.$={}));var g=b.s,k=b.i,h=b.x,t=b.h,x=b.a,m=b.c,q=b.j,l=a.g.length,n=0,r="";q&&(r+=";"+q,-1",l=0;l",f));c||(!a.o&&L&&(a.v=Function("p","s","data","index","view", -'"use strict";var self,v'+L)),B[b.n+(a.cache?"$":"")]={v:a.v,o:a.o,g:a.g,node:d});return d}function M(a,b,c){L=1g?l:g,r=0,x=this.key;for(c||(c=0);c=l,n=void 0,t=void 0,y=void 0;if(!h&&(n=f[c],t=m[x],y=n._k,y===t)){d&&this.update(n,m,b,c);continue}if(d&&(h||!e[t])){h||!this.u?(l++,k=l>g?l:g,this.add(m,b,c)):this.replace(n,m,b,c);continue}for(var u=h=void 0,w=c+1;w=u?(p=f[h-1],this.b.insertBefore(p,n||null),d&&this.update(p, +m,b,c),h===u?(1l?l:m)-1),r--,c--);p=1;break}}p||(this.remove(c),l--,k=l>g?l:g,c--)}return this};function I(a,b,c,d){var f=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=f} +q.add=function(a,b,c,d){if(!d)if("number"===typeof b){c=b;b=null;var f=1}else if(c||0===c)f=1;c=d||f?c:this.length;a=this.create(a,b,c);f?(this.b.insertBefore(a,this.f[c]||null),I(this.f,this.length-1,c,a),this.length++):(d?this.b.replaceChild(a,d):(this.b.appendChild(a),this.length++),this.f[c]=a);return this};q.clear=function(){this.length&&this.remove(0,this.length);return this};q.destroy=function(a){a&&this.unload();this.length=0;this.f=this.b=this.v=this.g=this.w=this.A=this.l=null}; +q.append=function(a,b,c){if("number"===typeof b){c=b;b=null;var d=1}else d=c||0===c;for(var f=a.length,e=0;ea&&(a=d+a-1));if(!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;!a&&b>=d?(a=this.f,b=a.length,this.b.textContent="",this.b._d=this.f=c?Array(c):[],d=0):(a=this.f.splice(a,b),d-=b);this.length=d;if(this.m&&!this.u&&1"===m?k=k.firstElementChild:"+"===m?k=k.nextElementSibling:"|"===m&&(k=k.firstChild),d[p]=k)}}f[l]=k}return b._p=f}var K; +function G(a,b,c,d,f){if(!c){var e=A[b.n+(a.cache?"$":"")];if(e)return a.w=e.w,a.o=e.o,a.g=e.g,e.node}e=document.createElement(b.t||"div");c||(c=0,d="&",K="",a.g=[],e._p=f=[],a.cache&&(e.$={}));var g=b.s,l=b.i,k=b.x,r=b.h,x=b.a,p=b.c,m=b.j,h=a.g.length,n=0,t="";m&&(t+=";"+m,-1",h=0;h",f),e.appendChild(d);c||(!a.o&&K&&(a.w=Function("p","s","data","index", +"view",'"use strict";var self,v'+K)),A[b.n+(a.cache?"$":"")]={w:a.w,o:a.o,g:a.g,node:e});return e}function L(a,b,c){K=1Math.abs(G-b)&&50>Math.abs(H-c)&&D.call(this,a,"tap")},ha=function(a){ea(a,a.touches)};aa=function(a){l(a,B?"pointerdown":"touchstart",ha,!1);l(a,B?"pointerup":"touchend",fa,!1)}} -F.listen=F.prototype.listen=function(a,b){E[a]||(l(1,a,D,b||!0),E[a]=1);return this};F.unlisten=F.prototype.unlisten=function(a,b){E[a]&&(l(0,a,D,b||!0),E[a]=0);return this};k=F.prototype;k.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=a._i;0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; -k.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;var e=0>b;if(e&&d||!e&&db;e--)d=this.b[e]=this.b[e- -1],d._i=e,this.store&&(this.store[e]=this.store[e-1]);else for(e=d;eb&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};k.after=function(a,b){"number"!==typeof a&&(a=a._i);"number"!==typeof b&&(b=b._i);b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; -k.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=a._i;if("number"===typeof b){var e=b;b=this.b[b]}else e=b._i;if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),a._i=e,b._i=d,this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= -a)}return this};var I={};function ia(a){return I[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ja(a,b){J(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ka(a,b){b=(a._c||(a._c=a.className)).replace(I[b]||ia(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function J(a,b){return!!(a._c||(a._c=a.className)).match(I[b]||ia(b))}function la(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var ma=window.localStorage;F.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.v.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.v.add(c,a,this.view);P=!1;return b};k.push=function(a){P=!0;this.v.add(a,this.view);this.v.proxy||(this[this.length]=a);L&&this.length++;P=!1};k.unshift=function(a){P=!0;this.v.add(a,0,this.view);this.D.unshift(a);P=!1}; -k.pop=function(){P=!0;this.v.remove(this.length-1);var a=this.D.pop();P=!1;return a};k.shift=function(){P=!0;this.v.remove(0);var a=this.D.shift();P=!1;return a};k.concat=function(a){for(var b=a.length,c=0;cg?h:g,n=0,y=this.key;for(c||(c=0);c=h)){h++;m=h>g?h:g;var u=1;this.add(p,b,c,null,1);continue}var t=e[c],A=t._k;if(A===w){u&&(t._i=c);d&&this.update(t,p,b,c);continue}for(var v=void 0,z=void 0,q=c+1;q=z?(r=e[v-1],this.root.insertBefore(r,t),r._i=c,d&&this.update(r,p,b,c),v===z?(1h?h:u)-1),u=1,n--,c--);r=1;break}}r||(this.remove(c,1,0,1),u=1,h--,m=h>g?h:g,c--)}this.store&&!this.K&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} -k.add=function(a,b,c,d,e){if(!d)if("number"===typeof b){c=b;b=null;var f=1}else if(c||0===c)f=1;c=d||f?c:this.length;b=this.create(a,b,c);var g;this.proxy&&(this.w&&this.B&&b._m===a?g=1:a._y||(a=ra(a,b._p||V(this,b),this.proxy)));g||(this.store?f&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));b._i=c;if(f){if(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++,!e)for(;++ca&&(a=e+a-1));if(!e||a>=e)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);if(!a&&b>=e){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.A||this.o))for(b=0;b"===p?m=m.firstElementChild:"+"===p?m=m.nextElementSibling:"|"===p&&(m=m.firstChild),d[r]=m)}}e[h]=m}return b._p=e}var X; -function U(a,b,c,d,e){if(!c){var f=R[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.w=f.w,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[],a.cache&&(f.$={}));var g=b.s,h=b.i,m=b.x,n=b.h,y=b.a,r=b.e,p=b.c,w=b.j,u=a.u.length,t=0,A=0,v="";w&&(v+=";"+w,-1",C=0;C",e))}b.f&&(X+="}else "+(1Math.abs(H-b)&&50>Math.abs(I-c)&&D.call(this,a,"tap")},fa=function(a){da(a,a.touches)};aa=function(a){l(a,B?"pointerdown":"touchstart",fa,!1);l(a,B?"pointerup":"touchend",ea,!1)}}G.listen=G.prototype.listen=function(a,b){F[a]||(l(1,a,D,b||!0),F[a]=1);return this};G.unlisten=G.prototype.unlisten=function(a,b){F[a]&&(l(0,a,D,b||!0),F[a]=0);return this};k=G.prototype;k.move=function(a,b){if("number"===typeof a){var c=a;a=this.b[c]}else c=this.index(a);0>b&&(b=this.length+b-1);c!==b&&this.shift(a,b-c);return this}; +k.shift=function(a,b,c){if(!b)return this;if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);var e=0>b;if(e&&d||!e&&db;d--)this.b[d]= +this.b[d-1],this.store&&(this.store[d]=this.store[d-1]);else for(;db&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1));return this};k.after=function(a,b){"number"!==typeof a&&(a=this.index(a));"number"!==typeof b&&(b=this.index(b));b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1));return this}; +k.swap=function(a,b,c){if(a!==b){if("number"===typeof a){var d=a;a=this.b[a]}else d=this.index(a);if("number"===typeof b){var e=b;b=this.b[b]}else e=this.index(b);if(this.H&&(this.store||this.B)){var f=this.store?this.store[d]:a._m;this.update(a,this.store?this.store[e]:b._m,c,d);this.update(b,f,c,e)}else c=d+1!==e,this.root.insertBefore(c?a:b,c?b:a),c&&e+1!==d&&this.root.insertBefore(b,this.b[d+1]||null),this.b[d]=b,this.b[e]=a,this.store&&!this.K&&(a=this.store[e],this.store[e]=this.store[d],this.store[d]= +a)}return this};var J={};function ha(a){return J[a]=new RegExp("(?:^|\\s)"+a+"(?!\\S)","g")}function ia(a,b){K(a,b)||(a.className+=" "+b,a._c+=" "+b);return this}function ja(a,b){b=(a._c||(a._c=a.className)).replace(J[b]||ha(b),"");a._c!==b&&(a.className=b,a._c=b);return this}function K(a,b){return!!(a._c||(a._c=a.className)).match(J[b]||ha(b))}function ka(a,b){var c=a._a||(a._a={}),d=c[b];return d||""===d?d:c[b]=a.getAttribute(b)};var la=window.localStorage;G.prototype.export=function(){if(this.store)var a=this.store;else if(this.B){a=Array(this.length);for(var b=0;b=g?(e.add(c,d),a.length++):bb&&(b=0));b&&this.w.remove(a,b);b=c?this.D.splice(a,b,c):this.D.splice(a,b);c&&this.w.add(c,a,this.view);Q=!1;return b};k.push=function(a){Q=!0;this.w.add(a,this.view);this.w.proxy||(this[this.length]=a);M&&this.length++;Q=!1};k.unshift=function(a){Q=!0;this.w.add(a,0,this.view);this.D.unshift(a);Q=!1}; +k.pop=function(){Q=!0;this.w.remove(this.length-1);var a=this.D.pop();Q=!1;return a};k.shift=function(){Q=!0;this.w.remove(0);var a=this.D.shift();Q=!1;return a};k.concat=function(a){for(var b=a.length,c=0;ch?m:h,y=0,v=this.key;e&&(this.store=0);for(c||(c=0);c=m,t=void 0,A=void 0,w=void 0;if(!q&&(t=f[c],A=r[v],w=t._k,w===A)){d&&this.update(t,r,b,c);continue}if(d&&(q||!g[A])){q||!this.v?(m++,n=m>h?m:h,this.add(r,b,c)):this.replace(t,r,b,c);continue}for(var z=q=void 0,u=c+1;u=z?(p=f[q- +1],this.root.insertBefore(p,t||null),d&&this.update(p,r,b,c),q===z?(1m?m:r)-1),y--,c--);p=1;break}}p||(this.remove(c),m--,n=m>h?m:h,c--)}e&&(this.store=a);return this};function W(a,b,c,d){var e=d||a[b];d&&b++;if(bc;b--)a[b]=a[b-1];a[c]=e} +k.add=function(a,b,c,d){if(!d)if("number"===typeof b){c=b;b=null;var e=1}else if(c||0===c)e=1;c=d||e?c:this.length;b=this.create(a,b,c);var f;this.proxy&&(this.A&&this.B&&b._m===a?f=1:a._y||(a=qa(a,b._p||Aa(this,b),this.proxy)));f||(this.store?e&&!this.K?W(this.store,this.length-1,c,a):(this.L=1,this.store[c]=a,this.L=0):this.B&&(b._m=a));e?(this.root.insertBefore(b,this.b[c]||null),W(this.b,this.length-1,c,b),this.length++):(d?this.root.replaceChild(b,d):(this.root.appendChild(b),this.length++), +this.b[c]=b);var g;(g=this.J)&&(g=g.insert)&&g(b);return this};k.clear=function(a){this.length&&this.remove(0,this.length);if(a){S[this.l+(this.cache?"$":"")]=null;if(this.key)if(this.length){a=Object.keys(this.g);for(var b=0,c=a.length,d=void 0;ba&&(a=d+a-1));if(!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;if(!a&&b>=d){this.store&&!this.K&&(this.store=c?Array(c):[]);if(this.include&&(this.v||this.o))for(b=0;b"===p?m=m.firstElementChild:"+"===p?m=m.nextElementSibling:"|"===p&&(m=m.firstChild),d[v]=m)}}e[h]=m}return b._p=e}var X; +function V(a,b,c,d,e){if(!c){var f=S[b.n+(a.cache?"$":"")];if(f)return a.G=f.G,a.F=f.F,a.A=f.A,a.proxy=f.proxy,a.include=f.O,a.u=f.u,f.node}f=document.createElement(b.t||"div");c||(c=0,d="&",X="",a.u=[],f._p=e=[]);var g=b.s,h=b.i,m=b.x,n=b.h,y=b.a,v=b.e,p=b.c,r=b.j,q=a.u.length,t=0,A=0,w="";r&&(w+=";"+r,-1",w=0;w",e);f.appendChild(d)}b.f&&(X+="}else "+(1h.length&&h.unshift("value"),g=h[0],h="{{=="+h[1]+"}}"),Da[g.substring(2)]&&-1!==h.indexOf("{{")&&(g=g.substring(2)),Da[g]?Z(c.e||(c.e={}),g,h):Z(c.a||(c.a={}),g,h))}}a=a.childNodes;if(d=a.length){for(f=e=0;fMath.abs(i-c)&&50>Math.abs(j-d)&&a.call(this,b,"tap")}function e(a,b){b&&(a=b[0]),i=a.clientX,j=a.clientY}k=function(a){b(a,g?"pointerdown":"touchstart",c,!1),b(a,g?"pointerup":"touchend",d,!1)}}Mikado.listen=Mikado.prototype.listen=function(d,e){return c[d]||(b(1,d,a,e||!0),c[d]=1),this},Mikado.unlisten=Mikado.prototype.unlisten=function(d,e){return c[d]&&(b(0,d,a,e||!0),c[d]=0),this}} \ No newline at end of file +import Mikado from"./mikado.js";{function a(a,b){b||(b=a.type);const c=a.target;let f=c,g=c["_event_"+b];if(!g){for(;f!==e;){if("click"===b&&h&&(g=f.getAttribute("tap")),g||(g=f.getAttribute(b)),g){const a=g.indexOf(":");if(-1!==a){const b=g.substring(0,a),c=g.substring(a+1);for(g=0,f=f.parentElement;f!==e;){if(f.hasAttribute(c)){g=b;break}f=f.parentElement}}break}f=f.parentElement}if(!g)return;c["_event_"+b]=g,c["_root_"+b]=f}else f=c["_root_"+b];const i=d[g];!i||(a.preventDefault(),i(f,a,c)),a.stopPropagation()}function b(a,b,c,d){if("tap"===b){if(f||g)return void k(a);h=!0,b="click"}window[(a?"add":"remove")+"EventListener"](b,c,d||{passive:!0,capture:!0})}const c={},d={},e=document.body,f="ontouchstart"in window,g=!f&&window.PointerEvent&&navigator.maxTouchPoints;let h;Mikado.route=Mikado.prototype.route=function(a,b){return d[a]=b,this},Mikado.dispatch=Mikado.prototype.dispatch=function(a,b,c,e){return d[a](b,c,e),this};let i,j,k;if(f||g){function c(a){e(a,a.touches)}function d(b){let c=i,d=j;e(b,b.changedTouches),50>Math.abs(i-c)&&50>Math.abs(j-d)&&a.call(this,b,"tap")}function e(a,b){b&&(a=b[0]),i=a.clientX,j=a.clientY}k=function(a){b(a,g?"pointerdown":"touchstart",c,!1),b(a,g?"pointerup":"touchend",d,!1)}}Mikado.listen=Mikado.prototype.listen=function(d,e){return c[d]||(b(1,d,a,e||!0),c[d]=1),this},Mikado.unlisten=Mikado.prototype.unlisten=function(d,e){return c[d]&&(b(0,d,a,e||!0),c[d]=0),this}} \ No newline at end of file diff --git a/dist/module/helper.js b/dist/module/helper.js index f45223d..8bd05a4 100644 --- a/dist/module/helper.js +++ b/dist/module/helper.js @@ -1 +1 @@ -import Mikado from"./mikado.js";{function c(c,d,e,a,b,f){if(e._idx=b,a._idx=f,c[f]=a,c[b]=e,d){const a=d[b];d[b]=d[f],d[f]=a}}Mikado.prototype.move=function(a,b){let c;return"number"==typeof a?(c=a,a=this.dom[c]):c=a._idx,0>b&&(b=this.length+b-1),c!==b&&this.shift(a,b-c),this},Mikado.prototype.shift=function(d,e,f){if(!e)return this;let g;"number"==typeof d?(g=d,d=this.dom[d]):g=d._idx;const h=0>e;if(h&&g||!h&&ga;b--)d=this.dom[b]=this.dom[b-1],d._idx=b,this.store&&(this.store[b]=this.store[b-1]);else for(let b=g;bb&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1)),this},Mikado.prototype.after=function(a,b){return"number"!=typeof a&&(a=a._idx),"number"!=typeof b&&(b=b._idx),b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1)),this},Mikado.prototype.swap=function(c,d,e){if(c!==d){let a,b;if("number"==typeof c?(a=c,c=this.dom[c]):a=c._idx,"number"==typeof d?(b=d,d=this.dom[d]):b=d._idx,this.reuse&&(this.store||this.loose)){const f=this.store?this.store[a]:c._data;this.update(c,this.store?this.store[b]:d._data,e,a),this.update(d,f,e,b)}else{const e=a+1!==b;if(this.root.insertBefore(e?c:d,e?d:c),e&&b+1!==a&&this.root.insertBefore(d,this.dom[a+1]||null),c._idx=b,d._idx=a,this.dom[a]=d,this.dom[b]=c,this.store&&!this.extern){const c=this.store[b];this.store[b]=this.store[a],this.store[a]=c}}}return this}} \ No newline at end of file +import Mikado from"./mikado.js";{function c(c,d,e,a,b,f){if(c[f]=a,c[b]=e,d){const a=d[b];d[b]=d[f],d[f]=a}}Mikado.prototype.move=function(a,b){let c;return"number"==typeof a?(c=a,a=this.dom[c]):c=this.index(a),0>b&&(b=this.length+b-1),c!==b&&this.shift(a,b-c),this},Mikado.prototype.shift=function(d,e,f){if(!e)return this;let g;"number"==typeof d?(g=d,d=this.dom[d]):g=this.index(d);const h=0>e;if(h&&g||!h&&ga;b--)d=this.dom[b]=this.dom[b-1],this.store&&(this.store[b]=this.store[b-1]);else for(let b=g;bb&&(b=this.length+b,0>a&&b--),0>a&&(a=this.length+a-1),this.shift(a,b-a-1)),this},Mikado.prototype.after=function(a,b){return"number"!=typeof a&&(a=this.index(a)),"number"!=typeof b&&(b=this.index(b)),b!==a-1&&(0>b&&(b=this.length+b-2,0>a&&b++),0>a&&(a=this.length+a-1),this.shift(a,b-a+1)),this},Mikado.prototype.swap=function(c,d,e){if(c!==d){let a,b;if("number"==typeof c?(a=c,c=this.dom[c]):a=this.index(c),"number"==typeof d?(b=d,d=this.dom[d]):b=this.index(d),this.reuse&&(this.store||this.loose)){const f=this.store?this.store[a]:c._data;this.update(c,this.store?this.store[b]:d._data,e,a),this.update(d,f,e,b)}else{const e=a+1!==b;if(this.root.insertBefore(e?c:d,e?d:c),e&&b+1!==a&&this.root.insertBefore(d,this.dom[a+1]||null),this.dom[a]=d,this.dom[b]=c,this.store&&!this.extern){const c=this.store[b];this.store[b]=this.store[a],this.store[a]=c}}}return this}} \ No newline at end of file diff --git a/dist/module/mikado.js b/dist/module/mikado.js index 651bfc9..316bc11 100644 --- a/dist/module/mikado.js +++ b/dist/module/mikado.js @@ -1 +1 @@ -import"./event.js";import"./helper.js";import"./cache.js";import"./store.js";import"./polyfill.js";import Observer from"./array.js";import create_proxy from"./proxy.js";const{requestAnimationFrame,cancelAnimationFrame}=window;let state={};const templates={};let factory_pool={};const template_pool={},keyed_pool={};export default function Mikado(a,b,c){return this instanceof Mikado?void(!a.nodeType&&(c=b,b=a,a=null),a?this.mount(a):(this.dom=null,this.root=null,this.length=0),this.init(b,c)):new Mikado(a,b,c)}Mikado.register=Mikado.register=function(a,b){return b||(b=a,a=b.n),templates[a]=b,Mikado},Mikado.prototype.mount=function(a){return this.root!==a&&(this.key&&this.root&&(this.root._pool=this.live,this.live=a._pool||{}),this.root=a,this.check(),this.dom=a._dom||(a._dom=collection_to_array(a.children)),this.length=this.dom.length),this},Mikado.prototype.sync=function(a){if(this.root._dom=this.dom=collection_to_array(this.root.children),this.length=this.dom.length,a&&this.cache)for(let a=0;ah?i:h,k=0;const l=this.key;for(d||(d=0);d=i)){i++,j=i>h?i:h,g=1,this.add(n,b,d,null,1);continue}const p=f[d],q=p._key;if(q===o){g&&(p._idx=d),e&&this.update(p,n,b,d);continue}let r,s;for(let a=d+1;a=s){const h=f[r-1];this.root.insertBefore(h,p),h._idx=d,e&&this.update(h,n,b,d),r==s?(1i?i:a)-1),g=1,k--,d--}m=1;break}}m||(this.remove(d,1,0,1),g=1,i--,j=i>h?i:h,d--)}return this.store&&!this.extern&&(this.store=c),this};function splice(a,b,c,d){const e=d||a[b];if(d&&b++,bc;b--)a[b]=a[b-1];a[c]=e}Mikado.prototype.add=function(a,b,c,d,e){let f;d||("number"==typeof b?(c=b,b=null,f=1):(c||0===c)&&(f=1));let g=d||f?c:this.length;const h=this.create(a,b,g);{let b;this.proxy&&(this.stealth&&this.loose&&h._data===a?b=1:a._proxy||(a=create_proxy(a,h._path||this.create_path(h),this.proxy))),b||(this.store?f&&!this.extern?splice(this.store,this.length-1,g,a):(this.skip=1,this.store[g]=a,this.skip=0):this.loose&&(h._data=a))}if(h._idx=g,!f)d?this.root.replaceChild(h,d):(this.root.appendChild(h),this.length++),this.dom[g]=h;else if(this.root.insertBefore(h,this.dom[g]||null),splice(this.dom,this.length-1,g,h),this.length++,!e)for(;++ga&&(a=e+a-1)),!e||a>=e)return this;0>b?(a-=b+1,0>a&&(a=0),b*=-1):b||(b=1);let f;if(!a&&b>=e){if(this.store&&!this.extern&&(this.store=c?Array(c):[]),this.include&&(this.key_pool||this.tpl_pool))for(let a=0;a"===e?a=a.firstElementChild:"+"===e?a=a.nextElementSibling:"|"===e&&(a=a.firstChild),c[f]=a)}return a}let tmp_fn,last_conditional,root_node;Mikado.prototype.parse=function(a,b,c,d){if(!b){const b=factory_pool[a.n+(this.cache?"_cache":"")];if(b)return this.update_path=b.update_path,this.static=b.static,this.stealth=b.stealth,this.proxy=b.proxy,this.include=b.include,this.vpath=b.vpath,b.node}const e=document.createElement(a.t||"div");b||(b=0,c="&",tmp_fn="",this.vpath=[],e._path=d=[],this.cache&&(e._cache={}),root_node=e);let f=a.s,g=a.i,h=a.x,i=a.h;const j=a.a,k=a.e;let l=a.c;const m=a.j;let n=this.vpath.length,o=0,p=0,q="";if(m&&(q+=";"+m,-1",d))}if(a.f&&(tmp_fn+="}else "+(1h?i:h,k=0;const l=this.key;for(f&&(this.store=0),d||(d=0);d=i;let o,p,q;if(!n&&(o=g[d],p=m[l],q=o._key,q===p)){e&&this.update(o,m,b,d);continue}if(e&&(n||!a[p])){n||!this.key_pool?(i++,j=i>h?i:h,this.add(m,b,d)):this.replace(o,m,b,d);continue}let r,s;for(let a=d+1;a=s){const c=g[r-1];insertBefore(this.root,c,o),e&&this.update(c,m,b,d),r==s?(1i?i:a)-1),k--,d--}f=1;break}}f||(this.remove(d),i--,j=i>h?i:h,d--)}return f&&(this.store=c),this};function insertBefore(c,d,a){c.insertBefore(d,a||null)}function appendChild(a,b){a.appendChild(b)}function splice(a,b,c,d){const e=d||a[b];if(d&&b++,bc;b--)a[b]=a[b-1];a[c]=e}Mikado.prototype.add=function(a,b,c,d){let e;d||("number"==typeof b?(c=b,b=null,e=1):(c||0===c)&&(e=1));let f=d||e?c:this.length;const g=this.create(a,b,f);{let b;this.proxy&&(this.stealth&&this.loose&&g._data===a?b=1:a._proxy||(a=create_proxy(a,g._path||this.create_path(g),this.proxy))),b||(this.store?e&&!this.extern?splice(this.store,this.length-1,f,a):(this.skip=1,this.store[f]=a,this.skip=0):this.loose&&(g._data=a))}e?(insertBefore(this.root,g,this.dom[f]),splice(this.dom,this.length-1,f,g),this.length++):(d?this.root.replaceChild(g,d):(appendChild(this.root,g),this.length++),this.dom[f]=g);let h;return(h=this.on)&&(h=h.insert)&&h(g),this},Mikado.prototype.clear=function(a){return this.length&&this.remove(0,this.length),a&&this.purge(),this},Mikado.prototype.destroy=function(a){a&&this.unload(),this.length=0,this.dom=this.root=this.template=this.vpath=this.update_path=this.factory=this.live=null,this.store=null,this.include=null},Mikado.prototype.cancel=function(){return this.timer&&(cancelAnimationFrame(this.timer),this.timer=null),this},Mikado.prototype.append=function(a,b,c){let d;"number"==typeof b?(c=b,b=null,d=1):d=c||0===c;const e=a.length;for(let f=0;fa&&(a=d+a-1)),!d||a>=d)return this;b?0>b&&(a-=b+1,0>a&&(a=0),b*=-1):b=1;let e;if(!a&&b>=d){if(this.store&&!this.extern&&(this.store=c?Array(c):[]),this.include&&(this.key_pool||this.tpl_pool))for(let a=0;a"===e?a=a.firstElementChild:"+"===e?a=a.nextElementSibling:"|"===e&&(a=a.firstChild),c[f]=a)}return a}let tmp_fn,last_conditional,root_node;Mikado.prototype.parse=function(a,b,c,d){if(!b){const b=factory_pool[a.n+(this.cache?"_cache":"")];if(b)return this.update_path=b.update_path,this.static=b.static,this.stealth=b.stealth,this.proxy=b.proxy,this.include=b.include,this.vpath=b.vpath,b.node}const e=document.createElement(a.t||"div");b||(b=0,c="&",tmp_fn="",this.vpath=[],e._path=d=[],!1,root_node=e);let f=a.s,g=a.i,h=a.x,i=a.h;const j=a.a,k=a.e;let l=a.c;const m=a.j;let n=this.vpath.length,o=0,p=0,q="";if(m&&(q+=";"+m,-1",d))}if(a.f&&(tmp_fn+="}else "+(1 pos; i--){ current = this.dom[i] = this.dom[i - 1]; - current["_idx"] = i; if(SUPPORT_STORAGE && this.store){ @@ -103,7 +102,6 @@ if(SUPPORT_HELPERS){ for(let i = index; i < pos; i++){ current = this.dom[i] = this.dom[i + 1]; - current["_idx"] = i; if(SUPPORT_STORAGE && this.store){ @@ -113,7 +111,6 @@ if(SUPPORT_HELPERS){ } current = this.dom[pos] = tmp; - current["_idx"] = pos; if(SUPPORT_STORAGE && this.store){ @@ -132,9 +129,6 @@ if(SUPPORT_HELPERS){ function update(dom, store, a, b, index_b, index_a){ - a["_idx"] = index_b; - b["_idx"] = index_a; - dom[index_a] = b; dom[index_b] = a; @@ -195,12 +189,12 @@ if(SUPPORT_HELPERS){ if(typeof tmp_a !== "number"){ - tmp_a = tmp_a["_idx"]; + tmp_a = this.index(tmp_a); } if(typeof tmp_b !== "number"){ - tmp_b = tmp_b["_idx"]; + tmp_b = this.index(tmp_b); } if(tmp_b !== tmp_a + 1){ @@ -233,12 +227,12 @@ if(SUPPORT_HELPERS){ if(typeof tmp_a !== "number"){ - tmp_a = tmp_a["_idx"]; + tmp_a = this.index(tmp_a); } if(typeof tmp_b !== "number"){ - tmp_b = tmp_b["_idx"]; + tmp_b = this.index(tmp_b); } if(tmp_b !== tmp_a - 1){ @@ -290,7 +284,7 @@ if(SUPPORT_HELPERS){ } else{ - tmp_a = a["_idx"]; + tmp_a = this.index(a); } if(typeof b === "number"){ @@ -300,7 +294,7 @@ if(SUPPORT_HELPERS){ } else{ - tmp_b = b["_idx"]; + tmp_b = this.index(b); } //if(tmp_a !== tmp_b){ @@ -324,9 +318,6 @@ if(SUPPORT_HELPERS){ //this.root.insertBefore(b, (tmp_a + 1) === tmp_b ? a : this.dom[tmp_a + 1]); //this.root.insertBefore(b, this.dom[tmp_a + 1] || null); - a["_idx"] = tmp_b; - b["_idx"] = tmp_a; - this.dom[tmp_a] = b; this.dom[tmp_b] = a; diff --git a/src/mikado.js b/src/mikado.js index 1ac2509..a835503 100644 --- a/src/mikado.js +++ b/src/mikado.js @@ -224,7 +224,12 @@ if(SUPPORT_POOLS && ((SUPPORT_HELPERS === true) || (SUPPORT_HELPERS && SUPPORT_H Mikado.prototype.index = function(node){ - return node["_idx"]; + for(let i = 0, length = this.length; i < length; i++){ + + if(this.dom[i] === node) return i; + } + + return -1; }; Mikado.prototype.node = function(index){ @@ -244,7 +249,7 @@ if(SUPPORT_STORAGE){ this.store ? - this.store[get_by_node ? index["_idx"] : index] + this.store[get_by_node ? this.index(index) : index] : (get_by_node ? index : this.dom[index])["_data"] ); @@ -516,7 +521,6 @@ function collection_to_array(collection){ for(let i = 0, node; i < length; i++) { node = collection[i]; - node["_idx"] = i; array[i] = node; } @@ -535,7 +539,7 @@ Mikado.prototype.create = function(data, view, index){ if(SUPPORT_POOLS && keyed && ( // NOTE: this optimization cannot render more than one data item which has // the same key within same template on the same view instance - // TODO: removing from the live pool may break indices + // TODO: removing from the live pool may break indices, also breaks shift within reconcile //(node = this.live[key]) || ((pool = this.key_pool) && (node = pool[key])) )){ @@ -592,10 +596,10 @@ Mikado.prototype.create = function(data, view, index){ factory = 1; node = this.factory; - // if(node){ - // - // node["_cache"] = {}; - // } + if(SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && node && this.cache){ + + node["_cache"] = {}; + } } if(!SUPPORT_STORAGE || !SUPPORT_REACTIVE || !found || !this.stealth || this.observe){ @@ -607,9 +611,11 @@ Mikado.prototype.create = function(data, view, index){ node = this.factory.cloneNode(true); - if(SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS){ + if(SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && this.cache){ - node["_cache"] = Object.assign({}, this.factory["_cache"]); + node["_cache"] = this.factory["_cache"]; + // NOTE: how often a cache from factory could be re-used VS. overhead from Object.assign + //node["_cache"] = Object.assign({}, this.factory["_cache"]); } let tmp; @@ -648,8 +654,6 @@ Mikado.prototype.apply = function(root, data, payload, index){ } else{ - //index || (index === 0) || (index = root["_idx"]); - if(SUPPORT_STORAGE){ data || (data = this.store ? this.store[index] : root["_data"]); @@ -706,11 +710,11 @@ if(SUPPORT_STORAGE){ node = this.dom[index]; } - else if(index && (typeof (tmp = index["_idx"]) === "number")){ - - node = index; - index = tmp; - } + // else if(index && (typeof (tmp = index["_idx"]) === "number")){ + // + // node = index; + // index = tmp; + // } else{ view = index; @@ -884,8 +888,6 @@ Mikado.prototype.render = function(data, view, callback, skip_async){ // update if(x < min){ - //let has_moved; - for(; x < min; x++){ const node = this.dom[x]; @@ -898,16 +900,13 @@ Mikado.prototype.render = function(data, view, callback, skip_async){ // if((tmp = this.live[key])){ // this.arrange(node, tmp, item, view, x); - // //has_moved = true; // } // else{ - // // this.replace(node, item, view, x); // } } else{ - // if(has_moved) node["_idx"] = x; this.update(node, item, view, x); } } @@ -994,16 +993,22 @@ Mikado.prototype.render = function(data, view, callback, skip_async){ Mikado.prototype.reconcile = function(b, view, x, render){ + const store = SUPPORT_STORAGE && this.store && !this.extern; const a = this.dom; const keys = this.live; let end_b = b.length; let end_a = a.length; let max_end = end_a > end_b ? end_a : end_b; let shift = 0; - let has_update; const key = this.key; //let steps = 0; + if(store){ + + // skips updating internal store + this.store = 0; + } + for(x || (x = 0); x < max_end; x++){ let found; @@ -1011,31 +1016,40 @@ Mikado.prototype.reconcile = function(b, view, x, render){ if(x < end_b){ const b_x = b[x]; - const b_x_key = b_x[key]; + const ended = x >= end_a; + let a_x; + let b_x_key; + let a_x_key; - if(render && (!keys[b_x_key] || (x >= end_a))){ + if(!ended){ - end_a++; - max_end = end_a > end_b ? end_a : end_b; - has_update = 1; + a_x = a[x]; + b_x_key = b_x[key]; + a_x_key = a_x["_key"]; - this.add(b_x, view, x, null, /* skip indexing */ 1); - continue; + if(a_x_key === b_x_key){ + + if(render){ + + this.update(a_x, b_x, view, x); + } + + continue; + } } - const a_x = a[x]; - const a_x_key = a_x["_key"]; + if(render && (ended || !keys[b_x_key])){ - if(a_x_key === b_x_key){ + if(ended || !this.key_pool){ - if(has_update){ + end_a++; + max_end = end_a > end_b ? end_a : end_b; - a_x["_idx"] = x; + this.add(b_x, view, x); } + else{ - if(render){ - - this.update(a_x, b_x, view, x); + this.replace(a_x, b_x, view, x); } continue; @@ -1057,30 +1071,28 @@ Mikado.prototype.reconcile = function(b, view, x, render){ const tmp_a = a[idx_a - 1]; // when distance is 1 it will always move before, no predecessor check necessary - this.root.insertBefore(tmp_a, a_x); - tmp_a["_idx"] = x; + insertBefore(this.root, tmp_a, a_x); if(render){ this.update(tmp_a, b_x, view, x); } - // fast path optimization when distance is equal (just useful to skip re-indexing), has no extra cost + // fast path optimization when distance is equal (skips finding on next turn) if(idx_a === idx_b){ if((y - x) > 1){ - this.root.insertBefore(a_x, a[idx_a] || null); + insertBefore(this.root, a_x, a[idx_a]); } - a_x["_idx"] = y; a[x] = a[y]; a[y] = a_x; - if(render){ - - this.update(a_x, b[y], view, y); - } + // if(render){ + // + // this.update(a_x, b[y], view, y); + // } //steps++; } @@ -1090,7 +1102,6 @@ Mikado.prototype.reconcile = function(b, view, x, render){ //a.splice(x, 0, a.splice(idx_a - 1, 1)[0]); shift++; - has_update = 1; } //steps++; @@ -1098,15 +1109,13 @@ Mikado.prototype.reconcile = function(b, view, x, render){ // shift down (move current => target) else{ - // the shift counter is the secret key for this strategy const index = idx_b - 1 + shift; // distance is always greater than 1, no predecessor check necessary - this.root.insertBefore(a_x, a[index] || null); + insertBefore(this.root, a_x, a[index]); splice(a, x, (index > end_a ? end_a : index) - 1); //a.splice(/* one is removed: */ index - 1, 0, a.splice(x, 1)[0]); - has_update = 1; shift--; x--; //steps++; @@ -1120,16 +1129,15 @@ Mikado.prototype.reconcile = function(b, view, x, render){ if(!found){ - this.remove(x, 1, /* resize */ 0, /* skip indexing */ 1); + this.remove(x); - has_update = 1; end_a--; max_end = end_a > end_b ? end_a : end_b; x--; } } - if(SUPPORT_STORAGE && this.store && !this.extern){ + if(store){ this.store = b; } @@ -1139,6 +1147,16 @@ Mikado.prototype.reconcile = function(b, view, x, render){ return this; }; +function insertBefore(root, a, b){ + + root.insertBefore(a, b || null); +} + +function appendChild(root, child){ + + root.appendChild(child); +} + /** * @param {Array} arr * @param {number} pos_old @@ -1178,11 +1196,10 @@ function splice(arr, pos_old, pos_new, insert){ * @param {Object|number=} view * @param {number|null=} index * @param {Element=} _replace_node - * @param {boolean|number=} _skip_indexing * @returns {Mikado} */ -Mikado.prototype.add = function(data, view, index, _replace_node, _skip_indexing){ +Mikado.prototype.add = function(data, view, index, _replace_node){ //profiler_start("add"); @@ -1244,22 +1261,12 @@ Mikado.prototype.add = function(data, view, index, _replace_node, _skip_indexing } } - node["_idx"] = length; - if(has_index){ - this.root.insertBefore(node, this.dom[length] || null); + insertBefore(this.root, node, this.dom[length]); splice(this.dom, this.length - 1, length, node); //this.dom.splice(length, 0, node); this.length++; - - if(!_skip_indexing){ - - for(;++length < this.length;){ - - this.dom[length]["_idx"] = length; - } - } } else{ @@ -1270,7 +1277,7 @@ Mikado.prototype.add = function(data, view, index, _replace_node, _skip_indexing } else{ - this.root.appendChild(node); + appendChild(this.root, node); this.length++; } @@ -1317,12 +1324,12 @@ Mikado.prototype.destroy = function(unload){ } this.length = 0; - this.dom = null; - this.root = null; - this.template = null; - this.vpath = null; - this.update_path = null; - this.factory = null; + this.dom = + this.root = + this.template = + this.vpath = + this.update_path = + this.factory = this.live = null; if(SUPPORT_STORAGE){ @@ -1389,11 +1396,10 @@ Mikado.prototype.append = function(data, view, index){ * @param {!Element|number} index * @param {number=} count * @param {number=} resize - * @param {boolean|number=} _skip_indexing * @returns {Mikado} */ -Mikado.prototype.remove = function(index, count, resize, _skip_indexing){ +Mikado.prototype.remove = function(index, count, resize){ let length = this.length; @@ -1403,7 +1409,7 @@ Mikado.prototype.remove = function(index, count, resize, _skip_indexing){ if(typeof index === "object"){ - index = index["_idx"]; + index = this.index(index); } else if(index < 0){ @@ -1413,20 +1419,23 @@ Mikado.prototype.remove = function(index, count, resize, _skip_indexing){ if(!length || (index >= length)) return this; - if(count < 0){ + if(count){ - index -= count + 1; + if(count < 0){ - if(index < 0){ + index -= count + 1; - index = 0; - } + if(index < 0){ + + index = 0; + } - count *= -1; + count *= -1; + } } else{ - count || (count = 1); + count = 1; } let nodes; @@ -1482,14 +1491,6 @@ Mikado.prototype.remove = function(index, count, resize, _skip_indexing){ this.length = length; - if(!_skip_indexing && (index < length)){ - - for(; index < length; index++){ - - this.dom[index]["_idx"] = index; - } - } - if(SUPPORT_POOLS && this.tpl_pool && !this.key_pool && (count > 1)){ // reverse is applied in order to use push/pop rather than shift/unshift @@ -1568,7 +1569,7 @@ Mikado.prototype.replace = function(node, data, view, index){ } else{ - index = node["_idx"]; + index = this.index(node); } } @@ -1615,7 +1616,7 @@ Mikado.prototype.update = function(node, data, view, index){ } else{ - index = node["_idx"]; + index = this.index(node); } } @@ -1786,7 +1787,7 @@ Mikado.prototype.parse = function(tpl, index, path, dom_path){ tmp_fn = ""; this.vpath = []; node["_path"] = dom_path = []; - if(SUPPORT_CACHE && this.cache) node["_cache"] = {}; + if(SUPPORT_CACHE && !SUPPORT_CACHE_HELPERS && this.cache) node["_cache"] = {}; root_node = node; } @@ -2034,7 +2035,7 @@ Mikado.prototype.parse = function(tpl, index, path, dom_path){ // } } - node.appendChild(text_node); + appendChild(node, text_node); } else if(html){ @@ -2113,7 +2114,7 @@ Mikado.prototype.parse = function(tpl, index, path, dom_path){ } // process child recursively - node.appendChild(this.parse(current, index + i + 1, path + tmp, dom_path)); + appendChild(node, this.parse(current, index + i + 1, path + tmp, dom_path)); } } else{ @@ -2125,7 +2126,7 @@ Mikado.prototype.parse = function(tpl, index, path, dom_path){ } // process child recursively - node.appendChild(this.parse(child, index + 1, path + ">", dom_path)); + appendChild(node, this.parse(child, index + 1, path + ">", dom_path)); } } diff --git a/test/dist/mikado.pre.js b/test/dist/mikado.pre.js index 3d9ca64..fa9bb70 100644 --- a/test/dist/mikado.pre.js +++ b/test/dist/mikado.pre.js @@ -1,5 +1,5 @@ /**! - * Mikado.js v0.7.4 + * Mikado.js v0.7.42 * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Licence: Apache-2.0 @@ -11,8 +11,8 @@ Object.assign || (Object.assign = function() { e = a[d]; f = Object.keys(e); g = f.length; - for (var h = 0, m; h < g; h++) { - m = f[h], c[m] = e[m]; + for (var k = 0, l; k < g; k++) { + l = f[k], c[l] = e[l]; } } return c; @@ -38,9 +38,9 @@ window.Promise || (window.Promise = function() { }; return a; }()); -function k(a, b, c, d) { +function h(a, b, c, d) { if ("tap" === b) { - if (q || v) { + if (t || x) { aa(a); return; } @@ -49,7 +49,7 @@ function k(a, b, c, d) { } window[(a ? "add" : "remove") + "EventListener"](b, c, d || {passive:!0, capture:!0}); } -function B(a, b) { +function A(a, b) { b || (b = a.type); var c = a.target, d = c, e = c["_event_" + b]; if (e) { @@ -82,54 +82,58 @@ function B(a, b) { c["_event_" + b] = e; c["_root_" + b] = d; } - if (b = da[e]) { + if (b = D[e]) { a.preventDefault(), b(d, a, c); } a.stopPropagation(); } -var D = {}, da = {}, ca = document.body, q = "ontouchstart" in window, v = !q && window.PointerEvent && navigator.maxTouchPoints, ba; -E.route = E.prototype.route = function(a, b) { - da[a] = b; +var E = {}, D = {}, ca = document.body, t = "ontouchstart" in window, x = !t && window.PointerEvent && navigator.maxTouchPoints, ba; +F.route = F.prototype.route = function(a, b) { + D[a] = b; return this; }; -var F, G, aa; -if (q || v) { - var ea = function(a, b) { +F.dispatch = F.prototype.dispatch = function(a, b, c, d) { + D[a](b, c, d); + return this; +}; +var G, H, aa; +if (t || x) { + var da = function(a, b) { b && (a = b[0]); - F = a.clientX; - G = a.clientY; + G = a.clientX; + H = a.clientY; + }, ea = function(a) { + var b = G, c = H; + da(a, a.changedTouches); + 50 > Math.abs(G - b) && 50 > Math.abs(H - c) && A.call(this, a, "tap"); }, fa = function(a) { - var b = F, c = G; - ea(a, a.changedTouches); - 50 > Math.abs(F - b) && 50 > Math.abs(G - c) && B.call(this, a, "tap"); - }, ha = function(a) { - ea(a, a.touches); + da(a, a.touches); }; aa = function(a) { - k(a, v ? "pointerdown" : "touchstart", ha, !1); - k(a, v ? "pointerup" : "touchend", fa, !1); + h(a, x ? "pointerdown" : "touchstart", fa, !1); + h(a, x ? "pointerup" : "touchend", ea, !1); }; } -E.listen = E.prototype.listen = function(a, b) { - D[a] || (k(1, a, B, b || !0), D[a] = 1); +F.listen = F.prototype.listen = function(a, b) { + E[a] || (h(1, a, A, b || !0), E[a] = 1); return this; }; -E.unlisten = E.prototype.unlisten = function(a, b) { - D[a] && (k(0, a, B, b || !0), D[a] = 0); +F.unlisten = F.prototype.unlisten = function(a, b) { + E[a] && (h(0, a, A, b || !0), E[a] = 0); return this; }; -E.prototype.move = function(a, b) { +F.prototype.move = function(a, b) { if ("number" === typeof a) { var c = a; a = this.dom[c]; } else { - c = a._idx; + c = this.index(a); } 0 > b && (b = this.length + b - 1); c !== b && this.shift(a, b - c); return this; }; -E.prototype.shift = function(a, b, c) { +F.prototype.shift = function(a, b, c) { if (!b) { return this; } @@ -137,112 +141,111 @@ E.prototype.shift = function(a, b, c) { var d = a; a = this.dom[a]; } else { - d = a._idx; + d = this.index(a); } var e = 0 > b; if (e && d || !e && d < this.length - 1) { b = e ? Math.max(d + b, 0) : Math.min(d + b, this.length - 1); var f = this.dom[b], g = e && 1 < d - b || !e && 1 < b - d; if (!g && this.reuse && (this.store || this.loose)) { - var h = this.store ? this.store[d] : a._data; + var k = this.store ? this.store[d] : a._data; this.update(a, this.store ? this.store[b] : f._data, c, b); - this.update(f, h, c, d); + this.update(f, k, c, d); } else { this.root.insertBefore(a, e ? f : this.dom[b + 1] || null); } if (g) { - f = this.dom[d]; - a = this.store && this.store[d]; + a = this.dom[d]; + f = this.store && this.store[d]; if (e) { - for (e = d; e > b; e--) { - d = this.dom[e] = this.dom[e - 1], d._idx = e, this.store && (this.store[e] = this.store[e - 1]); + for (; d > b; d--) { + this.dom[d] = this.dom[d - 1], this.store && (this.store[d] = this.store[d - 1]); } } else { - for (e = d; e < b; e++) { - d = this.dom[e] = this.dom[e + 1], d._idx = e, this.store && (this.store[e] = this.store[e + 1]); + for (; d < b; d++) { + this.dom[d] = this.dom[d + 1], this.store && (this.store[d] = this.store[d + 1]); } } - d = this.dom[b] = f; - d._idx = b; - this.store && (this.store[b] = a); + this.dom[b] = a; + this.store && (this.store[b] = f); } else { - c = this.dom, e = this.store, a._idx = b, f._idx = d, c[d] = f, c[b] = a, e && (f = e[b], e[b] = e[d], e[d] = f); + c = this.dom, e = this.store, c[d] = f, c[b] = a, e && (a = e[b], e[b] = e[d], e[d] = a); } } return this; }; -E.prototype.up = function(a, b) { +F.prototype.up = function(a, b) { (!b || 0 < b) && this.shift(a, -(b || 1)); return this; }; -E.prototype.down = function(a, b) { +F.prototype.down = function(a, b) { (!b || 0 < b) && this.shift(a, b || 1); return this; }; -E.prototype.first = function(a) { +F.prototype.first = function(a) { return this.shift(a, -this.length); }; -E.prototype.last = function(a) { +F.prototype.last = function(a) { return this.shift(a, this.length); }; -E.prototype.before = function(a, b) { - "number" !== typeof a && (a = a._idx); - "number" !== typeof b && (b = b._idx); +F.prototype.before = function(a, b) { + "number" !== typeof a && (a = this.index(a)); + "number" !== typeof b && (b = this.index(b)); b !== a + 1 && (0 > b && (b = this.length + b, 0 > a && b--), 0 > a && (a = this.length + a - 1), this.shift(a, b - a - 1)); return this; }; -E.prototype.after = function(a, b) { - "number" !== typeof a && (a = a._idx); - "number" !== typeof b && (b = b._idx); +F.prototype.after = function(a, b) { + "number" !== typeof a && (a = this.index(a)); + "number" !== typeof b && (b = this.index(b)); b !== a - 1 && (0 > b && (b = this.length + b - 2, 0 > a && b++), 0 > a && (a = this.length + a - 1), this.shift(a, b - a + 1)); return this; }; -E.prototype.swap = function(a, b, c) { +F.prototype.swap = function(a, b, c) { if (a !== b) { if ("number" === typeof a) { var d = a; a = this.dom[a]; } else { - d = a._idx; + d = this.index(a); } if ("number" === typeof b) { var e = b; b = this.dom[b]; } else { - e = b._idx; + e = this.index(b); } if (this.reuse && (this.store || this.loose)) { var f = this.store ? this.store[d] : a._data; this.update(a, this.store ? this.store[e] : b._data, c, d); this.update(b, f, c, e); } else { - c = d + 1 !== e, this.root.insertBefore(c ? a : b, c ? b : a), c && e + 1 !== d && this.root.insertBefore(b, this.dom[d + 1] || null), a._idx = e, b._idx = d, this.dom[d] = b, this.dom[e] = a, this.store && !this.extern && (a = this.store[e], this.store[e] = this.store[d], this.store[d] = a); + c = d + 1 !== e, this.root.insertBefore(c ? a : b, c ? b : a), c && e + 1 !== d && this.root.insertBefore(b, this.dom[d + 1] || null), this.dom[d] = b, this.dom[e] = a, this.store && !this.extern && (a = this.store[e], this.store[e] = this.store[d], this.store[d] = a); } } return this; }; -var H = {}; -function ia(a) { - return H[a] = new RegExp("(?:^|\\s)" + a + "(?!\\S)", "g"); +var I = {}; +function ha(a) { + return I[a] = new RegExp("(?:^|\\s)" + a + "(?!\\S)", "g"); } -function ja(a, b) { - I(a, b) || (a.className += " " + b, a._class += " " + b); +function ia(a, b) { + J(a, b) || (a.className += " " + b, a._class += " " + b); return this; } -function ka(a, b) { - b = (a._class || (a._class = a.className)).replace(H[b] || ia(b), ""); +function ja(a, b) { + b = (a._class || (a._class = a.className)).replace(I[b] || ha(b), ""); a._class !== b && (a.className = b, a._class = b); return this; } -function I(a, b) { - return !!(a._class || (a._class = a.className)).match(H[b] || ia(b)); +function J(a, b) { + return !!(a._class || (a._class = a.className)).match(I[b] || ha(b)); } -function la(a, b) { +function ka(a, b) { var c = a._attr || (a._attr = {}), d = c[b]; return d || "" === d ? d : c[b] = a.getAttribute(b); } -;var J = window.localStorage; -E.prototype.export = function() { +;var K = window.localStorage; +F.prototype.export = function() { if (this.store) { var a = this.store; } else { @@ -253,142 +256,142 @@ E.prototype.export = function() { } } } - a && J.setItem(this.template, JSON.stringify(a)); + a && K.setItem(this.template, JSON.stringify(a)); return this; }; -E.prototype.import = function() { - var a = J.getItem(this.template); +F.prototype.import = function() { + var a = K.getItem(this.template); a && (this.store = a = JSON.parse(a)); return this; }; -E.prototype.delete = function(a) { - J.removeItem(a || this.template); +F.prototype.delete = function(a) { + K.removeItem(a || this.template); return this; }; -var K = Array.prototype, L = window.Proxy, M = 0; -function N(a) { - if (!(this instanceof N)) { - return new N(a); +var L = Array.prototype, M = window.Proxy, N = 0; +function O(a) { + if (!(this instanceof O)) { + return new O(a); } - if (a instanceof N) { + if (a instanceof O) { return a; } this.view = this.mikado = null; var b = a ? a.length : 0; - if (L) { + if (M) { if (b) { for (var c = 0; c < b; c++) { this[c] = a[c]; } } this.length = b; - this.proto = {splice:K.splice.bind(this), pop:K.pop.bind(this), shift:K.shift.bind(this), unshift:K.unshift.bind(this), push:K.push.bind(this)}; - return new Proxy(this, ma); + this.proto = {splice:L.splice.bind(this), pop:L.pop.bind(this), shift:L.shift.bind(this), unshift:L.unshift.bind(this), push:L.push.bind(this)}; + return new Proxy(this, la); } this.proto = a || []; for (a = 0; a <= b; a++) { - O(this, a); + P(this, a); } - M = b; - O(this, "length"); + N = b; + P(this, "length"); } -function O(a, b) { +function P(a, b) { Object.defineProperty(a, b, {get:function() { return this.proto[b]; }, set:function(a) { - "number" === typeof b && (b === M && O(this, ++M), ma.set(this, b, a)); + "number" === typeof b && (b === N && P(this, ++N), la.set(this, b, a)); }}); } -var P = !1, ma = {set:function(a, b, c) { +var Q = !1, la = {set:function(a, b, c) { if ("number" === typeof b) { var d = !0; } else { var e = parseInt(b, 10); b === "" + e && (b = e, d = !0); } - if (!P) { - P = !0; + if (!Q) { + Q = !0; if ((e = a.mikado) && !e.skip) { var f = a.length; if (d) { var g = e.length; f !== g && (a.length = g); if (e.stealth && a[b] === c) { - return P = !1, !0; + return Q = !1, !0; } d = a.view; b >= g ? (e.add(c, d), a.length++) : b < g && (f = e.key, g = e.dom[b], e.reuse || f && g._key === c[f] ? e.update(g, c, d, b) : e.replace(g, c, d, b)); if (e.proxy) { - return P = !1, !0; + return Q = !1, !0; } } else { "length" === b && c < f && e.remove(c, f - c); } } - P = !1; + Q = !1; } - (L ? a : a.proto)[b] = c; + (M ? a : a.proto)[b] = c; return !0; }}; -N.prototype.swap = function(a, b) { - P = !0; +O.prototype.swap = function(a, b) { + Q = !0; this.mikado.swap(a, b, this.view); - P = !1; + Q = !1; return this; }; -N.prototype.splice = function(a, b, c) { - P = !0; +O.prototype.splice = function(a, b, c) { + Q = !0; a || (a = 0); "undefined" === typeof b && (b = this.length - a, 0 > b && (b = 0)); b && this.mikado.remove(a, b); b = c ? this.proto.splice(a, b, c) : this.proto.splice(a, b); c && this.mikado.add(c, a, this.view); - P = !1; + Q = !1; return b; }; -N.prototype.push = function(a) { - P = !0; +O.prototype.push = function(a) { + Q = !0; this.mikado.add(a, this.view); this.mikado.proxy || (this[this.length] = a); - L && this.length++; - P = !1; + M && this.length++; + Q = !1; }; -N.prototype.unshift = function(a) { - P = !0; +O.prototype.unshift = function(a) { + Q = !0; this.mikado.add(a, 0, this.view); this.proto.unshift(a); - P = !1; + Q = !1; }; -N.prototype.pop = function() { - P = !0; +O.prototype.pop = function() { + Q = !0; this.mikado.remove(this.length - 1); var a = this.proto.pop(); - P = !1; + Q = !1; return a; }; -N.prototype.shift = function() { - P = !0; +O.prototype.shift = function() { + Q = !0; this.mikado.remove(0); var a = this.proto.shift(); - P = !1; + Q = !1; return a; }; -N.prototype.concat = function(a) { +O.prototype.concat = function(a) { for (var b = a.length, c = 0; c < b; c++) { this.push(a[c]); } return this; }; -N.prototype.sort = function(a) { - K.sort.call(this, a); +O.prototype.sort = function(a) { + L.sort.call(this, a); return this; }; -N.prototype.reverse = function() { - K.reverse.call(this); +O.prototype.reverse = function() { + L.reverse.call(this); return this; }; -N.prototype.slice = K.slice; -N.prototype.map = function(a, b) { +O.prototype.slice = L.slice; +O.prototype.map = function(a, b) { b && (a = a.bind(this)); b = 0; for (var c = this.length; b < c; b++) { @@ -396,7 +399,7 @@ N.prototype.map = function(a, b) { } return this; }; -N.prototype.filter = function(a, b) { +O.prototype.filter = function(a, b) { b && (a = a.bind(this)); b = 0; for (var c = this.length; b < c; b++) { @@ -414,7 +417,7 @@ N.prototype.filter = function(a, b) { e && this.splice(d, e); return this; }; -N.prototype.indexOf = function(a) { +O.prototype.indexOf = function(a) { for (var b = 0, c = this.length; b < c; b++) { if (this[b] === a) { return b; @@ -422,7 +425,7 @@ N.prototype.indexOf = function(a) { } return -1; }; -N.prototype.lastIndexOf = function(a) { +O.prototype.lastIndexOf = function(a) { for (var b = this.length - 1; 0 <= b; b--) { if (this[b] === a) { return b; @@ -430,12 +433,12 @@ N.prototype.lastIndexOf = function(a) { } return -1; }; -N.prototype.forEach = function(a) { +O.prototype.forEach = function(a) { for (var b = 0, c = this.length; b < c; b++) { a(this[b]); } }; -var oa = !window.Proxy && function() { +var na = !window.Proxy && function() { function a(a, c) { this.path = c.path; this.handler = c.handler; @@ -452,11 +455,11 @@ var oa = !window.Proxy && function() { Object.defineProperty(a, c, {get:function() { return d; }, set:function(a) { - d !== a && (na(b.handler, b.path, c, a), d = a); + d !== a && (ma(b.handler, b.path, c, a), d = a); }}); }; return a; -}(), pa = {_text:function(a, b) { +}(), oa = {_text:function(a, b) { a.nodeValue = b; }, _html:function(a, b) { a.innerHTML = b; @@ -467,43 +470,43 @@ var oa = !window.Proxy && function() { }, _attr:function(a, b, c) { a.setAttribute(c, b); }}; -function qa(a, b, c) { - return new (oa || Proxy)(a, {path:b, handler:c, get:ra, set:sa}); +function pa(a, b, c) { + return new (na || Proxy)(a, {path:b, handler:c, get:qa, set:ra}); } -function ra(a, b) { +function qa(a, b) { return "_proxy" === b || a[b]; } -function sa(a, b, c) { - a[b] !== c && (na(this.handler, this.path, b, c), a[b] = c); +function ra(a, b, c) { + a[b] !== c && (ma(this.handler, this.path, b, c), a[b] = c); return !0; } -function na(a, b, c, d) { +function ma(a, b, c, d) { if (a = a["data." + c]) { for (var e = 0, f = a.length, g; e < f; e++) { - g = a[e], pa[g[0]](b[g[1]], d, g[2] || c); + g = a[e], oa[g[0]](b[g[1]], d, g[2] || c); } } } -;var ta = window, ua = ta.requestAnimationFrame, va = ta.cancelAnimationFrame, wa = {}, Q = {}, R = {}, S = {}, T = {}; -function E(a, b, c) { - if (!(this instanceof E)) { - return new E(a, b, c); +;var sa = window, ta = sa.requestAnimationFrame, ua = sa.cancelAnimationFrame, va = {}, R = {}, S = {}, T = {}, U = {}; +function F(a, b, c) { + if (!(this instanceof F)) { + return new F(a, b, c); } a.nodeType || (c = b, b = a, a = null); a ? this.mount(a) : (this.root = this.dom = null, this.length = 0); this.init(b, c); } -E.register = E.register = function(a, b) { +F.register = F.register = function(a, b) { b || (b = a, a = b.n); - Q[a] = b; - return E; + R[a] = b; + return F; }; -E.prototype.mount = function(a) { - this.root !== a && (this.key && this.root && (this.root._pool = this.live, this.live = a._pool || {}), this.root = a, this.check(), this.dom = a._dom || (a._dom = xa(a.children)), this.length = this.dom.length); +F.prototype.mount = function(a) { + this.root !== a && (this.key && this.root && (this.root._pool = this.live, this.live = a._pool || {}), this.root = a, this.check(), this.dom = a._dom || (a._dom = wa(a.children)), this.length = this.dom.length); return this; }; -E.prototype.sync = function(a) { - this.root._dom = this.dom = xa(this.root.children); +F.prototype.sync = function(a) { + this.root._dom = this.dom = wa(this.root.children); this.length = this.dom.length; if (a && this.cache) { for (a = 0; a < this.length; a++) { @@ -517,8 +520,8 @@ E.prototype.sync = function(a) { } return this; }; -E.prototype.purge = function() { - R[this.template + (this.cache ? "_cache" : "")] = null; +F.prototype.purge = function() { + S[this.template + (this.cache ? "_cache" : "")] = null; if (this.key) { if (this.length) { for (var a = Object.keys(this.live), b = 0, c = a.length, d = void 0; b < c; b++) { @@ -528,21 +531,26 @@ E.prototype.purge = function() { this.live = {}; } } - this.tpl_pool && (this.tpl_pool = S[this.template] = []); - this.key_pool && (this.key_pool = T[this.template] = {}); + this.tpl_pool && (this.tpl_pool = T[this.template] = []); + this.key_pool && (this.key_pool = U[this.template] = {}); return this; }; -E.prototype.index = function(a) { - return a._idx; +F.prototype.index = function(a) { + for (var b = 0, c = this.length; b < c; b++) { + if (this.dom[b] === a) { + return b; + } + } + return -1; }; -E.prototype.node = function(a) { +F.prototype.node = function(a) { return this.dom[a]; }; -E.prototype.data = function(a) { +F.prototype.data = function(a) { var b = "object" === typeof a; - return this.store ? this.store[b ? a._idx : a] : (b ? a : this.dom[a])._data; + return this.store ? this.store[b ? this.index(a) : a] : (b ? a : this.dom[a])._data; }; -E.prototype.find = function(a) { +F.prototype.find = function(a) { if (this.key) { return this.live["object" !== typeof a ? a : a[this.key]]; } @@ -552,7 +560,7 @@ E.prototype.find = function(a) { } } }; -E.prototype.search = function(a) { +F.prototype.search = function(a) { a = Object.values(a).join("^"); for (var b = 0; b < this.length; b++) { if (Object.values(this.data(b)).join("^") === a) { @@ -560,12 +568,12 @@ E.prototype.search = function(a) { } } }; -E.prototype.where = function(a) { +F.prototype.where = function(a) { for (var b = Object.keys(a), c = b.length, d = [], e = 0, f, g; e < this.length; e++) { f = this.data(e); g = 1; - for (var h = 0, m; h < c; h++) { - if (m = b[h], f[m] !== a[m]) { + for (var k = 0, l; k < c; k++) { + if (l = b[k], f[l] !== a[l]) { g = 0; break; } @@ -574,18 +582,18 @@ E.prototype.where = function(a) { } return d; }; -E.prototype.init = function(a, b) { - "string" === typeof a ? a = Q[a] : (b || !a || a.n || (b = a, a = null), a ? a.n && E.register(a) : a = Q[this.template]); +F.prototype.init = function(a, b) { + "string" === typeof a ? a = R[a] : (b || !a || a.n || (b = a, a = null), a ? a.n && F.register(a) : a = R[this.template]); b || (b = this.config || {}); this.reuse = !1 !== b.reuse; - this.state = b.state || wa; + this.state = b.state || va; this.cache = !1 !== b.cache; this.async = b.async; this.timer = 0; this.on = b.on; var c = b.store || !1 !== b.store; (this.extern = "object" === typeof c) ? b.store = !0 : c && (c = []); - if (this.observe = c instanceof N) { + if (this.observe = c instanceof O) { c.mikado = this; } this.skip = 0; @@ -593,11 +601,11 @@ E.prototype.init = function(a, b) { this.store = !this.loose && c; this.config = b; c = a.n; - this.template !== c && (this.template = c, this.static = a.d, this.update_path = this.vpath = null, this.proxy = this.stealth = 0, this.include = null, this.factory = !1 !== b.prefetch && this.parse(a), this.check(), this.live = (this.key = a.k) && {}, this.tpl_pool = this.reuse && !1 !== b.pool && (S[c] || (S[c] = [])), this.key_pool = this.key && (b.keep || this.tpl_pool) && (T[c] || (T[c] = {})), this.size = this.tpl_pool && b.size); + this.template !== c && (this.template = c, this.static = a.d, this.update_path = this.vpath = null, this.proxy = this.stealth = 0, this.include = null, this.factory = !1 !== b.prefetch && this.parse(a), this.check(), this.live = (this.key = a.k) && {}, this.tpl_pool = this.reuse && !1 !== b.pool && (T[c] || (T[c] = [])), this.key_pool = this.key && (b.keep || this.tpl_pool) && (U[c] || (U[c] = {})), this.size = this.tpl_pool && b.size); return this; }; -E.once = E.once = function(a, b, c, d, e) { - var f = new E(a, b); +F.once = F.once = function(a, b, c, d, e) { + var f = new F(a, b); "function" === typeof d && (e = d, d = null); if (e) { var g = e; @@ -608,31 +616,31 @@ E.once = E.once = function(a, b, c, d, e) { } f.render(c, d, e); e || f.destroy(1); - return E; + return F; }; -E.prototype.check = function() { +F.prototype.check = function() { if (this.root) { var a = this.root._tpl; a !== this.template && (this.root._tpl = this.template, a && (this.live = {}, this.remove(0, this.length))); } return this; }; -function xa(a) { +function wa(a) { for (var b = a.length, c = Array(b), d = 0, e; d < b; d++) { - e = a[d], e._idx = d, c[d] = e; + e = a[d], c[d] = e; } return c; } -E.prototype.create = function(a, b, c) { +F.prototype.create = function(a, b, c) { var d = this.key, e = d && a[d], f, g; if (d && (g = this.key_pool) && (f = g[e])) { - var h = 1; + var k = 1; if (g) { if (g[e] = null, g = this.tpl_pool) { - var m = f._index; + var l = f._index; f._index = null; var n = g.pop(); - n !== f && (n._index = m, g[m] = n); + n !== f && (n._index = l, g[l] = n); } } else { d = 0; @@ -641,21 +649,21 @@ E.prototype.create = function(a, b, c) { if ((f = this.tpl_pool) && f.length) { f = f.pop(), g && (f._index = null, g[f._key] = null); } else { - var w = 1; + var v = 1; f = this.factory; } } - h && this.stealth && !this.observe || this.apply(f, a, b, c); - if (w) { + k && this.stealth && !this.observe || this.apply(f, a, b, c); + if (v) { f = this.factory.cloneNode(!0); - var l; - (l = this.on) && (l = l.create) && l(f); + var m; + (m = this.on) && (m = m.create) && m(f); } d && (f._key = e, this.live[e] = f); return f; }; -E.prototype.apply = function(a, b, c, d) { - this.factory || (this.factory = a = this.parse(Q[this.template])); +F.prototype.apply = function(a, b, c, d) { + this.factory || (this.factory = a = this.parse(R[this.template])); if (!this.static) { b || (b = this.store ? this.store[d] : a._data); c && this.observe && (this.store.view = c); @@ -665,18 +673,14 @@ E.prototype.apply = function(a, b, c, d) { return this; } }; -E.prototype.refresh = function(a, b) { +F.prototype.refresh = function(a, b) { if (this.stealth) { return this; } var c; - if ("number" === typeof a) { - var d = this.dom[a]; - } else { - a && "number" === typeof(c = a._idx) ? (d = a, a = c) : b = a; - } - if (d) { - return this.apply(d, null, b, a); + "number" === typeof a ? c = this.dom[a] : b = a; + if (c) { + return this.apply(c, null, b, a); } a = this.length; if ((c = this.store) && this.loose) { @@ -689,13 +693,13 @@ E.prototype.refresh = function(a, b) { } return this; }; -E.prototype.render = function(a, b, c, d) { +F.prototype.render = function(a, b, c, d) { if (!d) { b && "object" !== typeof b && (c = b, b = null); this.timer && this.cancel(); if (c) { var e = this; - this.timer = ua(function() { + this.timer = ta(function() { e.timer = 0; e.render(a, b, null, 1); "function" === typeof c && c(); @@ -705,7 +709,7 @@ E.prototype.render = function(a, b, c, d) { if (this.async) { var f = this; return new Promise(function(c) { - f.timer = ua(function() { + f.timer = ta(function() { f.timer = 0; f.render(a, b, null, 1); c(); @@ -733,16 +737,16 @@ E.prototype.render = function(a, b, c, d) { return this.remove(0, d); } } - var h = (this.key_pool || !this.reuse) && this.key; - h || this.reuse || (this.remove(0, d, g), d = 0); - var m = d < g ? d : g, n = 0; - if (n < m) { - for (; n < m; n++) { - var w = this.dom[n], l = a[n]; - if (h && w._key !== l[h]) { + var k = (this.key_pool || !this.reuse) && this.key; + k || this.reuse || (this.remove(0, d, g), d = 0); + var l = d < g ? d : g, n = 0; + if (n < l) { + for (; n < l; n++) { + var v = this.dom[n], m = a[n]; + if (k && v._key !== m[k]) { return this.reconcile(a, b, n, 1); } - this.update(w, l, b, n); + this.update(v, m, b, n); } } if (n < g) { @@ -754,39 +758,35 @@ E.prototype.render = function(a, b, c, d) { } return this; }; -E.prototype.reconcile = function(a, b, c, d) { - var e = this.dom, f = this.live, g = a.length, h = e.length, m = h > g ? h : g, n = 0, w = this.key; - for (c || (c = 0); c < m; c++) { - var l = void 0; - if (c < g) { - var t = a[c], u = t[w]; - if (d && (!f[u] || c >= h)) { - h++; - m = h > g ? h : g; - var p = 1; - this.add(t, b, c, null, 1); +F.prototype.reconcile = function(a, b, c, d) { + var e = this.store && !this.extern, f = this.dom, g = this.live, k = a.length, l = f.length, n = l > k ? l : k, v = 0, m = this.key; + e && (this.store = 0); + for (c || (c = 0); c < n; c++) { + var u = void 0; + if (c < k) { + var q = a[c], p = c >= l, w = void 0, r = void 0, B = void 0; + if (!p && (w = f[c], r = q[m], B = w._key, B === r)) { + d && this.update(w, q, b, c); continue; } - var r = e[c], z = r._key; - if (z === u) { - p && (r._idx = c); - d && this.update(r, t, b, c); + if (d && (p || !g[r])) { + p || !this.key_pool ? (l++, n = l > k ? l : k, this.add(q, b, c)) : this.replace(w, q, b, c); continue; } - for (var x = void 0, y = void 0, A = c + 1; A < m; A++) { - if (!x && A < h && e[A]._key === u && (x = A + 1), !y && A < g && a[A][w] === z && (y = A + 1), x && y) { - x >= y ? (l = e[x - 1], this.root.insertBefore(l, r), l._idx = c, d && this.update(l, t, b, c), x === y ? (1 < A - c && this.root.insertBefore(r, e[x] || null), r._idx = A, e[c] = e[A], e[A] = r, d && this.update(r, a[A], b, A)) : (U(e, x - 1, c), n++, p = 1)) : (p = y - 1 + n, this.root.insertBefore(r, e[p] || null), U(e, c, (p > h ? h : p) - 1), p = 1, n--, c--); - l = 1; + for (var y = p = void 0, z = c + 1; z < n; z++) { + if (!p && z < l && f[z]._key === r && (p = z + 1), !y && z < k && a[z][m] === B && (y = z + 1), p && y) { + p >= y ? (u = f[p - 1], this.root.insertBefore(u, w || null), d && this.update(u, q, b, c), p === y ? (1 < z - c && this.root.insertBefore(w, f[p] || null), f[c] = f[z], f[z] = w) : (V(f, p - 1, c), v++)) : (q = y - 1 + v, this.root.insertBefore(w, f[q] || null), V(f, c, (q > l ? l : q) - 1), v--, c--); + u = 1; break; } } } - l || (this.remove(c, 1, 0, 1), p = 1, h--, m = h > g ? h : g, c--); + u || (this.remove(c), l--, n = l > k ? l : k, c--); } - this.store && !this.extern && (this.store = a); + e && (this.store = a); return this; }; -function U(a, b, c, d) { +function V(a, b, c, d) { var e = d || a[b]; d && b++; if (b < c) { @@ -800,52 +800,43 @@ function U(a, b, c, d) { } a[c] = e; } -E.prototype.add = function(a, b, c, d, e) { +F.prototype.add = function(a, b, c, d) { if (!d) { if ("number" === typeof b) { c = b; b = null; - var f = 1; + var e = 1; } else { if (c || 0 === c) { - f = 1; + e = 1; } } } - c = d || f ? c : this.length; + c = d || e ? c : this.length; b = this.create(a, b, c); + var f; + this.proxy && (this.stealth && this.loose && b._data === a ? f = 1 : a._proxy || (a = pa(a, b._path || this.create_path(b), this.proxy))); + f || (this.store ? e && !this.extern ? V(this.store, this.length - 1, c, a) : (this.skip = 1, this.store[c] = a, this.skip = 0) : this.loose && (b._data = a)); + e ? (this.root.insertBefore(b, this.dom[c] || null), V(this.dom, this.length - 1, c, b), this.length++) : (d ? this.root.replaceChild(b, d) : (this.root.appendChild(b), this.length++), this.dom[c] = b); var g; - this.proxy && (this.stealth && this.loose && b._data === a ? g = 1 : a._proxy || (a = qa(a, b._path || this.create_path(b), this.proxy))); - g || (this.store ? f && !this.extern ? U(this.store, this.length - 1, c, a) : (this.skip = 1, this.store[c] = a, this.skip = 0) : this.loose && (b._data = a)); - b._idx = c; - if (f) { - if (this.root.insertBefore(b, this.dom[c] || null), U(this.dom, this.length - 1, c, b), this.length++, !e) { - for (; ++c < this.length;) { - this.dom[c]._idx = c; - } - } - } else { - d ? this.root.replaceChild(b, d) : (this.root.appendChild(b), this.length++), this.dom[c] = b; - } - var h; - (h = this.on) && (h = h.insert) && h(b); + (g = this.on) && (g = g.insert) && g(b); return this; }; -E.prototype.clear = function(a) { +F.prototype.clear = function(a) { this.length && this.remove(0, this.length); a && this.purge(); return this; }; -E.prototype.destroy = function(a) { +F.prototype.destroy = function(a) { a && this.unload(); this.length = 0; - this.include = this.store = this.live = this.factory = this.update_path = this.vpath = this.template = this.root = this.dom = null; + this.include = this.store = this.dom = this.root = this.template = this.vpath = this.update_path = this.factory = this.live = null; }; -E.prototype.cancel = function() { - this.timer && (va(this.timer), this.timer = null); +F.prototype.cancel = function() { + this.timer && (ua(this.timer), this.timer = null); return this; }; -E.prototype.append = function(a, b, c) { +F.prototype.append = function(a, b, c) { if ("number" === typeof b) { c = b; b = null; @@ -858,55 +849,48 @@ E.prototype.append = function(a, b, c) { } return this; }; -E.prototype.remove = function(a, b, c, d) { - var e = this.length; - a && ("object" === typeof a ? a = a._idx : 0 > a && (a = e + a - 1)); - if (!e || a >= e) { +F.prototype.remove = function(a, b, c) { + var d = this.length; + a && ("object" === typeof a ? a = this.index(a) : 0 > a && (a = d + a - 1)); + if (!d || a >= d) { return this; } - 0 > b ? (a -= b + 1, 0 > a && (a = 0), b *= -1) : b || (b = 1); - if (!a && b >= e) { + b ? 0 > b && (a -= b + 1, 0 > a && (a = 0), b *= -1) : b = 1; + if (!a && b >= d) { this.store && !this.extern && (this.store = c ? Array(c) : []); if (this.include && (this.key_pool || this.tpl_pool)) { for (b = 0; b < this.include.length; b++) { this.include[b].clear(); } } - var f = this.dom; - b = f.length; + a = this.dom; + b = a.length; this.root.textContent = ""; this.root._dom = this.dom = c ? Array(c) : []; - e = 0; + d = 0; } else { - this.store && !this.observe && this.store.splice(a, b), f = this.dom.splice(a, b), e -= b; + this.store && !this.observe && this.store.splice(a, b), a = this.dom.splice(a, b), d -= b; } - var g; - if ((g = this.on) && (g = g.remove)) { + var e; + if ((e = this.on) && (e = e.remove)) { for (c = 0; c < b; c++) { - g(f[c]); - } - } - this.length = e; - if (!d && a < e) { - for (; a < e; a++) { - this.dom[a]._idx = a; + e(a[c]); } } + this.length = d; if (this.tpl_pool && !this.key_pool && 1 < b) { - a = f; - d = a.length; - g = d / 2 | 0; - c = 0; - for (var h; c < g; c++) { - h = a[c], a[c] = a[d - c - 1], a[d - c - 1] = h; + e = a; + c = e.length; + for (var f = c / 2 | 0, g = 0, k; g < f; g++) { + k = e[g], e[g] = e[c - g - 1], e[c - g - 1] = k; } } - for (a = 0; a < b; a++) { - d = f[a], e && this.root.removeChild(d), this.checkout(d); + for (e = 0; e < b; e++) { + c = a[e], d && this.root.removeChild(c), this.checkout(c); } return this; }; -E.prototype.checkout = function(a) { +F.prototype.checkout = function(a) { if (this.key) { var b = a._key; this.live[b] = null; @@ -914,21 +898,21 @@ E.prototype.checkout = function(a) { } this.tpl_pool && (b = this.tpl_pool.length, !this.size || b < this.size) && (this.key_pool && (a._index = b), this.tpl_pool[b] = a); }; -E.prototype.replace = function(a, b, c, d) { - "undefined" === typeof d && ("number" === typeof a ? (d = a, a = this.dom[d]) : d = a._idx); +F.prototype.replace = function(a, b, c, d) { + "undefined" === typeof d && ("number" === typeof a ? (d = a, a = this.dom[d]) : d = this.index(a)); this.add(b, c, d, a); this.checkout(a); var e; (e = this.on) && (e = e.remove) && e(a); return this; }; -E.prototype.update = function(a, b, c, d) { - "undefined" === typeof d && ("number" === typeof a ? (d = a, a = this.dom[a]) : d = a._idx); +F.prototype.update = function(a, b, c, d) { + "undefined" === typeof d && ("number" === typeof a ? (d = a, a = this.dom[a]) : d = this.index(a)); if (this.proxy) { if (this.stealth && (this.store ? this.store[d] : a._data) === b) { return this; } - b._proxy || (b = qa(b, a._path || this.create_path(a), this.proxy)); + b._proxy || (b = pa(b, a._path || this.create_path(a), this.proxy)); } this.store ? (this.skip = 1, this.store[d] = b, this.skip = 0) : this.loose && (a._data = b); if (this.key) { @@ -939,116 +923,118 @@ E.prototype.update = function(a, b, c, d) { (g = this.on) && (g = g.update) && g(a); return this.apply(a, b, c, d); }; -E.prototype.create_path = function(a) { +F.prototype.create_path = function(a) { for (var b = this.vpath.length, c = {}, d = Array(b), e = 0, f; e < b; e++) { f = this.vpath[e]; - var g = e, h; - if (!(h = c[f])) { - h = a; - for (var m = 0, n = f.length, w = ""; m < n; m++) { - var l = f[m]; - w += l; - c[w] ? h = c[w] : (">" === l ? h = h.firstElementChild : "+" === l ? h = h.nextElementSibling : "|" === l && (h = h.firstChild), c[w] = h); + var g = e, k; + if (!(k = c[f])) { + k = a; + for (var l = 0, n = f.length, v = ""; l < n; l++) { + var m = f[l]; + v += m; + c[v] ? k = c[v] : (">" === m ? k = k.firstElementChild : "+" === m ? k = k.nextElementSibling : "|" === m && (k = k.firstChild), c[v] = k); } } - d[g] = h; + d[g] = k; } return a._path = d; }; -var V; -E.prototype.parse = function(a, b, c, d) { +var W; +F.prototype.parse = function(a, b, c, d) { if (!b) { - var e = R[a.n + (this.cache ? "_cache" : "")]; + var e = S[a.n + (this.cache ? "_cache" : "")]; if (e) { return this.update_path = e.update_path, this.static = e.static, this.stealth = e.stealth, this.proxy = e.proxy, this.include = e.include, this.vpath = e.vpath, e.node; } } e = document.createElement(a.t || "div"); - b || (b = 0, c = "&", V = "", this.vpath = [], e._path = d = [], this.cache && (e._cache = {})); - var f = a.s, g = a.i, h = a.x, m = a.h, n = a.a, w = a.e, l = a.c, t = a.j, u = this.vpath.length, p = 0, r = 0, z = ""; - t && (z += ";" + t, -1 < z.indexOf("self") && (p = 2)); - a.f && (V += ";if(" + a.f + "){self.hidden=false", p = 2); - l && ("object" === typeof l ? (t = l[1], l = l[0], z += this.cache ? ";v=" + l + ";if(self._class!==v){self._class=v;self.className=v}" : ";self.className=" + l, t && (W(this, l, ["_class", u]), r++), p++) : e.className = l); - if (n || w) { - var x; - n && (x = Object.keys(n)); - w && (l = Object.keys(w), x = x ? x.concat(l) : l); - for (l = 0; l < x.length; l++) { - t = x[l]; + b || (b = 0, c = "&", W = "", this.vpath = [], e._path = d = []); + var f = a.s, g = a.i, k = a.x, l = a.h, n = a.a, v = a.e, m = a.c, u = a.j, q = this.vpath.length, p = 0, w = 0, r = ""; + u && (r += ";" + u, -1 < r.indexOf("self") && (p = 2)); + a.f && (W += ";if(" + a.f + "){self.hidden=false", p = 2); + m && ("object" === typeof m ? (u = m[1], m = m[0], r += this.cache ? ";v=" + m + ";if(self._class!==v){self._class=v;self.className=v}" : ";self.className=" + m, u && (X(this, m, ["_class", q]), w++), p++) : e.className = m); + if (n || v) { + var B; + n && (B = Object.keys(n)); + v && (m = Object.keys(v), B = B ? B.concat(m) : m); + for (m = 0; m < B.length; m++) { + u = B[m]; var y = void 0; - n && "undefined" !== typeof(y = n[t]) || (y = w[t], this.listen(t)); + n && "undefined" !== typeof(y = n[u]) || (y = v[u], this.listen(u)); if ("object" === typeof y) { - var A = y[1]; + var z = y[1]; y = y[0]; - z += this.cache ? ";v=" + y + ";var _a=self._attr||(self._attr={});if(_a['" + t + "']!==v){_a['" + t + "']=v;self.setAttribute('" + t + "',v)}" : ";self.setAttribute('" + t + "'," + y + ")"; - A && (W(this, y, ["_attr", u, t]), r++); + r += this.cache ? ";v=" + y + ";var _a=self._attr||(self._attr={});if(_a['" + u + "']!==v){_a['" + u + "']=v;self.setAttribute('" + u + "',v)}" : ";self.setAttribute('" + u + "'," + y + ")"; + z && (X(this, y, ["_attr", q, u]), w++); p++; } else { - e.setAttribute(t, y); + e.setAttribute(u, y); } } } - f && ("string" === typeof f ? e.style.cssText = f : f.length && (x = f[1], f = f[0], z += this.cache ? ";v=" + f + ";if(self._css!==v){self._css=v;(self._style||(self._style=self.style)).cssText=v}" : ";self.style.cssText=" + f, x && (W(this, f, ["_css", u]), r++), p++)); + f && ("string" === typeof f ? e.style.cssText = f : f.length && (B = f[1], f = f[0], r += this.cache ? ";v=" + f + ";if(self._css!==v){self._css=v;(self._style||(self._style=self.style)).cssText=v}" : ";self.style.cssText=" + f, B && (X(this, f, ["_css", q]), w++), p++)); if (a["@"] || a.r) { this.include || (this.include = []); var C = a["@"] || a.i; a["@"] || (C.n = a["@"] = this.template + "@" + this.include.length, a.i = null); g = null; - z += ";this.include[" + this.include.length + "].mount(self).render(" + a.r + (a.m ? ".slice(" + (0 <= a.m ? "0," + a.m : a.m) + ")" : "") + ",view)"; - h = V; - V = ""; - this.include.push(new E(e, C, Object.assign({}, this.config, {store:!1, async:0}))); - V = h; + r += ";this.include[" + this.include.length + "].mount(self).render(" + a.r + (a.m ? ".slice(" + (0 <= a.m ? "0," + a.m : a.m) + ")" : "") + ",view)"; + k = W; + W = ""; + this.include.push(new F(e, C, Object.assign({}, this.config, {store:!1, async:0}))); + W = k; p++; } else { if (!g) { if (a["+"]) { - g = Q[a["+"]]; + g = R[a["+"]]; } else { - if (h) { - if (m = "object" === typeof h) { - C = h[1], h = h[0]; + if (k) { + if (l = "object" === typeof k) { + C = k[1], k = k[0]; } - f = document.createTextNode(h); - m && (p && u++, this.vpath[u] = c + "|", d[u] = f, ya(p, this.cache ? ";v=" + h + ";if(self._text!==v){self._text=v;self.nodeValue=v}" : ";self.nodeValue=" + h, u, this.cache), C && (W(this, h, ["_text", u]), r++), p && u--); + f = document.createTextNode(k); + l && (p && q++, this.vpath[q] = c + "|", d[q] = f, xa(p, this.cache ? ";v=" + k + ";if(self._text!==v){self._text=v;self.nodeValue=v}" : ";self.nodeValue=" + k, q, this.cache), C && (X(this, k, ["_text", q]), w++), p && q--); e.appendChild(f); } else { - m && ("object" === typeof m ? (C = m[1], m = m[0], z += this.cache ? ";v=" + m + ";if(self._html!==v){self._html=v;self.innerHTML=v}" : ";self.innerHTML=" + m, C && (W(this, m, ["_html", u]), r++), p++) : e.innerHTML = m); + l && ("object" === typeof l ? (C = l[1], l = l[0], r += this.cache ? ";v=" + l + ";if(self._html!==v){self._html=v;self.innerHTML=v}" : ";self.innerHTML=" + l, C && (X(this, l, ["_html", q]), w++), p++) : e.innerHTML = l); } } } } - p ? (this.vpath[u] = c, d[u] = e, this.static = 0, p === r && (this.stealth = 1), ya(p, z, u, this.cache)) : z && (V += z); - V += ""; + p ? (this.vpath[q] = c, d[q] = e, this.static = 0, p === w && (this.stealth = 1), xa(p, r, q, this.cache)) : r && (W += r); + W += ""; if (g) { if (g.length) { - for (z = ">", C = 0; C < g.length; C++) { - C && (z += "+"); - h = g[C]; - if (r = h["+"]) { - h = Q[r]; + for (w = ">", r = 0; r < g.length; r++) { + r && (w += "+"); + k = g[r]; + if (C = k["+"]) { + k = R[C]; } - e.appendChild(this.parse(h, b + C + 1, c + z, d)); + C = this.parse(k, b + r + 1, c + w, d); + e.appendChild(C); } } else { - if (r = g["+"]) { - g = Q[r]; + if (C = g["+"]) { + g = R[C]; } - e.appendChild(this.parse(g, b + 1, c + ">", d)); + c = this.parse(g, b + 1, c + ">", d); + e.appendChild(c); } } - a.f && (V += "}else " + (1 < p ? "self" : "p[" + u + "]") + ".hidden=true"); - b || (!this.static && V && (this.update_path = Function("p", "s", "data", "index", "view", '"use strict";var self,v' + V)), b = {update_path:this.update_path, static:this.static, vpath:this.vpath, node:e}, b.include = this.include, b.proxy = this.proxy, b.stealth = this.stealth, R[a.n + (this.cache ? "_cache" : "")] = b); + a.f && (W += "}else " + (1 < p ? "self" : "p[" + q + "]") + ".hidden=true"); + b || (!this.static && W && (this.update_path = Function("p", "s", "data", "index", "view", '"use strict";var self,v' + W)), b = {update_path:this.update_path, static:this.static, vpath:this.vpath, node:e}, b.include = this.include, b.proxy = this.proxy, b.stealth = this.stealth, S[a.n + (this.cache ? "_cache" : "")] = b); return e; }; -function W(a, b, c) { +function X(a, b, c) { a.proxy || (a.proxy = {}); (a.proxy[b] || (a.proxy[b] = [])).push(c); } -function ya(a, b, c, d) { - V = d || 1 < a ? V + (";self=p[" + c + "]" + b) : V + b.replace(/self/g, "p[" + c + "]"); +function xa(a, b, c, d) { + W = d || 1 < a ? W + (";self=p[" + c + "]" + b) : W + b.replace(/self/g, "p[" + c + "]"); } -E.prototype.load = function(a, b) { +F.prototype.load = function(a, b) { var c = this, d = new XMLHttpRequest; d.overrideMimeType("application/json"); d.open("GET", a, !1 !== b); @@ -1057,10 +1043,10 @@ E.prototype.load = function(a, b) { if (a) { try { var d = JSON.parse(a); - E.register(d); - c instanceof E && c.init(d); - } catch (h) { - var g = h; + F.register(d); + c instanceof F && c.init(d); + } catch (k) { + var g = k; } "function" === typeof b && b(g); } @@ -1068,35 +1054,35 @@ E.prototype.load = function(a, b) { d.send(); return this; }; -E.load = E.prototype.load; -E.prototype.unload = function(a) { +F.load = F.prototype.load; +F.prototype.unload = function(a) { a ? "object" === typeof a && (a = a.n) : a = this.template; - a && (Q[a] = null, S[a] = T[a] = R[a] = null, R[a + "_cache"] = null); + a && (R[a] = null, T[a] = U[a] = S[a] = null, S[a + "_cache"] = null); return this; }; -E.unregister = E.prototype.unregister = E.unload = E.prototype.unload; -var za = {tap:1, change:1, click:1, dblclick:1, input:1, keydown:1, keypress:1, keyup:1, mousedown:1, mouseenter:1, mouseleave:1, mousemove:1, mouseout:1, mouseover:1, mouseup:1, mousewheel:1, touchstart:1, touchmove:1, touchend:1, reset:1, select:1, submit:1, toggle:1, blur:1, error:1, focus:1, load:1, resize:1, scroll:1}, X, Aa = 0; -function Ba(a, b) { +F.unregister = F.prototype.unregister = F.unload = F.prototype.unload; +var ya = {tap:1, change:1, click:1, dblclick:1, input:1, keydown:1, keypress:1, keyup:1, mousedown:1, mouseenter:1, mouseleave:1, mousemove:1, mouseout:1, mouseover:1, mouseup:1, mousewheel:1, touchstart:1, touchmove:1, touchend:1, reset:1, select:1, submit:1, toggle:1, blur:1, error:1, focus:1, load:1, resize:1, scroll:1}, Y, za = 0; +function Aa(a, b) { var c = {}; if (!b) { - X = !0; + Y = !0; if ("string" === typeof a) { if (-1 !== a.indexOf("<")) { var d = document.createElement("div"); d.innerHTML = a; a = d.firstElementChild; - c.n = a.id || "tpl_" + Aa++; + c.n = a.id || "tpl_" + za++; } else { c.n = a, a = document.getElementById(a); } } else { - c.n = a.id || "tpl_" + Aa++; + c.n = a.id || "tpl_" + za++; } a.content ? a = a.content.firstElementChild : "TEMPLATE" === a.tagName && (a = a.firstElementChild); } if (d = a.tagName) { if ("INCLUDE" === d) { - return b = a.getAttribute("from"), c["+"] = b ? b : Y(a.firstChild.nodeValue), c; + return b = a.getAttribute("from"), c["+"] = b ? b : Ba(a.firstChild.nodeValue), c; } "DIV" !== d && (c.t = d.toLowerCase()); } else { @@ -1109,28 +1095,28 @@ function Ba(a, b) { if ("class" === g) { Z(c, "c", a.className); } else { - var h = a.getAttribute(g); - "style" === g ? Z(c, "s", h) : "if" === g ? Z(c, "f", h) : "include" === g ? a.hasAttribute("for") || (g = {}, (c.i || (c.i = [])).push(g), Z(g, "+", h)) : "for" === g && "LABEL" !== d ? ((g = a.getAttribute("include")) && (c["@"] = Y(g)), Z(c, "r", h)) : "max" === g ? Z(c, "m", h) : "js" === g ? c.j = Y(h) : "key" === g ? Z(c, "k", h.replace("data.", "")) : ("bind" === g && (h = h.split(":"), 2 > h.length && h.unshift("value"), g = h[0], h = "{{==" + h[1] + "}}"), za[g.substring(2)] && -1 !== - h.indexOf("{{") && (g = g.substring(2)), za[g] ? Z(c.e || (c.e = {}), g, h) : Z(c.a || (c.a = {}), g, h)); + var k = a.getAttribute(g); + "style" === g ? Z(c, "s", k) : "if" === g ? Z(c, "f", k) : "include" === g ? a.hasAttribute("for") || (g = {}, (c.i || (c.i = [])).push(g), Z(g, "+", k)) : "for" === g && "LABEL" !== d ? ((g = a.getAttribute("include")) && (c["@"] = Ba(g)), Z(c, "r", k)) : "max" === g ? Z(c, "m", k) : "js" === g ? c.j = Ba(k) : "key" === g ? Z(c, "k", k.replace("data.", "")) : ("bind" === g && (k = k.split(":"), 2 > k.length && k.unshift("value"), g = k[0], k = "{{==" + k[1] + "}}"), ya[g.substring(2)] && + -1 !== k.indexOf("{{") && (g = g.substring(2)), ya[g] ? Z(c.e || (c.e = {}), g, k) : Z(c.a || (c.a = {}), g, k)); } } } a = a.childNodes; if (d = a.length) { for (f = e = 0; f < d; f++) { - if (h = Ba(a[f], 1)) { - 1 === d && 3 === a[f].nodeType ? (h.j && (c.j = h.j), h.h && (c.h = h.h), h.x && (c.x = h.x)) : (c.i || (c.i = []))[e++] = h; + if (k = Aa(a[f], 1)) { + 1 === d && 3 === a[f].nodeType ? (k.j && (c.j = k.j), k.h && (c.h = k.h), k.x && (c.x = k.x)) : (c.i || (c.i = []))[e++] = k; } } 1 === e && (c.i = c.i[0]); } - b || (c.d = X); + b || (c.d = Y); return c; } function Z(a, b, c) { if (-1 !== c.indexOf("{{") && -1 !== c.indexOf("}}")) { var d = -1 !== c.indexOf("{{=="), e = d || -1 !== c.indexOf("{{="); - X = !1; + Y = !1; c = c.replace(/{{==/g, "{{").replace(/{{=/g, "{{").replace(/"{{/g, "").replace(/}}"/g, "").replace(/{{/g, "' + ").replace(/}}/g, " + '"); a[b] = [("'" + c + "'").replace(/'' \+ /g, "").replace(/ \+ ''/g, "")]; d ? a[b].push(2) : e && a[b].push(1); @@ -1138,73 +1124,73 @@ function Z(a, b, c) { a[b] = c; } } -function Y(a) { +function Ba(a) { return a.replace(/{{/g, "").replace(/}}/g, "").trim(); } -;E.compile = Ba; -E.array = N; -E.setText = function(a, b) { +;F.compile = Aa; +F.array = O; +F.setText = function(a, b) { b += ""; 3 !== a.nodeType && (a._html = null, a = a.firstChild || a.appendChild(document.createTextNode(a._text = b))); a._text !== b && (a.nodeValue = b, a._text = b); return this; }; -E.getText = function(a) { +F.getText = function(a) { if (3 !== a.nodeType && !(a = a.firstChild)) { return ""; } var b = a._text; return b || "" === b ? b : a._text = a.nodeValue; }; -E.setHTML = function(a, b) { +F.setHTML = function(a, b) { b += ""; a._html !== b && (a.innerHTML = b, a._html = b); return this; }; -E.getHTML = function(a) { +F.getHTML = function(a) { var b = a._html; return b || "" === b ? b : a._html = a.innerHTML; }; -E.setClass = function(a, b) { +F.setClass = function(a, b) { a._class !== b && (a.className = b, a._class = b); return this; }; -E.getClass = function(a) { +F.getClass = function(a) { var b = a._class; return b || "" === b ? b : a._class = a.className; }; -E.hasClass = I; -E.toggleClass = function(a, b) { - I(a, b) ? ka(a, b) : ja(a, b); +F.hasClass = J; +F.toggleClass = function(a, b) { + J(a, b) ? ja(a, b) : ia(a, b); return this; }; -E.removeClass = ka; -E.addClass = ja; -E.setCSS = function(a, b) { +F.removeClass = ja; +F.addClass = ia; +F.setCSS = function(a, b) { a._css !== b && ((a._style || (a._style = a.style)).cssText = b, a._css = b); return this; }; -E.getCSS = function(a) { +F.getCSS = function(a) { var b = a._css; return b || "" === b ? b : a._css = a.getAttribute("style"); }; -E.setAttribute = function(a, b, c) { +F.setAttribute = function(a, b, c) { var d = a._attr || (a._attr = {}); d[b] !== c && (a.setAttribute(b, c), d[b] = c); return this; }; -E.getAttribute = la; -E.hasAttribute = function(a, b) { - a = la(a, b); +F.getAttribute = ka; +F.hasAttribute = function(a, b) { + a = ka(a, b); return !!a || "" === a; }; -E.removeAttribute = function(a, b) { +F.removeAttribute = function(a, b) { var c = a._attr || (a._attr = {}); null !== c[b] && (a.removeAttribute(b), c[b] = null); return this; }; (function() { - var a = E, b = this || window, c; + var a = F, b = this || window, c; (c = b.define) && c.amd ? c([], function() { return a; }) : (c = b.modules) ? c.mikado = a : "object" === typeof b.exports ? b.module.exports = a : b.Mikado = a; diff --git a/test/test.js b/test/test.js index fde826f..8c24cb4 100644 --- a/test/test.js +++ b/test/test.js @@ -237,15 +237,15 @@ validate(root_1.children[0], items[0]); }); - it("Should have been indexed properly", function(){ - - mikado = new Mikado(root_1, "template"); - - mikado.render(data); - - expect(mikado.dom[0]["_idx"]).to.equal(0); - expect(mikado.dom[data.length - 1]["_idx"]).to.equal(data.length - 1); - }); + // it("Should have been indexed properly", function(){ + // + // mikado = new Mikado(root_1, "template"); + // + // mikado.render(data); + // + // expect(mikado.dom[0]["_idx"]).to.equal(0); + // expect(mikado.dom[data.length - 1]["_idx"]).to.equal(data.length - 1); + // }); it("Should have been re-mounted properly", function(){ @@ -261,7 +261,7 @@ mikado.mount(root_1); expect(mikado.dom).to.equal(root_1._dom); - expect(mikado.dom[0]["_idx"]).to.equal(0); + //expect(mikado.dom[0]["_idx"]).to.equal(0); expect(mikado.dom[0].dataset.id).to.equal(data[0]["id"]); validate(mikado.dom[0], data[0]); @@ -269,14 +269,14 @@ expect(mikado.root).to.equal(root_2); expect(mikado.dom).to.equal(root_2._dom); - expect(mikado.dom[0]["_idx"]).to.equal(0); + //expect(mikado.dom[0]["_idx"]).to.equal(0); expect(mikado.dom[0].dataset.id).to.equal(data[10]["id"]); validate(mikado.dom[0], data[10]); mikado.mount(root_1); expect(mikado.dom).to.equal(root_1._dom); - expect(mikado.dom[0]["_idx"]).to.equal(0); + //expect(mikado.dom[0]["_idx"]).to.equal(0); expect(mikado.dom[0].dataset.id).to.equal(data[0]["id"]); validate(mikado.dom[0], data[0]); }); @@ -392,7 +392,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); validate(mikado.dom[i], items[i]); } @@ -406,7 +406,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); validate(mikado.dom[i], items[i]); } }); @@ -420,7 +420,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); validate(mikado.dom[i], items[i]); } @@ -434,7 +434,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); validate(mikado.dom[i], items[i]); } }); @@ -452,7 +452,7 @@ for(var i = 0; i < items.length; i++){ mikado.dom[i]._test = items[i].id; - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.dom[i]["_data"]).to.equal(items[i]); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); @@ -470,7 +470,7 @@ for(var i = 0; i < items.length; i++){ if(mikado.dom[i]._test) expect(mikado.dom[i]._test).to.equal(items[i].id); - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.dom[i]["_data"]).to.equal(items[i]); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); @@ -488,7 +488,7 @@ for(var i = 0; i < items.length; i++){ mikado.dom[i]._test = items[i].id; - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); expect(mikado.store[i]).to.equal(items[i]); @@ -506,7 +506,7 @@ for(var i = 0; i < items.length; i++){ if(mikado.dom[i]._test) expect(mikado.dom[i]._test).to.equal(items[i].id); - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); expect(mikado.store[i]).to.equal(items[i]); @@ -523,7 +523,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); validate(mikado.dom[i], items[i]); @@ -539,7 +539,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); validate(mikado.dom[i], items[i]); @@ -555,7 +555,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); validate(mikado.dom[i], items[i]); @@ -571,7 +571,7 @@ for(var i = 0; i < items.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); expect(mikado.dom[i]["_key"]).to.equal(items[i].id); expect(mikado.live[items[i].id]).to.equal(mikado.dom[i]); validate(mikado.dom[i], items[i]); @@ -1146,7 +1146,7 @@ for(var i = 0; i < mikado.length; i++){ - expect(mikado.dom[i]["_idx"]).to.equal(i); + //expect(mikado.dom[i]["_idx"]).to.equal(i); validate(mikado.dom[i], items[i]); } }); @@ -1394,8 +1394,8 @@ expect(root_1.children[9]).to.equal(tmp_a); expect(root_1.children[10]).to.equal(mikado.dom[10]); expect(root_1.children[9]).to.equal(mikado.dom[9]); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[9]["_idx"]).to.equal(9); + //expect(mikado.dom[10]["_idx"]).to.equal(10); + //expect(mikado.dom[9]["_idx"]).to.equal(9); tmp_a = root_1.children[10]; tmp_b = root_1.children[9]; @@ -1426,10 +1426,10 @@ expect(root_1.children[6]).to.equal(tmp_b); expect(root_1.children[10]).to.equal(tmp_c); - expect(mikado.dom[5]["_idx"]).to.equal(5); - expect(mikado.dom[6]["_idx"]).to.equal(6); - expect(mikado.dom[7]["_idx"]).to.equal(7); - expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[5]["_idx"]).to.equal(5); + // expect(mikado.dom[6]["_idx"]).to.equal(6); + // expect(mikado.dom[7]["_idx"]).to.equal(7); + // expect(mikado.dom[10]["_idx"]).to.equal(10); expect(root_1.children[5]).to.equal(mikado.dom[5]); expect(root_1.children[6]).to.equal(mikado.dom[6]); @@ -1452,10 +1452,10 @@ expect(root_1.children[1]).to.equal(tmp_b); expect(root_1.children[2]).to.equal(tmp_c); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[9]["_idx"]).to.equal(9); - expect(mikado.dom[1]["_idx"]).to.equal(1); - expect(mikado.dom[0]["_idx"]).to.equal(0); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[9]["_idx"]).to.equal(9); + // expect(mikado.dom[1]["_idx"]).to.equal(1); + // expect(mikado.dom[0]["_idx"]).to.equal(0); expect(root_1.children[10]).to.equal(mikado.dom[10]); expect(root_1.children[9]).to.equal(mikado.dom[9]); @@ -1477,8 +1477,8 @@ expect(root_1.children[11]).to.equal(tmp_a); expect(root_1.children[10]).to.equal(mikado.dom[10]); expect(root_1.children[11]).to.equal(mikado.dom[11]); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); tmp_a = root_1.children[10]; tmp_b = root_1.children[11]; @@ -1509,10 +1509,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[14]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]); @@ -1536,10 +1536,10 @@ expect(root_1.children[length - 2]).to.equal(tmp_b); expect(root_1.children[10]).to.equal(tmp_c); - expect(mikado.dom[length - 1]["_idx"]).to.equal(length - 1); - expect(mikado.dom[length - 2]["_idx"]).to.equal(length - 2); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[length - 1]["_idx"]).to.equal(length - 1); + // expect(mikado.dom[length - 2]["_idx"]).to.equal(length - 2); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[length - 1]).to.equal(mikado.dom[length - 1]); expect(root_1.children[length - 2]).to.equal(mikado.dom[length - 2]); @@ -1563,10 +1563,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[14]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]); @@ -1596,10 +1596,10 @@ expect(root_1.children[6]).to.equal(tmp_b); expect(root_1.children[10]).to.equal(tmp_c); - expect(mikado.dom[5]["_idx"]).to.equal(5); - expect(mikado.dom[6]["_idx"]).to.equal(6); - expect(mikado.dom[7]["_idx"]).to.equal(7); - expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[5]["_idx"]).to.equal(5); + // expect(mikado.dom[6]["_idx"]).to.equal(6); + // expect(mikado.dom[7]["_idx"]).to.equal(7); + // expect(mikado.dom[10]["_idx"]).to.equal(10); expect(root_1.children[5]).to.equal(mikado.dom[5]); expect(root_1.children[6]).to.equal(mikado.dom[6]); @@ -1626,8 +1626,8 @@ expect(mikado.dom[10]).to.equal(tmp_b); expect(mikado.dom[11]).to.equal(tmp_a); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); }); it("Should have been used 'move' properly (down)", function(){ @@ -1646,10 +1646,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[14]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]); @@ -1682,10 +1682,10 @@ expect(root_1.children[6]).to.equal(tmp_b); expect(root_1.children[10]).to.equal(tmp_c); - expect(mikado.dom[5]["_idx"]).to.equal(5); - expect(mikado.dom[6]["_idx"]).to.equal(6); - expect(mikado.dom[7]["_idx"]).to.equal(7); - expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[5]["_idx"]).to.equal(5); + // expect(mikado.dom[6]["_idx"]).to.equal(6); + // expect(mikado.dom[7]["_idx"]).to.equal(7); + // expect(mikado.dom[10]["_idx"]).to.equal(10); expect(root_1.children[5]).to.equal(mikado.dom[5]); expect(root_1.children[6]).to.equal(mikado.dom[6]); @@ -1734,10 +1734,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[14]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]); @@ -1795,10 +1795,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[14]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]); @@ -1856,10 +1856,10 @@ expect(root_1.children[10]).to.equal(tmp_b); expect(root_1.children[11]).to.equal(tmp_c); - expect(mikado.dom[15]["_idx"]).to.equal(15); - expect(mikado.dom[14]["_idx"]).to.equal(14); - expect(mikado.dom[10]["_idx"]).to.equal(10); - expect(mikado.dom[11]["_idx"]).to.equal(11); + // expect(mikado.dom[15]["_idx"]).to.equal(15); + // expect(mikado.dom[14]["_idx"]).to.equal(14); + // expect(mikado.dom[10]["_idx"]).to.equal(10); + // expect(mikado.dom[11]["_idx"]).to.equal(11); expect(root_1.children[15]).to.equal(mikado.dom[15]); expect(root_1.children[14]).to.equal(mikado.dom[14]);