-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
528 lines (505 loc) · 27.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Even3MindMap</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!--link rel="shortcut icon" href="favicon.ico"/-->
</head>
<body>
<style>
#wrapper{text-align: center; position: absolute; width:100%}
#statusbar{
position:relative; z-index: 2; top:0px; height:20px;
color:rgba(255,255,255,.33);
-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none;
}
.prop{width:48%;float:left;background: #444;}
.val{width:48%;float:right;background: #444;border: 1px solid #666; margin-top: 2px;}
.line{height:25px;}
#box{
display:none;
position:relative; z-index: 10; top:0px; width:330px; height:80px; margin: auto; padding: 5px;
background: #444; border: 1px solid #666; box-shadow: 0px 0px 8px}
#cnv{position:relative; top:0px; background: #444; text-rendering: optimizeSpeed; image-rendering: optimizeSpeed}
body{background: #303030; text-align: center; margin: 0px;overflow: hidden}
</style>
<div id=wrapper>
<div id=statusbar><small>наведите мышь на пункт, что бы просмотреть его описание</small></div>
<div id=box>
<div class=line><span class=prop>Дочернее имя:</span> <input class=val id=child type=text></input></div>
<div class=line><span class=prop>Имя элемента:</span> <input class=val id=node type=text></input></div>
</div>
</div>
<canvas id=cnv></canvas>
<!--script src='mmap.json'></script-->
<script>var iddb = (function(dbName, ver){
ver = ver || 7;
var name = 'root';
var OPT = 0, DEF = 1, storstr = ["opt", "def"];
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
var db = indexedDB.open(dbName, ver);
var obj, kid;
db.onupgradeneeded = function(e){//storstr.forEach(function(v){ e.currentTarget.result.createObjectStore(v, {keyPath:"id", autoIncrement: true}) });
var db = e.currentTarget.result
var stor = [db.createObjectStore(storstr[OPT], {keyPath:"id", autoIncrement: true}),
db.createObjectStore(storstr[DEF], {keyPath:"id", autoIncrement: false})];
stor[OPT].createIndex('parent', 'parent', { unique: false });
stor[OPT].add({cap: name, parent: name}).onsuccess = function(e){
stor[DEF].add({id : e.target.result});
}
//saveDB(json, stor); onJsonLoaded(json)
}
function saveDB(node, stor, parentId){
node[0].parent = parentId || name;
var opt2db = {}, def2db = {};
for(var k in node[0])
if (k == 'default') for(var j in node[0].default) def2db[j] = node[0].default[j];
else opt2db[k] = node[0][k];
stor[OPT].add( opt2db ).onsuccess = function(e){
def2db.id = opt2db.id = node[0].id = e.target.result;
stor[DEF].add( def2db );
for(var n = node.length; --n ;) saveDB(node[n], node[0].id);
};
}
db.onsuccess = function(){
var transaction = this.result.transaction(storstr, "readwrite"),
stor = storstr.map(function(v, i){ return transaction.objectStore(v) });
//saveDB(json, stor); onJsonLoaded(json); //импортировать json в базу данных и запустить mindmap
loadDB();
function loadDB(){
obj = [];
stor[OPT].openCursor().onsuccess = function(e) {
var cur = e.target.result;
if (cur) {
obj[cur.value.id] = [cur.value];
cur.continue();
} else {
stor[DEF].openCursor().onsuccess = function(e) {
var cur = e.target.result;
if (!cur) return done();
var id = cur.value.id;
delete cur.value.id;
obj[id][0].default = cur.value;
cur.continue();
};
}
};
function done(){
var root;
obj.forEach(function(v, i){
if( v[0].parent == name ) return root = i;
obj[v[0].parent].push(v);
})
console.log(name, root);
console.log('obj', obj);
onJsonLoaded(obj[root]); //TODO: async auto detect modification api
}
};
};
return {
add : function(node, parent){
var opt2db = {}, def2db = {};
for(var k in node[0])
if (k == 'default') for(var j in node[0].default) def2db[j] = node[0].default[j];
else if (k == 'parent' && node[0].parent[0]) opt2db.parent = node[0].parent[0].id;
else if (k != 'id') opt2db[k] = node[0][k];
if(parent) opt2db.parent = parent[0].id;
indexedDB.open(dbName, ver).onsuccess = function(){
var transaction = this.result.transaction(storstr, "readwrite"),
stor = storstr.map(function(v, i){ return transaction.objectStore(v) });
stor[OPT].add( opt2db ).onsuccess = function(e){
node[0].id = e.target.result;
def2db.id = node[0].id;
stor[DEF].add( def2db );
}
}
},
del : function(node){
var id = node[0].id;
console.log('IDDB.DEL',node);
indexedDB.open(dbName, ver).onsuccess = function(){
var transaction = this.result.transaction(storstr, "readwrite"),
stor = storstr.map(function(v, i){ return transaction.objectStore(v) });
(function delKid(id){
stor[OPT].index("parent").openCursor(IDBKeyRange.only(id)).onsuccess = function(e) {
var cur = e.target.result;
if(!cur) return;
delKid(cur.primaryKey);
stor[OPT].delete(cur.primaryKey);
stor[DEF].delete(cur.primaryKey);
cur.continue();
}
})(id);
stor[OPT].delete(id);
stor[DEF].delete(id);
}
},
mov : function(node, parent){
var opt2db = {}, def2db = {id : node[0].id};
for(var k in node[0])
if (k == 'default') for(var j in node[0].default) def2db[j] = node[0].default[j];
else if (k == 'parent' && node[0].parent[0]) opt2db.parent = node[0].parent[0].id;
else if (k == 'parent' && node[0][k] === false) opt2db.parent = name; //fix root map name (hothix)
else if (k != 'mark') opt2db[k] = node[0][k];
if(parent) opt2db.parent = parent[0].id;
console.log('IDDB.MOV','opt2db', opt2db, 'def2db', def2db);
indexedDB.open(dbName, ver).onsuccess = function(){
var transaction = this.result.transaction(storstr, "readwrite"),
stor = storstr.map(function(v, i){ return transaction.objectStore(v) });
stor[OPT].put( opt2db )
stor[DEF].put( def2db );
}
}
};
})("test");</script>
<script>'use strict';
var MindMap = function (map, ids, px, angle, x0, y0) {
//TODO: опцилональное автоскрытие одиночной цепи
var lastId = 0;
console.log('map', map);
(function setParent(node, parent) {
node[0].parent = parent || false;
//if(!node[0].id) node[0].id = lastId++; //autoIncrementID
console.log(node[0].cap, 'child of', parent && parent[0].cap || 'none');
for (var n = node.length; --n;) setParent(node[n], node);
})(map);
var ctx = ids.canvas.getContext('2d');
ctx.imageSmoothingEnabled=ctx.webkitImageSmoothingEnabled=ctx.mozImageSmoothingEnabled=ctx.oImageSmoothingEnabled=false;
px = px || 20;
angle = angle || Math.PI*2;
x0 = x0 || ids.canvas.width / 2; y0 = y0 || ids.canvas.height /2
ctx.translate(x0, y0);
ids.node.onkeydown = function(e){ //изменение названия пункта
if((e || window.event).keyCode^13)return;
targets[0][0].cap = this.value;
iddb.mov(targets[0]);
ids.box.style.display = 'none';
ctx.sel.one();
}
ids.child.onkeydown = function(e){ //добавление потомка
if((e||window.event).keyCode^13)return;
if(!this.value)return ctx.sel.one()||ctx.sel.opt(); //при пустом вводе отмена ввода
var node = [{cap:this.value, parent:targets[0]}] //создание пункта
iddb.add(node);
targets[0].push( node );
this.value='';
}
ctx.scroll = function(dx, dy){
x0 += dx; y0 += dy; //var matrix = ctx.currentTransform //matrix.e matrix.f;
//http://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/currentTransform
ctx.translate(dx, dy);
}
ctx.pick = function(x, y, a, r, node, rotate, sector, radiusA){
r = r || Math.hypot(y - y0, x - x0);
radiusA = radiusA || 20; //TODO: const root offset
node = node || map;
if(r < 20) return map; //TODO: global mmap root path
a = a || Math.atan2(y - y0, x - x0);
rotate = rotate || (typeof node[0].a === 'number' ? node[0].a : Math.PI); //TODO: global mmap rotate;
sector = sector || angle;
var n = node.length - 1,
step = sector / n,
find = ((((a - rotate) % (Math.PI*2)) + Math.PI*2) % (Math.PI*2)) / step | 0;
ctx.save();
for(var m in node[0].default) ctx[m] = node[0].default[m]; //local styles
var w = ctx.measureText(node[0].cap).width + margin*2,
radA = Math.max(radiusA, parseInt(ctx.font.split(' ')[0].replace('px', '')) / Math.sin(Math.min(sector, Math.PI/3))) + w;
if(node === map) radA = 20; //TODO: global root offset
ctx.restore();
if (radA > r) return node;
if (node.length > 1) return ctx.pick(x, y, a, r, node[find+1], rotate + step * find, step, radA);
return false;
}
ctx.textBaseline = 'middle';
ctx.textAlign = "center";
ctx.lineWidth = .5;
var style = {default:{fillStyle: 'rgba(0,0,0,0)'}, select: {strokeStyle: '#6af', fillStyle: '#2f3437'}}
var margin = px / 8;
ctx.clear = function(){
ctx.clearRect(-x0, -y0, cnv.width, cnv.height);
}
ctx.draw = function(node, a, da, r, lim){
node = node || map;
da = (da || node[0].da) || (Math.PI*2);
r = r || node[0].r || 0;
lim = lim || 9;
if(typeof a === 'undefined') a = typeof node[0].a === 'number' ? node[0].a : Math.PI;
var name = node[0].cap || 'noname',
sector = da / (node.length - 1),
radA;
ctx.save();
for(var m in node[0].default) ctx[m] = node[0].default[m]; //local styles
var w = ctx.measureText(name).width + margin*2;
radA = Math.max(r, parseInt(ctx.font.split(' ')[0].replace('px', '')) / Math.sin(Math.min(da, Math.PI/3))) + w;
ctx.save();
if(node[0].mark) for(var m in style.select) ctx[m] = style.select[m]; //if selected node set style
else for(var m in style.default) ctx[m] = style.default[m];
if(node === map) radA = 20; //СВЕРТКА пути! //TODO: опциональность
//if(da === Math.PI*2) radA = 20; //СВЕРТКА пути! //TODO: опциональность
ctx.beginPath();
if(r)ctx.arc(0, 0, r , a, a+da);
ctx.arc(0, 0, radA - margin, a+da, a, true);
ctx.closePath();
ctx.fill();
ctx.stroke();
//ctx.rotate(a); ctx.strokeRect(radA - margin - 9,3,6,6); //TODO: sector sort button?
ctx.restore();
//if(da !== Math.PI*2){ //СВЕРТКА пути! //TODO: опциональность
ctx.rotate(a+da/2); //TODO: one transform // +da/2 cos vertical centred
ctx.translate(radA - w/2 - margin, 0);
if(Math.cos(a+da/2) < 0) ctx.scale(-1,-1);
ctx.fillText(name, 0, 0);
//}
ctx.restore();
if(lim <= 0)return;
for(var k = 1; k < node.length; k++)
ctx.draw(node[k], a+sector * (k-1), sector, radA, lim - 1);
}
var targets = [],
way = map;
ctx.sel = {
get css(){return style.select}, //получить стиль выделенного пункта
/** открыть карту с уровня пункта */
way : function(node){},
/** открыть окно опций для переданного пункта */
opt : function(node){
if(!node){
if(ids.box.style.display !== 'none'){
ids.box.style.display = 'none';
ctx.sel.one();
}
return
}
ctx.sel.one(node);
ids.child.select();
ids.box.style.display = 'block';
ids.node.value = node[0].cap || 'none';
ids.child.focus();
},
/** добавить пункт в карту */
add : function(node){
},
/** удалить пункт из карты */
del : function(node,dbKeep){ //удаляет пункт
if(node === map)return; //нельзя удалить корневой пункт
if(!dbKeep) iddb.del(node) //удалить из базы
var parent = node[0].parent,
idx = parent.indexOf(node);
console.log('DELETE', node[0].cap + ' ' + idx, 'child of', parent && parent[0].cap || 'none');
ctx.sel.pop(node);
parent.splice(idx, 1);
//console.log(map);
},
kin : function(node){
return !node||(typeof node[0].parent != 'object')? []: ctx.sel.kin(node[0].parent).concat([node]);
},
/** переместить выбранное в сообщенный пункт */
mov : function(node,force){
// исключить node и корень из target
if(~targets.indexOf(map)) ctx.sel.pop(map); //перетаскивание корня! //TODO: можно перегрузить на выход вверх
//if(node===undefined)
if(~targets.indexOf(node)) ctx.sel.pop(node); //перетаскивание на себя! //TODO: можно перегрузить (продолжить режим перемещения)
console.log('kin(node) = ',ctx.sel.kin(node).reduce( function(p,c){return p+c[0].cap+'/'}, '/' ) );
// если хоть один из target является родителем хоть одного другого или node
console.log('can move items, by kins filtred:',
targets.filter(function(T){
var nKins = ctx.sel.kin(node); //вседрево родителей node и сам node
var tKins = ctx.sel.kin(T);
return nKins.some(function(n){
n[0].parent==T&&console.log(n[0].cap,T[0].cap);
return n[0].parent==T;
}) || targets.some(function(b){
return tKins.some(function(t){
t[0].parent==b&&console.log(t[0].cap,b[0].cap);
return t[0].parent==b});
})
}).map(function(v){ctx.sel.pop(v); return v[0].cap})
);
//return;
// открыть окно подробностей
// иначе
// переместить сразу
//force - true для выполнения без проверок
//TODO: remove iddb
//if(!node); //перетаскивание в пустоту (можно перегрузить для корня)
/*
if(!force){
var kins = ctx.sel.fit(node);
if(kins>1) return 'alert'//ids.msg.style.display = 'block';
if(kins==false) node[0].parent = targets[0][0].parent;
if(kins>1) node[0].parent = targets[0][0].parent;
}*/
for(var t; t = targets[targets.length-1];){
ctx.sel.del(t, node);
if (node) {
node.push(t);
iddb.mov(t, node);
t[0].parent = node; //защита пункта от удаления из базы (пункт без родителя считается корневым и не может быть удален)
}
}
},
/** получить список выбранных на данный момент пунктов */
get : function(){return targets},
/** выбор только переданного пункта или снятие всего выбора, если не передан */
one : function(node){
//console.log('before',targets); //DEBUG:
for(var n = targets.length; n--;) ctx.sel.pop(targets[n]);
if(node) ctx.sel.set(node);
//console.log('after',targets); //DEBUG:
},
/** добавить переданный пункт к выбранным */
set : function(node){ //добавляет пункт к выбранным
if(!node)return;
if(node[0].mark) return; //if already keep return
node[0].mark = 1;
targets.push(node);
//ctx.draw(node); //TODO: out from API ?
},
/** убрать переданный пункт из выбора */
pop : function(node){ //убирает пункт из выбранных (если он выбран) //TODO: nodes[] support
if(!node)return;
if(!node[0].mark)return; //if already free return
node[0].mark = 0; //TODO: multiuser(color) select can be add here if check bits
var idx = targets.indexOf(node);
if(!~idx)console.log('error drop target', idx, node, 'from', targets);//DEBUG: check targets work
targets.splice(idx, 1);
},
/** инвертировать выбор на переданном пункте */
xor : function(node){
//console.log('before',targets); //DEBUG:
if(!node)return;
if(node[0].mark) ctx.sel.pop(node); else ctx.sel.set(node);
//console.log('after',targets); //DEBUG:
}
}
return ctx;
}</script>
<script>"use strict";
//TRY: reject by Object.defineProperty() events external reset
//TODO: циклические ссылки в цепях
//TRY: multi-item Even3 optimization //!!! see event.target!
//TODO: extension event types
//FIX: alias from touch to mouse - reject multitouch
function Even3(ext){
var tree = [{root:function(){throw Error("impossible mistake: Can't run root node")}}],
self, state = tree, sub = {type:'wait'};
self = function(e){
e = e || window.event || {};
e.preventDefault && e.preventDefault(); //для отмены действий поумолчанию
e.returnValue = false;
for(var n in ext)
if((new RegExp(n)).test(e.type)){
var evt = ext[n](e);
//console.log('touch evt convert to ->',evt.type);
route(evt||{type:'wait'});
return;
}
route(e || {type:'wait'});
}
var route = function(e){
sub.event = sub.event || e;
//sub.event.timeStamp = sub.event.timeStamp || (window.performance && window.performance.now());
sub.X = e.pageX; sub.Y = e.pageY;
sub.now = e.timeStamp || (window.performance && window.performance.now());
sub.time = sub.time || sub.now;
sub.dT = (sub.now - sub.event.timeStamp) || 0;
sub.dx = (sub.X - sub.x) || 0; sub.dy = (sub.Y - sub.y) || 0;
sub.dX = (sub.X - sub.event.pageX) || 0; sub.dY = (sub.Y - sub.event.pageY) || 0;
while(true){
sub.dt = (sub.now - sub.time) || 0;
for(var buf = [], key, obj, n = 1; obj = state[n] && state[n][0]; n++)
if('wait' == (key = Object.keys(obj)[0])){
var newsub = obj[key](e, sub);
if(newsub === true) continue;
if(newsub === false || newsub === undefined) {state = tree; break;} //событие обрывает цепочку
if(newsub >= 0) continue;
buf.push({delay: newsub - Math.random(), state: state[n]});
}
if(!buf.length) break;
var erlyest = buf.reduce(function(a, b){return (a.delay < b.delay) ? a : b});
state = erlyest.state;
sub.time += erlyest.delay; //|| sub.now;
if(state.length <= 1) state = tree; //тупиковая цепочка, возвращаем состояние на корень Even3
}
if(state.length <= 1) state = tree; //тупиковая цепочка, возвращаем состояние на корень Even3
for(var key, obj, n = 1; obj = state[n] && state[n][0]; n++){
var regex = new RegExp(key = Object.keys(obj)[0]);
if(regex.test(e.type)){
var newsub = obj[key](e, sub);
sub.time = sub.now; //дублируем метку времени события
sub.x = sub.X; sub.y = sub.Y;
if(newsub === true) continue; //событие ожидает других условий
if(newsub === false) { state = tree; return false}; //событие обрывает цепочку
sub.event = e; //сохраняем информацию о выполненном событии
//TODO: событие может вернуть объект newsub... сделаем управляемый переход для граффовой структуры цепочек?
state = state[n];
return false;
}
}
}
self.set = function(){for(var n = 0; n < arguments.length; n++) tree.push(arguments[n]);return self};
self.add = function(eitem){for(var key in eitem)key.split('|').forEach((e)=>{eitem[key].addEventListener(e, self)});return self};
return self;
}</script>
<script>
"use strict";
//var size = Math.min(innerWidth, innerHeight); cnv.width = size; cnv.height = size;
function onJsonLoaded(json){
cnv.width = innerWidth; cnv.height = innerHeight;
var mmap = MindMap(json, {
canvas:cnv,box:document.getElementById('box'),node:document.getElementById('node'),child:document.getElementById('child')
});
mmap.font = '900 18px sans-serif';
mmap.fillStyle = '#000'; mmap.strokeStyle = '#666';
var debugtime = (new Date()).getTime();
document.title = 'карта построена за '+ ((new Date()).getTime() - debugtime)+'ms';
go();
function go(){
mmap.clear();
mmap.draw();
window.requestAnimationFrame(go);
//setTimeout(go,500);
//json[0].a+=.003;
}
var item = document.getElementById('cnv');
setInterval(Even3({'touchstart|touchmove|touchend':(e)=>{
var t = e.changedTouches&&(e.touches.length==(e.type!='touchend'))&&e.changedTouches[0];
t.type = e.type; t.timeStamp = e.timeStamp; return t;
}})
.add({'mouseup|mousemove|mousedown|touchstart|touchmove|touchend':item})
.set(
[{'mousemove': function(e,sub){
console.log('Hover');
var item = mmap.pick(sub.X - cnv.offsetLeft, sub.Y - cnv.offsetTop)
document.getElementById('statusbar').innerHTML = item ?
'<b><big>"' + item[0].cap + '":</big></b> ' + (item[0].alt || 'no tip') :
'<small>наведите мышь на пункт, что бы просмотреть его описание</small>';
}}],
[{'mousedown|touchstart': function(e,sub){console.log('Down');mmap.sel.opt(); mmap.sel.xor(mmap.pick(sub.X -cnv.offsetLeft, sub.Y -cnv.offsetTop))}},
[{'wait': function(e, sub){console.log('Hold...', sub.dT);if(sub.dT < 700) return true; mmap.sel.set(mmap.pick(sub.x -cnv.offsetLeft, sub.y -cnv.offsetTop)); mmap.sel.css.strokeStyle='#fa6';return-1;}},
[{'mousemove|touchmove': function(e, sub){console.log('H-Drag'); return true;}}],
[{'mouseup|touchend': function(e, sub){
console.log('H-Drop'); mmap.sel.mov(mmap.pick(sub.X -cnv.offsetLeft, sub.Y -cnv.offsetTop));mmap.sel.css.strokeStyle='#6af';return false;}}
]
],
[{wait: function(e, sub){
return(Math.hypot(sub.dX, sub.dY) < 8||mmap.sel.xor(mmap.pick(sub.x -cnv.offsetLeft, sub.y -cnv.offsetTop)) )-1;}},
[{'mousemove|touchmove': function(e, sub){console.log('Drag'); mmap.scroll(sub.dx, sub.dy); return true;}}],
[{'mouseup|touchend': function(){console.log('Drop')}}]
],
[{'mouseup|touchend': function(e){console.log('Click');}},
[{'wait': function(e, sub){return ((Math.hypot(sub.dX, sub.dY) < 8) && (sub.dT < 300))||console.log('Dbl break by time/drag');}}],
[{'mousedown|touchstart': function(e,sub){console.log('DblDown');mmap.sel.set(mmap.pick(sub.X -cnv.offsetLeft, sub.Y -cnv.offsetTop))}},
[{'mouseup|touchend': function(e, sub){console.log('DblClick');mmap.sel.opt(mmap.pick(sub.x -cnv.offsetLeft, sub.y -cnv.offsetTop));}}],
[{'wait': function(e, sub){
console.log('DblHold...', sub.dT); if(sub.dT < 200) return true; console.log('DblHold'); mmap.sel.one(false);}}
]
]
]
]
), 50);
}
</script>
</body>
</html>