Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrsjng committed Apr 28, 2019
1 parent a05a11d commit d76b3c4
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
max-len: [0, 80, 4]
max-nested-callbacks: [1, 3]
max-params: [1, 5] ###
max-statements: [1, 32] ###
max-statements: [1, 48] ###
new-cap: 0
new-parens: 2
newline-after-var: 0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.nyc_output/
/build/
/coverage/
/local/
Expand Down
178 changes: 87 additions & 91 deletions dist/pagemap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! pagemap v1.1.0 - https://larsjung.de/pagemap/ */
/*! pagemap v1.2.0 - https://larsjung.de/pagemap/ */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -99,102 +99,100 @@ return /******/ (function(modules) { // webpackBootstrap
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(global) {var WIN = global.window;
var DOC = WIN.document;
var DOC_EL = DOC.documentElement;
var body = DOC.querySelector('body');
/* WEBPACK VAR INJECTION */(function(global) {module.exports = function (canvas, options) {
var WIN = global.window;
var DOC = WIN.document;
var DOC_EL = DOC.documentElement;
var BODY = DOC.querySelector('body');
var CTX = canvas.getContext('2d');

var black = function black(pc) {
return "rgba(0,0,0,".concat(pc / 100, ")");
};

var defaults = {
viewport: null,
styles: {
'header,footer,section,article': black(8),
'h1,a': black(10),
'h2,h3,h4': black(8)
},
back: black(2),
view: black(5),
drag: black(10),
interval: null
};

var _listener = function _listener(el, method, types, fn) {
return types.split(/\s+/).forEach(function (type) {
return el[method](type, fn);
});
};
var black = function black(pc) {
return "rgba(0,0,0,".concat(pc / 100, ")");
};

var on = function on(el, types, fn) {
return _listener(el, 'addEventListener', types, fn);
};
var settings = Object.assign({
viewport: null,
styles: {
'header,footer,section,article': black(8),
'h1,a': black(10),
'h2,h3,h4': black(8)
},
back: black(2),
view: black(5),
drag: black(10),
interval: null
}, options);

var _listener = function _listener(el, method, types, fn) {
return types.split(/\s+/).forEach(function (type) {
return el[method](type, fn);
});
};

var off = function off(el, types, fn) {
return _listener(el, 'removeEventListener', types, fn);
};
var on = function on(el, types, fn) {
return _listener(el, 'addEventListener', types, fn);
};

var Rect = function Rect(x, y, w, h) {
return {
x: x,
y: y,
w: w,
h: h
var off = function off(el, types, fn) {
return _listener(el, 'removeEventListener', types, fn);
};
};

var rect_rel_to = function rect_rel_to(rect) {
var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
x: 0,
y: 0
var Rect = function Rect(x, y, w, h) {
return {
x: x,
y: y,
w: w,
h: h
};
};
return Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h);
};

var rect_of_doc = function rect_of_doc() {
return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight);
};
var rect_rel_to = function rect_rel_to(rect) {
var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
x: 0,
y: 0
};
return Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h);
};

var rect_of_win = function rect_of_win() {
return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight);
};
var rect_of_doc = function rect_of_doc() {
return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight);
};

var el_get_offset = function el_get_offset(el) {
var br = el.getBoundingClientRect();
return {
x: br.left + WIN.pageXOffset,
y: br.top + WIN.pageYOffset
var rect_of_win = function rect_of_win() {
return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight);
};
};

var rect_of_el = function rect_of_el(el) {
var _el_get_offset = el_get_offset(el),
x = _el_get_offset.x,
y = _el_get_offset.y;
var el_get_offset = function el_get_offset(el) {
var br = el.getBoundingClientRect();
return {
x: br.left + WIN.pageXOffset,
y: br.top + WIN.pageYOffset
};
};

return Rect(x, y, el.offsetWidth, el.offsetHeight);
};
var rect_of_el = function rect_of_el(el) {
var _el_get_offset = el_get_offset(el),
x = _el_get_offset.x,
y = _el_get_offset.y;

var rect_of_viewport = function rect_of_viewport(el) {
var _el_get_offset2 = el_get_offset(el),
x = _el_get_offset2.x,
y = _el_get_offset2.y;
return Rect(x, y, el.offsetWidth, el.offsetHeight);
};

return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
};
var rect_of_viewport = function rect_of_viewport(el) {
var _el_get_offset2 = el_get_offset(el),
x = _el_get_offset2.x,
y = _el_get_offset2.y;

var rect_of_content = function rect_of_content(el) {
var _el_get_offset3 = el_get_offset(el),
x = _el_get_offset3.x,
y = _el_get_offset3.y;
return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
};

return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight);
};
var rect_of_content = function rect_of_content(el) {
var _el_get_offset3 = el_get_offset(el),
x = _el_get_offset3.x,
y = _el_get_offset3.y;

module.exports = function (canvas, options) {
var settings = Object.assign({}, defaults, options);
var context = canvas.getContext('2d');
return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight);
};

var calc_scale = function () {
var width = canvas.clientWidth;
Expand Down Expand Up @@ -225,14 +223,12 @@ module.exports = function (canvas, options) {
var drag_ry;

var draw_rect = function draw_rect(rect, col) {
if (!col) {
return;
if (col) {
CTX.beginPath();
CTX.rect(rect.x, rect.y, rect.w, rect.h);
CTX.fillStyle = col;
CTX.fill();
}

context.beginPath();
context.rect(rect.x, rect.y, rect.w, rect.h);
context.fillStyle = col;
context.fill();
};

var apply_styles = function apply_styles(styles) {
Expand All @@ -249,9 +245,9 @@ module.exports = function (canvas, options) {
view_rect = viewport ? rect_of_viewport(viewport) : rect_of_win();
scale = calc_scale(root_rect.w, root_rect.h);
resize_canvas(root_rect.w * scale, root_rect.h * scale);
context.setTransform(1, 0, 0, 1, 0, 0);
context.clearRect(0, 0, canvas.width, canvas.height);
context.scale(scale, scale);
CTX.setTransform(1, 0, 0, 1, 0, 0);
CTX.clearRect(0, 0, canvas.width, canvas.height);
CTX.scale(scale, scale);
draw_rect(rect_rel_to(root_rect, root_rect), settings.back);
apply_styles(settings.styles);
draw_rect(rect_rel_to(view_rect, root_rect), drag ? settings.drag : settings.view);
Expand All @@ -276,7 +272,7 @@ module.exports = function (canvas, options) {
var on_drag_end = function on_drag_end(ev) {
drag = false;
canvas.style.cursor = 'pointer';
body.style.cursor = 'auto';
BODY.style.cursor = 'auto';
off(WIN, 'mousemove', on_drag);
off(WIN, 'mouseup', on_drag_end);
on_drag(ev);
Expand All @@ -295,7 +291,7 @@ module.exports = function (canvas, options) {
}

canvas.style.cursor = 'crosshair';
body.style.cursor = 'crosshair';
BODY.style.cursor = 'crosshair';
on(WIN, 'mousemove', on_drag);
on(WIN, 'mouseup', on_drag_end);
on_drag(ev);
Expand Down
4 changes: 2 additions & 2 deletions dist/pagemap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pagemap",
"version": "1.1.0",
"version": "1.2.0",
"description": "Mini map for web pages.",
"homepage": "https://larsjung.de/pagemap/",
"bugs": "https://github.com/lrsjng/pagemap/issues",
Expand All @@ -22,7 +22,7 @@
"@babel/core": "7.4.4",
"@babel/preset-env": "7.4.4",
"eslint": "5.16.0",
"ghu": "0.19.0",
"ghu": "0.20.0",
"jsdom": "15.0.0",
"scar": "1.7.0"
},
Expand Down
Loading

0 comments on commit d76b3c4

Please sign in to comment.