aim
Advanced tools
Comparing version 0.0.10 to 0.0.12-de0edcc9ebea9474d776a9f52aa8e30cfe6316d5
@@ -15,2 +15,3 @@ const $1906921049_autoFocus = (aim, set) => { | ||
aim.currentFocusAttempt = target | ||
if (!('onFocus' in target) || target.onFocus(target) !== false) { | ||
@@ -32,4 +33,4 @@ const blurTarget = aim.currentFocus | ||
let parent = current | ||
let x = current.xMid | ||
let y = current.yMid | ||
let x = current.x + (current.xEnd - current.x) / 2 | ||
let y = current.y + (current.yEnd - current.y) / 2 | ||
let xOffset = 0 | ||
@@ -62,5 +63,13 @@ let yOffset = 0 | ||
next = children[i] | ||
const a = x - next.xMid - xOffset | ||
const b = y - next.yMid - yOffset | ||
// optimize this! | ||
const a = Math.min( | ||
Math.abs(x - next.x - xOffset), | ||
Math.abs(x - next.xEnd - xOffset) | ||
) | ||
const b = Math.min( | ||
Math.abs(y - next.y - yOffset), | ||
Math.abs(y - next.yEnd - yOffset) | ||
) | ||
const c = Math.sqrt(a * a + b * b) | ||
if (diff === void 0 || c < diff) { | ||
@@ -135,6 +144,8 @@ if (top || bottom) { | ||
child.y = parent.y | ||
child.xEnd = parent.xEnd | ||
child.yEnd = child.y | ||
if (index) { | ||
for (let i = index - 1; i >= 0; i--) { | ||
if (i in parent.children) { | ||
child.y = parent.children[i].yEnd | ||
child.y = parent.children[i].yEnd + 1 | ||
break | ||
@@ -144,4 +155,8 @@ } | ||
} | ||
child.xEnd = parent.xEnd | ||
child.yEnd = child.y | ||
for (let i = 0, l = parent.children.length; i < l; i++) { | ||
if (i in parent.children) { | ||
child.yEnd = parent.children[i].y - 1 | ||
break | ||
} | ||
} | ||
} else { | ||
@@ -151,6 +166,8 @@ child.direction = 'y' | ||
child.x = parent.x | ||
child.yEnd = parent.yEnd | ||
child.xEnd = child.x | ||
if (index) { | ||
for (let i = index - 1; i >= 0; i--) { | ||
if (i in parent.children) { | ||
child.x = parent.children[i].xEnd | ||
child.x = parent.children[i].xEnd + 1 | ||
break | ||
@@ -160,4 +177,8 @@ } | ||
} | ||
child.yEnd = parent.yEnd | ||
child.xEnd = child.x | ||
for (let i = 0, l = parent.children.length; i < l; i++) { | ||
if (i in parent.children) { | ||
child.xEnd = parent.children[i].x - 1 | ||
break | ||
} | ||
} | ||
} | ||
@@ -176,3 +197,3 @@ return (parent.children[index] = child) | ||
if (i in parent.children) { | ||
set.y = parent.children[i].yEnd | ||
set.y = parent.children[i].yEnd + 1 | ||
break | ||
@@ -185,3 +206,2 @@ } | ||
if (!('x' in set)) { | ||
set.x = parent.x | ||
@@ -191,3 +211,3 @@ if (index) { | ||
if (i in parent.children) { | ||
set.x = parent.children[i].xEnd | ||
set.x = parent.children[i].xEnd + 1 | ||
break | ||
@@ -198,9 +218,9 @@ } | ||
} | ||
if (!('y' in set)) set.y = parent.y | ||
if (!('y' in set)) { | ||
set.y = parent.y | ||
} | ||
} | ||
set.index = index | ||
set.xMid = set.x + (set.w || 1) / 2 | ||
set.xEnd = set.x + (set.w || 1) | ||
set.yMid = set.y + (set.h || 1) / 2 | ||
set.yEnd = set.y + (set.h || 1) | ||
set.xEnd = set.x + (set.w || 0) | ||
set.yEnd = set.y + (set.h || 0) | ||
set.parent = parent | ||
@@ -222,6 +242,7 @@ parent.children[index] = set | ||
child.xEnd += xDiff | ||
child.xMid = child.x - (child.xEnd - child.x) / 2 | ||
if ('children' in child) { | ||
for (var i = child.children.length - 1; i >= 0; i--) { | ||
if (i in child.children) $3174120555_updateX(child.children[i], xDiff) | ||
if (i in child.children) { | ||
$3174120555_updateX(child.children[i], xDiff) | ||
} | ||
} | ||
@@ -231,9 +252,10 @@ } | ||
const $3174120555_updateY = (child, xDiff) => { | ||
child.x += xDiff | ||
child.xEnd += xDiff | ||
child.xMid = child.x - (child.xEnd - child.x) / 2 | ||
const $3174120555_updateY = (child, yDiff) => { | ||
child.y += yDiff | ||
child.yEnd += yDiff | ||
if ('children' in child) { | ||
for (var i = child.children.length - 1; i >= 0; i--) { | ||
if (i in child.children) $3174120555_updateX(child.children[i], xDiff) | ||
if (i in child.children) { | ||
$3174120555_updateY(child.children[i], yDiff) | ||
} | ||
} | ||
@@ -245,3 +267,2 @@ } | ||
if (parent.xEnd < xEnd) { | ||
parent.xMid = parent.x + (xEnd - parent.x) / 2 | ||
if ('parent' in parent) { | ||
@@ -252,7 +273,3 @@ const siblings = parent.parent.children | ||
for (let i = l - 1; i >= 0; i--) { | ||
if (i in siblings) { | ||
const sibling = siblings[i] | ||
sibling.xEnd = xEnd | ||
sibling.xMid = parent.xMid | ||
} | ||
if (i in siblings) siblings[i].xEnd = xEnd | ||
} | ||
@@ -275,3 +292,2 @@ } else { | ||
if (parent.yEnd < yEnd) { | ||
parent.yMid = parent.y + (yEnd - parent.y) / 2 | ||
if ('parent' in parent) { | ||
@@ -283,5 +299,3 @@ const siblings = parent.parent.children | ||
if (i in siblings) { | ||
const sibling = siblings[i] | ||
sibling.yEnd = yEnd | ||
sibling.yMid = parent.yMid | ||
siblings[i].yEnd = yEnd | ||
} | ||
@@ -351,9 +365,7 @@ } | ||
if (parent.direction === 'y') { | ||
target.y = prevEnd || parent.y | ||
target.yMid = target.y + (target.h || 1) / 2 | ||
prevEnd = target.yEnd = target.y + (target.h || 1) | ||
target.y = prevEnd ? prevEnd + 1 : parent.y | ||
prevEnd = target.yEnd = target.y + (target.h || 0) | ||
} else { | ||
target.x = prevEnd || parent.x | ||
target.xMid = target.x + (target.w || 1) / 2 | ||
prevEnd = target.xEnd = target.x + (target.w || 1) | ||
target.x = prevEnd ? prevEnd + 1 : parent.x | ||
prevEnd = target.xEnd = target.x + (target.w || 0) | ||
} | ||
@@ -411,3 +423,9 @@ if (max === i) { | ||
39: $3174120555_events.right, | ||
40: $3174120555_events.down | ||
40: $3174120555_events.down, | ||
205: $3174120555_events.left, | ||
206: $3174120555_events.right, | ||
203: $3174120555_events.up, | ||
204: $3174120555_events.down, | ||
195: $3174120555_events.enter, | ||
196: $3174120555_events.back | ||
} | ||
@@ -418,6 +436,4 @@ | ||
x: 0, | ||
xMid: 0, | ||
xEnd: 0, | ||
y: 0, | ||
yMid: 0, | ||
yEnd: 0, | ||
@@ -436,3 +452,4 @@ children: [], | ||
handleKeyEvent (e) { | ||
if (e.keyCode in $3174120555_keys) { | ||
console.log('BAHHHH', e.keyCode) | ||
if (e.keyCode in $3174120555_keys && $3174120555_aim.currentFocus) { | ||
const event = $3174120555_keys[e.keyCode] | ||
@@ -474,25 +491,34 @@ if (event.name in $3174120555_aim.currentFocus) { | ||
var index = target.index | ||
var children = target.parent.children | ||
var parent = target.parent | ||
var children = parent.children | ||
var length | ||
if ($3174120555_aim.currentFocus === target) { | ||
$1906921049_changeFocus($3174120555_aim, 'x', -1) || $1906921049_changeFocus($3174120555_aim, 'y', -1) || | ||
$1906921049_changeFocus($3174120555_aim, 'x', 1) || $1906921049_changeFocus($3174120555_aim, 'y', 1) | ||
$3174120555_aim.currentFocus = false | ||
// changeFocus(aim, 'y', -1) || changeFocus(aim, 'x', -1) || | ||
// changeFocus(aim, 'y', 1) || changeFocus(aim, 'x', 1) | ||
} | ||
while ((length = children.length) === 1 && ('parent' in target)) { | ||
index = target.index | ||
target = target.parent | ||
children = target.children | ||
parent = target.parent | ||
children = parent.children | ||
target = parent | ||
} | ||
// why do we need this check??? | ||
if (index < length) { | ||
for (var i = index + 1; i < length; i++) { | ||
if (i in children) { | ||
children[children[i].index = i - 1] = children[i] | ||
} else { | ||
delete children[i - 1] | ||
} | ||
} | ||
if (index === length - 1) { | ||
children.pop() | ||
} else { | ||
delete children[index] | ||
} | ||
// // why do we need this check??? | ||
// if (index < length) { | ||
// for (var i = index + 1; i < length; i++) { | ||
// if (i in children) { | ||
// children[children[i].index = i - 1] = children[i] | ||
// } else { | ||
// delete children[i - 1] | ||
// } | ||
// } | ||
// children.pop() | ||
// } | ||
}, | ||
@@ -499,0 +525,0 @@ /* |
{ | ||
"name": "aim", | ||
"version": "0.0.10", | ||
"version": "0.0.12-de0edcc9ebea9474d776a9f52aa8e30cfe6316d5", | ||
"main": "dist/index.js", | ||
@@ -10,3 +10,5 @@ "description": "Dependency free focus manager with built-in universal key navigation.", | ||
"build": "builder-boy src/index.js dist/index.js -t node -r && npm run build-util", | ||
"build-util": "builder-boy src/util.js dist/util.js -t node -r" | ||
"build-util": "builder-boy src/util.js dist/util.js -t node -r", | ||
"version-commit": "npm --no-git-tag-version version $(node -pe \"require('./package.json').version.split('-')[0]\")-$(git log -n 1 --pretty=format:'%H')", | ||
"publish-branch": "npm run version-commit && npm publish --tag $(git rev-parse --abbrev-ref HEAD | sed 's/\\//-/g')" | ||
}, | ||
@@ -13,0 +15,0 @@ "files": [ |
19850
553