mirror of
https://github.com/lrsjng/pagemap.git
synced 2025-09-04 02:22:44 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
192be62516 | ||
|
cff4c99036 | ||
|
f6fcd78cec | ||
|
d76b3c4dd5 | ||
|
a05a11d795 | ||
|
cfd5be77a9 |
@@ -12,7 +12,7 @@ insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
|
||||
[{*.json,*.yml,.eslintrc}]
|
||||
[{*.json,*.yml}]
|
||||
indent_size = 2
|
||||
|
||||
|
||||
|
@@ -1,6 +0,0 @@
|
||||
/build/
|
||||
/coverage/
|
||||
/dist/
|
||||
/es5/
|
||||
/local/
|
||||
/node_modules/
|
179
.eslintrc
179
.eslintrc
@@ -1,179 +0,0 @@
|
||||
---
|
||||
root: true
|
||||
|
||||
env:
|
||||
es6: true
|
||||
node: true
|
||||
|
||||
rules:
|
||||
array-bracket-spacing: [2, never]
|
||||
arrow-parens: [2, as-needed]
|
||||
arrow-spacing: 2
|
||||
block-scoped-var: 2
|
||||
brace-style: [2, 1tbs, {allowSingleLine: true}]
|
||||
camelcase: 0
|
||||
comma-dangle: [2, never]
|
||||
comma-spacing: [2, {before: false, after: true}]
|
||||
comma-style: [2, last]
|
||||
complexity: [1, 16] ###
|
||||
computed-property-spacing: [2, never]
|
||||
consistent-return: 2
|
||||
consistent-this: [2, self]
|
||||
constructor-super: 2
|
||||
curly: [2, multi-line]
|
||||
default-case: 2
|
||||
dot-location: [2, property]
|
||||
dot-notation: [2, {allowKeywords: true}]
|
||||
eol-last: 2
|
||||
eqeqeq: 2
|
||||
func-names: 2
|
||||
func-style: [2, declaration, {allowArrowFunctions: true}]
|
||||
generator-star-spacing: [2, after]
|
||||
guard-for-in: 2
|
||||
handle-callback-err: 2
|
||||
indent: [2, 4]
|
||||
key-spacing: [2, {beforeColon: false, afterColon: true}]
|
||||
keyword-spacing: [2, {before: true, after: true}]
|
||||
linebreak-style: [2, unix]
|
||||
max-depth: [1, 4]
|
||||
max-len: [0, 80, 4]
|
||||
max-nested-callbacks: [1, 3]
|
||||
max-params: [1, 5] ###
|
||||
max-statements: [1, 32] ###
|
||||
new-cap: 0
|
||||
new-parens: 2
|
||||
newline-after-var: 0
|
||||
no-alert: 2
|
||||
no-array-constructor: 2
|
||||
no-bitwise: 2
|
||||
no-caller: 2
|
||||
no-catch-shadow: 2
|
||||
no-class-assign: 2
|
||||
no-cond-assign: 2
|
||||
no-console: 0 ###
|
||||
no-const-assign: 2
|
||||
no-constant-condition: 1
|
||||
no-continue: 0
|
||||
no-control-regex: 2
|
||||
no-debugger: 2
|
||||
no-delete-var: 2
|
||||
no-div-regex: 2
|
||||
no-dupe-args: 2
|
||||
no-dupe-class-members: 2
|
||||
no-dupe-keys: 2
|
||||
no-duplicate-case: 2
|
||||
no-else-return: 1
|
||||
no-empty: 2
|
||||
no-empty-character-class: 2
|
||||
no-empty-pattern: 2
|
||||
no-eq-null: 2
|
||||
no-eval: 2
|
||||
no-ex-assign: 2
|
||||
no-extend-native: 1
|
||||
no-extra-bind: 2
|
||||
no-extra-boolean-cast: 2
|
||||
no-extra-parens: 1
|
||||
no-extra-semi: 2
|
||||
no-fallthrough: 2
|
||||
no-floating-decimal: 2
|
||||
no-func-assign: 2
|
||||
no-implicit-coercion: [2, {boolean: false, number: true, string: true}]
|
||||
no-implied-eval: 2
|
||||
no-inline-comments: 0
|
||||
no-inner-declarations: [2, functions]
|
||||
no-invalid-regexp: 2
|
||||
no-invalid-this: 2
|
||||
no-irregular-whitespace: 2
|
||||
no-iterator: 2
|
||||
no-label-var: 2
|
||||
no-labels: 2
|
||||
no-lone-blocks: 2
|
||||
no-lonely-if: 2
|
||||
no-loop-func: 1
|
||||
no-magic-numbers: 0
|
||||
no-mixed-requires: [2, false]
|
||||
no-mixed-spaces-and-tabs: [2, false]
|
||||
no-multi-spaces: 2
|
||||
no-multi-str: 2
|
||||
no-multiple-empty-lines: [2, {max: 4}]
|
||||
no-native-reassign: 1
|
||||
no-negated-in-lhs: 2
|
||||
no-nested-ternary: 0
|
||||
no-new: 2
|
||||
no-new-func: 2
|
||||
no-new-object: 2
|
||||
no-new-require: 2
|
||||
no-new-wrappers: 2
|
||||
no-obj-calls: 2
|
||||
no-octal: 2
|
||||
no-octal-escape: 2
|
||||
no-param-reassign: 0
|
||||
no-path-concat: 2
|
||||
no-plusplus: 2
|
||||
no-process-env: 2
|
||||
no-process-exit: 2
|
||||
no-proto: 2
|
||||
no-redeclare: 2
|
||||
no-regex-spaces: 2
|
||||
no-restricted-modules: 2
|
||||
no-return-assign: 2
|
||||
no-script-url: 2
|
||||
no-self-compare: 2
|
||||
no-sequences: 2
|
||||
no-shadow: 2
|
||||
no-shadow-restricted-names: 2
|
||||
no-spaced-func: 2
|
||||
no-sparse-arrays: 2
|
||||
no-sync: 0
|
||||
no-ternary: 0
|
||||
no-this-before-super: 2
|
||||
no-throw-literal: 1
|
||||
no-trailing-spaces: 2
|
||||
no-undef: 2
|
||||
no-undef-init: 2
|
||||
no-undefined: 0
|
||||
no-underscore-dangle: 0
|
||||
no-unexpected-multiline: 2
|
||||
no-unneeded-ternary: 2
|
||||
no-unreachable: 2
|
||||
no-useless-call: 2
|
||||
no-useless-concat: 2
|
||||
no-unused-expressions: 2
|
||||
no-unused-vars: [1, {vars: all, args: after-used}]
|
||||
no-use-before-define: 2
|
||||
no-var: 2
|
||||
no-void: 2
|
||||
no-warning-comments: [1, {terms: [todo, fixme, xxx], location: start}]
|
||||
no-with: 2
|
||||
object-curly-spacing: [2, never]
|
||||
object-shorthand: [2, always]
|
||||
one-var: [2, never]
|
||||
operator-assignment: [2, always]
|
||||
operator-linebreak: [2, after]
|
||||
padded-blocks: [2, never]
|
||||
prefer-arrow-callback: 2
|
||||
prefer-const: 1
|
||||
prefer-reflect: 1
|
||||
prefer-spread: 2
|
||||
prefer-template: 0 ###
|
||||
quote-props: [2, as-needed]
|
||||
quotes: [2, single, avoid-escape]
|
||||
radix: 2
|
||||
require-yield: 2
|
||||
semi: 2
|
||||
semi-spacing: [2, {before: false, after: true}]
|
||||
sort-vars: 0
|
||||
space-before-blocks: [2, always]
|
||||
space-before-function-paren: [2, {anonymous: always, named: never}]
|
||||
space-in-parens: [2, never]
|
||||
space-infix-ops: 2
|
||||
space-unary-ops: [2, {words: true, nonwords: false}]
|
||||
spaced-comment: [2, always]
|
||||
strict: [2, never]
|
||||
use-isnan: 2
|
||||
valid-jsdoc: 2
|
||||
valid-typeof: 2
|
||||
vars-on-top: 0
|
||||
wrap-iife: [2, outside]
|
||||
wrap-regex: 2
|
||||
yoda: [2, never, {exceptRange: true}]
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/.nyc_output/
|
||||
/build/
|
||||
/coverage/
|
||||
/local/
|
||||
|
22
README.md
22
README.md
@@ -1,7 +1,6 @@
|
||||
# pagemap
|
||||
|
||||
[![license][license-img]][github] [![web][web-img]][web] [![github][github-img]][github] [![npm][npm-img]][npm]
|
||||
[![version][npm-v-img]][npm] [![downloads][npm-dm-img]][npm]
|
||||
[![license][license-img]][github] [![github][github-img]][github] [![npm][npm-img]][npm]
|
||||
|
||||
Mini map for web pages.
|
||||
|
||||
@@ -30,13 +29,13 @@ init and style the mini map:
|
||||
pagemap(document.querySelector('#map'), {
|
||||
viewport: null,
|
||||
styles: {
|
||||
'header,footer,section,article': rgba(0,0,0,0.08),
|
||||
'h1,a': rgba(0,0,0,0.10),
|
||||
'h2,h3,h4': rgba(0,0,0,0.08)
|
||||
'header,footer,section,article': 'rgba(0,0,0,0.08)',
|
||||
'h1,a': 'rgba(0,0,0,0.10)',
|
||||
'h2,h3,h4': 'rgba(0,0,0,0.08)'
|
||||
},
|
||||
back: rgba(0,0,0,0.02),
|
||||
view: rgba(0,0,0,0.05),
|
||||
drag: rgba(0,0,0,0.10),
|
||||
back: 'rgba(0,0,0,0.02)',
|
||||
view: 'rgba(0,0,0,0.05)',
|
||||
drag: 'rgba(0,0,0,0.10)',
|
||||
interval: null
|
||||
});
|
||||
```
|
||||
@@ -45,7 +44,7 @@ pagemap(document.querySelector('#map'), {
|
||||
## License
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Lars Jung (https://larsjung.de)
|
||||
Copyright (c) 2024 Lars Jung (https://larsjung.de)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -66,14 +65,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
[web]: https://larsjung.de/pagemap/
|
||||
[github]: https://github.com/lrsjng/pagemap
|
||||
[npm]: https://www.npmjs.org/package/pagemap
|
||||
|
||||
[license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
|
||||
[web-img]: https://img.shields.io/badge/web-larsjung.de/pagemap-a0a060.svg?style=flat-square
|
||||
[github-img]: https://img.shields.io/badge/github-lrsjng/pagemap-a0a060.svg?style=flat-square
|
||||
[npm-img]: https://img.shields.io/badge/npm-pagemap-a0a060.svg?style=flat-square
|
||||
|
||||
[npm-v-img]: https://img.shields.io/npm/v/pagemap.svg?style=flat-square
|
||||
[npm-dm-img]: https://img.shields.io/npm/dm/pagemap.svg?style=flat-square
|
||||
|
250
dist/pagemap.js
vendored
Normal file
250
dist/pagemap.js
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
/*! pagemap v1.4.1 - undefined */
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define("pagemap", [], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["pagemap"] = factory();
|
||||
else
|
||||
root["pagemap"] = factory();
|
||||
})((typeof self !== 'undefined' ? self : this), () => {
|
||||
return /******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ([
|
||||
/* 0 */
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
module.exports = function (canvas, options) {
|
||||
var WIN = __webpack_require__.g.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 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 on = function on(el, types, fn) {
|
||||
return _listener(el, 'addEventListener', types, fn);
|
||||
};
|
||||
var off = function off(el, types, fn) {
|
||||
return _listener(el, 'removeEventListener', types, fn);
|
||||
};
|
||||
var Rect = function Rect(x, y, w, h) {
|
||||
return {
|
||||
x: x,
|
||||
y: y,
|
||||
w: w,
|
||||
h: h
|
||||
};
|
||||
};
|
||||
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_doc = function rect_of_doc() {
|
||||
return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight);
|
||||
};
|
||||
var rect_of_win = function rect_of_win() {
|
||||
return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight);
|
||||
};
|
||||
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_el = function rect_of_el(el) {
|
||||
var _el_get_offset = el_get_offset(el),
|
||||
x = _el_get_offset.x,
|
||||
y = _el_get_offset.y;
|
||||
return Rect(x, y, el.offsetWidth, el.offsetHeight);
|
||||
};
|
||||
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 + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
|
||||
};
|
||||
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 - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight);
|
||||
};
|
||||
var calc_scale = function () {
|
||||
var width = canvas.clientWidth;
|
||||
var height = canvas.clientHeight;
|
||||
return function (w, h) {
|
||||
return Math.min(width / w, height / h);
|
||||
};
|
||||
}();
|
||||
var resize_canvas = function resize_canvas(w, h) {
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
canvas.style.width = "".concat(w, "px");
|
||||
canvas.style.height = "".concat(h, "px");
|
||||
};
|
||||
var viewport = settings.viewport;
|
||||
var find = function find(sel) {
|
||||
return Array.from((viewport || DOC).querySelectorAll(sel));
|
||||
};
|
||||
var drag = false;
|
||||
var root_rect;
|
||||
var view_rect;
|
||||
var scale;
|
||||
var drag_rx;
|
||||
var drag_ry;
|
||||
var draw_rect = function draw_rect(rect, col) {
|
||||
if (col) {
|
||||
CTX.beginPath();
|
||||
CTX.rect(rect.x, rect.y, rect.w, rect.h);
|
||||
CTX.fillStyle = col;
|
||||
CTX.fill();
|
||||
}
|
||||
};
|
||||
var apply_styles = function apply_styles(styles) {
|
||||
Object.keys(styles).forEach(function (sel) {
|
||||
var col = styles[sel];
|
||||
find(sel).forEach(function (el) {
|
||||
draw_rect(rect_rel_to(rect_of_el(el), root_rect), col);
|
||||
});
|
||||
});
|
||||
};
|
||||
var draw = function draw() {
|
||||
root_rect = viewport ? rect_of_content(viewport) : rect_of_doc();
|
||||
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);
|
||||
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);
|
||||
};
|
||||
var on_drag = function on_drag(ev) {
|
||||
ev.preventDefault();
|
||||
var cr = rect_of_viewport(canvas);
|
||||
var x = (ev.pageX - cr.x) / scale - view_rect.w * drag_rx;
|
||||
var y = (ev.pageY - cr.y) / scale - view_rect.h * drag_ry;
|
||||
if (viewport) {
|
||||
viewport.scrollLeft = x;
|
||||
viewport.scrollTop = y;
|
||||
} else {
|
||||
WIN.scrollTo(x, y);
|
||||
}
|
||||
draw();
|
||||
};
|
||||
var _on_drag_end = function on_drag_end(ev) {
|
||||
drag = false;
|
||||
canvas.style.cursor = 'pointer';
|
||||
BODY.style.cursor = 'auto';
|
||||
off(WIN, 'mousemove', on_drag);
|
||||
off(WIN, 'mouseup', _on_drag_end);
|
||||
on_drag(ev);
|
||||
};
|
||||
var on_drag_start = function on_drag_start(ev) {
|
||||
drag = true;
|
||||
var cr = rect_of_viewport(canvas);
|
||||
var vr = rect_rel_to(view_rect, root_rect);
|
||||
drag_rx = ((ev.pageX - cr.x) / scale - vr.x) / vr.w;
|
||||
drag_ry = ((ev.pageY - cr.y) / scale - vr.y) / vr.h;
|
||||
if (drag_rx < 0 || drag_rx > 1 || drag_ry < 0 || drag_ry > 1) {
|
||||
drag_rx = 0.5;
|
||||
drag_ry = 0.5;
|
||||
}
|
||||
canvas.style.cursor = 'crosshair';
|
||||
BODY.style.cursor = 'crosshair';
|
||||
on(WIN, 'mousemove', on_drag);
|
||||
on(WIN, 'mouseup', _on_drag_end);
|
||||
on_drag(ev);
|
||||
};
|
||||
var init = function init() {
|
||||
canvas.style.cursor = 'pointer';
|
||||
on(canvas, 'mousedown', on_drag_start);
|
||||
on(viewport || WIN, 'load resize scroll', draw);
|
||||
if (settings.interval > 0) {
|
||||
setInterval(function () {
|
||||
return draw();
|
||||
}, settings.interval);
|
||||
}
|
||||
draw();
|
||||
};
|
||||
init();
|
||||
return {
|
||||
redraw: draw
|
||||
};
|
||||
};
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/global */
|
||||
/******/ (() => {
|
||||
/******/ __webpack_require__.g = (function() {
|
||||
/******/ if (typeof globalThis === 'object') return globalThis;
|
||||
/******/ try {
|
||||
/******/ return this || new Function('return this')();
|
||||
/******/ } catch (e) {
|
||||
/******/ if (typeof window === 'object') return window;
|
||||
/******/ }
|
||||
/******/ })();
|
||||
/******/ })();
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/
|
||||
/******/ // startup
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ // This entry module is referenced by other modules so it can't be inlined
|
||||
/******/ var __webpack_exports__ = __webpack_require__(0);
|
||||
/******/
|
||||
/******/ return __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
||||
});
|
4
dist/pagemap.min.js
vendored
4
dist/pagemap.min.js
vendored
@@ -1,2 +1,2 @@
|
||||
/*! pagemap v0.6.0 - https://larsjung.de/pagemap/ */
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pagemap",[],t):"object"==typeof exports?exports.pagemap=t():e.pagemap=t()}("undefined"!=typeof self?self:this,function(){return function(n){var r={};function o(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=n,o.c=r,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(n,e,t){(function(e){var b=e.window,w=b.document,j=w.documentElement,O=w.querySelector("body"),t=function(e){return"rgba(0,0,0,".concat(e/100,")")},S={viewport:null,styles:{"header,footer,section,article":t(8),"h1,a":t(10),"h2,h3,h4":t(8)},back:t(2),view:t(5),drag:t(10),interval:null},r=function(t,n,e,r){return e.split(/\s+/).forEach(function(e){return t[n](e,r)})},T=function(e,t,n){return r(e,"addEventListener",t,n)},E=function(e,t,n){return r(e,"removeEventListener",t,n)},H=function(e,t,n,r){return{x:e,y:t,w:n,h:r}},L=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{x:0,y:0};return H(e.x-t.x,e.y-t.y,e.w,e.h)},P=function(e){var t=e.getBoundingClientRect();return{x:t.left+b.pageXOffset,y:t.top+b.pageYOffset}},W=function(e){var t=P(e),n=t.x,r=t.y;return H(n+e.clientLeft,r+e.clientTop,e.clientWidth,e.clientHeight)};n.exports=function(o,e){var n,r,i,c,u,l,f,t=Object.assign({},S,e),a=o.getContext("2d"),s=(n=o.clientWidth,r=o.clientHeight,function(e,t){return Math.min(n/e,r/t)}),p=t.viewport,d=!1,h=function(e,t){t&&(a.beginPath(),a.rect(e.x,e.y,e.w,e.h),a.fillStyle=t,a.fill())},y=function(n){Object.keys(n).forEach(function(e){var t=n[e];(function(e){return Array.from((p||w).querySelectorAll(e))})(e).forEach(function(e){h(L(function(e){var t=P(e),n=t.x,r=t.y;return H(n,r,e.offsetWidth,e.offsetHeight)}(e),i),t)})})},g=function(){i=p?function(e){var t=P(e),n=t.x,r=t.y;return H(n+e.clientLeft-e.scrollLeft,r+e.clientTop-e.scrollTop,e.scrollWidth,e.scrollHeight)}(p):H(0,0,j.scrollWidth,j.scrollHeight),c=p?W(p):H(b.pageXOffset,b.pageYOffset,j.clientWidth,j.clientHeight),u=s(i.w,i.h),function(e,t){o.width=e,o.height=t,o.style.width="".concat(e,"px"),o.style.height="".concat(t,"px")}(i.w*u,i.h*u),a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,o.width,o.height),a.scale(u,u),h(L(i,i),t.back),y(t.styles),h(L(c,i),d?t.drag:t.view)},v=function(e){e.preventDefault();var t=W(o),n=(e.pageX-t.x)/u-c.w*l,r=(e.pageY-t.y)/u-c.h*f;p?(p.scrollLeft=n,p.scrollTop=r):b.scrollTo(n,r),g()},m=function e(t){d=!1,o.style.cursor="pointer",O.style.cursor="auto",E(b,"mousemove",v),E(b,"mouseup",e),v(t)},x=function(e){d=!0;var t=W(o),n=L(c,i);l=((e.pageX-t.x)/u-n.x)/n.w,f=((e.pageY-t.y)/u-n.y)/n.h,(l<0||1<l||f<0||1<f)&&(f=l=.5),o.style.cursor="crosshair",O.style.cursor="crosshair",T(b,"mousemove",v),T(b,"mouseup",m),v(e)};return o.style.cursor="pointer",T(o,"mousedown",x),T(p||b,"load resize scroll",g),0<t.interval&&setInterval(function(){return g()},t.interval),g(),{redraw:g}}}).call(this,t(1))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n}])});
|
||||
/*! pagemap v1.4.1 - undefined */
|
||||
((t,e)=>{"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("pagemap",[],e):"object"==typeof exports?exports.pagemap=e():t.pagemap=e()})("undefined"!=typeof self?self:this,()=>{return r=[(t,e,B)=>{t.exports=function(r,t){function e(t){return"rgba(0,0,0,".concat(t/100,")")}function n(t){k=!0;var e=L(r),n=b(u,c);f=((t.pageX-e.x)/l-n.x)/n.w,s=((t.pageY-e.y)/l-n.y)/n.h,(f<0||1<f||s<0||1<s)&&(s=f=.5),r.style.cursor="crosshair",d.style.cursor="crosshair",w(a,"mousemove",A),w(a,"mouseup",C),A(t)}var o,i,c,u,l,f,s,a=B.g.window,h=a.document,p=h.documentElement,d=h.querySelector("body"),y=r.getContext("2d"),g=Object.assign({viewport:null,styles:{"header,footer,section,article":e(8),"h1,a":e(10),"h2,h3,h4":e(8)},back:e(2),view:e(5),drag:e(10),interval:null},t),v=function(e,n,t,r){return t.split(/\s+/).forEach(function(t){return e[n](t,r)})},w=function(t,e,n){return v(t,"addEventListener",e,n)},x=function(t,e,n){return v(t,"removeEventListener",e,n)},m=function(t,e,n,r){return{x:t,y:e,w:n,h:r}},b=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{x:0,y:0};return m(t.x-e.x,t.y-e.y,t.w,t.h)},T=function(){return m(0,0,p.scrollWidth,p.scrollHeight)},j=function(){return m(a.pageXOffset,a.pageYOffset,p.clientWidth,p.clientHeight)},E=function(t){t=t.getBoundingClientRect();return{x:t.left+a.pageXOffset,y:t.top+a.pageYOffset}},H=function(t){var e=E(t),n=e.x;return m(n,e.y,t.offsetWidth,t.offsetHeight)},L=function(t){var e=E(t),n=e.x;return m(n+t.clientLeft,e.y+t.clientTop,t.clientWidth,t.clientHeight)},O=function(t){var e=E(t),n=e.x;return m(n+t.clientLeft-t.scrollLeft,e.y+t.clientTop-t.scrollTop,t.scrollWidth,t.scrollHeight)},W=(o=r.clientWidth,i=r.clientHeight,function(t,e){return Math.min(o/t,i/e)}),X=function(t,e){r.width=t,r.height=e,r.style.width="".concat(t,"px"),r.style.height="".concat(e,"px")},Y=g.viewport,R=function(t){return Array.from((Y||h).querySelectorAll(t))},k=!1,S=function(t,e){e&&(y.beginPath(),y.rect(t.x,t.y,t.w,t.h),y.fillStyle=e,y.fill())},z=function(n){Object.keys(n).forEach(function(t){var e=n[t];R(t).forEach(function(t){S(b(H(t),c),e)})})},q=function(){c=Y?O(Y):T(),u=Y?L(Y):j(),l=W(c.w,c.h),X(c.w*l,c.h*l),y.setTransform(1,0,0,1,0,0),y.clearRect(0,0,r.width,r.height),y.scale(l,l),S(b(c,c),g.back),z(g.styles),S(b(u,c),k?g.drag:g.view)},A=function(t){t.preventDefault();var e=L(r),n=(t.pageX-e.x)/l-u.w*f,t=(t.pageY-e.y)/l-u.h*s;Y?(Y.scrollLeft=n,Y.scrollTop=t):a.scrollTo(n,t),q()},C=function(t){k=!1,r.style.cursor="pointer",d.style.cursor="auto",x(a,"mousemove",A),x(a,"mouseup",C),A(t)};return r.style.cursor="pointer",w(r,"mousedown",n),w(Y||a,"load resize scroll",q),0<g.interval&&setInterval(function(){return q()},g.interval),q(),{redraw:q}}}],o={},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n(0);function n(t){var e=o[t];return void 0!==e||(e=o[t]={exports:{}},r[t](e,e.exports,n)),e.exports}var r,o});
|
252
eslint.config.cjs
Normal file
252
eslint.config.cjs
Normal file
@@ -0,0 +1,252 @@
|
||||
const globals = require("globals");
|
||||
|
||||
module.exports = [{
|
||||
ignores: ["eslint.config.*", "build/", "coverage/", "dist/", "es5/", "local/", "node_modules/"],
|
||||
}, {
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
},
|
||||
|
||||
ecmaVersion: 2019,
|
||||
sourceType: "commonjs",
|
||||
},
|
||||
|
||||
rules: {
|
||||
"array-bracket-spacing": [2, "never"],
|
||||
"arrow-parens": [2, "as-needed"],
|
||||
"arrow-spacing": 2,
|
||||
"block-scoped-var": 2,
|
||||
|
||||
"brace-style": [2, "1tbs", {
|
||||
allowSingleLine: true,
|
||||
}],
|
||||
|
||||
camelcase: 0,
|
||||
"comma-dangle": [2, "never"],
|
||||
|
||||
"comma-spacing": [2, {
|
||||
before: false,
|
||||
after: true,
|
||||
}],
|
||||
|
||||
"comma-style": [2, "last"],
|
||||
complexity: [1, 16],
|
||||
"computed-property-spacing": [2, "never"],
|
||||
"consistent-return": 2,
|
||||
"consistent-this": [2, "self"],
|
||||
"constructor-super": 2,
|
||||
curly: [2, "multi-line"],
|
||||
"default-case": 2,
|
||||
"dot-location": [2, "property"],
|
||||
|
||||
"dot-notation": [2, {
|
||||
allowKeywords: true,
|
||||
}],
|
||||
|
||||
"eol-last": 2,
|
||||
eqeqeq: 2,
|
||||
"func-names": 2,
|
||||
|
||||
"func-style": [2, "declaration", {
|
||||
allowArrowFunctions: true,
|
||||
}],
|
||||
|
||||
"generator-star-spacing": [2, "after"],
|
||||
"guard-for-in": 2,
|
||||
"handle-callback-err": 2,
|
||||
indent: [2, 4],
|
||||
|
||||
"key-spacing": [2, {
|
||||
beforeColon: false,
|
||||
afterColon: true,
|
||||
}],
|
||||
|
||||
"keyword-spacing": [2, {
|
||||
before: true,
|
||||
after: true,
|
||||
}],
|
||||
|
||||
"linebreak-style": [2, "unix"],
|
||||
"max-depth": [1, 4],
|
||||
"max-len": [0, 80, 4],
|
||||
"max-nested-callbacks": [1, 3],
|
||||
"max-params": [1, 5],
|
||||
"max-statements": [1, 48],
|
||||
"new-cap": 0,
|
||||
"new-parens": 2,
|
||||
"newline-after-var": 0,
|
||||
"no-alert": 2,
|
||||
"no-array-constructor": 2,
|
||||
"no-bitwise": 2,
|
||||
"no-caller": 2,
|
||||
"no-catch-shadow": 2,
|
||||
"no-class-assign": 2,
|
||||
"no-cond-assign": 2,
|
||||
"no-console": 0,
|
||||
"no-const-assign": 2,
|
||||
"no-constant-condition": 1,
|
||||
"no-continue": 0,
|
||||
"no-control-regex": 2,
|
||||
"no-debugger": 2,
|
||||
"no-delete-var": 2,
|
||||
"no-div-regex": 2,
|
||||
"no-dupe-args": 2,
|
||||
"no-dupe-class-members": 2,
|
||||
"no-dupe-keys": 2,
|
||||
"no-duplicate-case": 2,
|
||||
"no-else-return": 1,
|
||||
"no-empty": 2,
|
||||
"no-empty-character-class": 2,
|
||||
"no-empty-pattern": 2,
|
||||
"no-eq-null": 2,
|
||||
"no-eval": 2,
|
||||
"no-ex-assign": 2,
|
||||
"no-extend-native": 1,
|
||||
"no-extra-bind": 2,
|
||||
"no-extra-boolean-cast": 2,
|
||||
"no-extra-parens": 1,
|
||||
"no-extra-semi": 2,
|
||||
"no-fallthrough": 2,
|
||||
"no-floating-decimal": 2,
|
||||
"no-func-assign": 2,
|
||||
|
||||
"no-implicit-coercion": [2, {
|
||||
boolean: false,
|
||||
number: true,
|
||||
string: true,
|
||||
}],
|
||||
|
||||
"no-implied-eval": 2,
|
||||
"no-inline-comments": 0,
|
||||
"no-inner-declarations": [2, "functions"],
|
||||
"no-invalid-regexp": 2,
|
||||
"no-invalid-this": 2,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-iterator": 2,
|
||||
"no-label-var": 2,
|
||||
"no-labels": 2,
|
||||
"no-lone-blocks": 2,
|
||||
"no-lonely-if": 2,
|
||||
"no-loop-func": 1,
|
||||
"no-magic-numbers": 0,
|
||||
"no-mixed-requires": [2, false],
|
||||
"no-mixed-spaces-and-tabs": [2, false],
|
||||
"no-multi-spaces": 2,
|
||||
"no-multi-str": 2,
|
||||
|
||||
"no-multiple-empty-lines": [2, {
|
||||
max: 4,
|
||||
}],
|
||||
|
||||
"no-native-reassign": 1,
|
||||
"no-negated-in-lhs": 2,
|
||||
"no-nested-ternary": 0,
|
||||
"no-new": 2,
|
||||
"no-new-func": 2,
|
||||
"no-new-object": 2,
|
||||
"no-new-require": 2,
|
||||
"no-new-wrappers": 2,
|
||||
"no-obj-calls": 2,
|
||||
"no-octal": 2,
|
||||
"no-octal-escape": 2,
|
||||
"no-param-reassign": 0,
|
||||
"no-path-concat": 2,
|
||||
"no-plusplus": 2,
|
||||
"no-process-env": 2,
|
||||
"no-process-exit": 2,
|
||||
"no-proto": 2,
|
||||
"no-redeclare": 2,
|
||||
"no-regex-spaces": 2,
|
||||
"no-restricted-modules": 2,
|
||||
"no-return-assign": 2,
|
||||
"no-script-url": 2,
|
||||
"no-self-compare": 2,
|
||||
"no-sequences": 2,
|
||||
"no-shadow": 2,
|
||||
"no-shadow-restricted-names": 2,
|
||||
"no-spaced-func": 2,
|
||||
"no-sparse-arrays": 2,
|
||||
"no-sync": 0,
|
||||
"no-ternary": 0,
|
||||
"no-this-before-super": 2,
|
||||
"no-throw-literal": 1,
|
||||
"no-trailing-spaces": 2,
|
||||
"no-undef": 2,
|
||||
"no-undef-init": 2,
|
||||
"no-undefined": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unexpected-multiline": 2,
|
||||
"no-unneeded-ternary": 2,
|
||||
"no-unreachable": 2,
|
||||
"no-useless-call": 2,
|
||||
"no-useless-concat": 2,
|
||||
"no-unused-expressions": 2,
|
||||
|
||||
"no-unused-vars": [1, {
|
||||
vars: "all",
|
||||
args: "after-used",
|
||||
}],
|
||||
|
||||
"no-use-before-define": 2,
|
||||
"no-var": 2,
|
||||
"no-void": 2,
|
||||
|
||||
"no-warning-comments": [1, {
|
||||
terms: ["todo", "fixme", "xxx"],
|
||||
location: "start",
|
||||
}],
|
||||
|
||||
"no-with": 2,
|
||||
"object-curly-spacing": [2, "never"],
|
||||
"object-shorthand": [2, "always"],
|
||||
"one-var": [2, "never"],
|
||||
"operator-assignment": [2, "always"],
|
||||
"operator-linebreak": [2, "after"],
|
||||
"padded-blocks": [2, "never"],
|
||||
"prefer-arrow-callback": 2,
|
||||
"prefer-const": 1,
|
||||
"prefer-reflect": 1,
|
||||
"prefer-spread": 2,
|
||||
"prefer-template": 0,
|
||||
"quote-props": [2, "as-needed"],
|
||||
quotes: [2, "single", "avoid-escape"],
|
||||
radix: 2,
|
||||
"require-yield": 2,
|
||||
semi: 2,
|
||||
|
||||
"semi-spacing": [2, {
|
||||
before: false,
|
||||
after: true,
|
||||
}],
|
||||
|
||||
"sort-vars": 0,
|
||||
"space-before-blocks": [2, "always"],
|
||||
|
||||
"space-before-function-paren": [2, {
|
||||
anonymous: "always",
|
||||
named: "never",
|
||||
}],
|
||||
|
||||
"space-in-parens": [2, "never"],
|
||||
"space-infix-ops": 2,
|
||||
|
||||
"space-unary-ops": [2, {
|
||||
words: true,
|
||||
nonwords: false,
|
||||
}],
|
||||
|
||||
"spaced-comment": [2, "always"],
|
||||
strict: [2, "never"],
|
||||
"use-isnan": 2,
|
||||
// "valid-jsdoc": 2,
|
||||
"valid-typeof": 2,
|
||||
"vars-on-top": 0,
|
||||
"wrap-iife": [2, "outside"],
|
||||
"wrap-regex": 2,
|
||||
|
||||
yoda: [2, "never", {
|
||||
exceptRange: true,
|
||||
}],
|
||||
},
|
||||
}];
|
27
ghu.js
27
ghu.js
@@ -23,30 +23,11 @@ ghu.task('clean', () => {
|
||||
});
|
||||
|
||||
ghu.task('build:script', runtime => {
|
||||
const webpackConfig = {
|
||||
mode: 'none',
|
||||
output: {
|
||||
library: NAME,
|
||||
libraryTarget: 'umd',
|
||||
umdNamedDefine: true,
|
||||
globalObject: '(typeof self !== \'undefined\' ? self : this)'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
include: [SRC],
|
||||
loader: 'babel-loader',
|
||||
query: {
|
||||
cacheDirectory: true,
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
return read(`${SRC}/${NAME}.js`)
|
||||
.then(webpack(webpackConfig, {showStats: false}))
|
||||
.then(webpack(webpack.cfg_umd(NAME, [SRC])))
|
||||
.then(wrap(runtime.commentJs))
|
||||
.then(write(`${DIST}/${NAME}.js`, {overwrite: true}))
|
||||
.then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.js`, {overwrite: true}))
|
||||
.then(uglify())
|
||||
.then(wrap(runtime.commentJs))
|
||||
.then(write(`${DIST}/${NAME}.min.js`, {overwrite: true}))
|
||||
|
12015
package-lock.json
generated
12015
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"name": "pagemap",
|
||||
"version": "0.6.0",
|
||||
"version": "1.4.1",
|
||||
"description": "Mini map for web pages.",
|
||||
"homepage": "https://larsjung.de/pagemap/",
|
||||
"bugs": "https://github.com/lrsjng/pagemap/issues",
|
||||
"author": "Lars Jung <lrsjng@gmail.com> (https://larsjung.de)",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
@@ -13,17 +11,17 @@
|
||||
"main": "dist/pagemap",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "node test",
|
||||
"check": "npm run -s lint && npm run -s test",
|
||||
"build": "node ghu release",
|
||||
"precommit": "npm run -s lint && npm run -s build"
|
||||
"precommit": "npm run -s check && npm run -s build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.4.0",
|
||||
"@babel/preset-env": "7.4.2",
|
||||
"babel-loader": "8.0.5",
|
||||
"eslint": "5.16.0",
|
||||
"ghu": "0.15.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
"@babel/core": "7.26.0",
|
||||
"@babel/preset-env": "7.26.0",
|
||||
"eslint": "9.14.0",
|
||||
"ghu": "0.28.5",
|
||||
"jsdom": "25.0.1",
|
||||
"scar": "2.3.4"
|
||||
}
|
||||
}
|
||||
|
@@ -2,10 +2,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>pagemap boxes demo</title>
|
||||
<link rel="stylesheet" href="boxes.css">
|
||||
<title>pagemap demo - boxes</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body class="checkers">
|
||||
<body id="boxes-demo" class="checkers">
|
||||
<div id="banner">
|
||||
<div>pagemap demo</div>
|
||||
<div><a href="text.html">text</a> - <strong>boxes</strong></div>
|
||||
</div>
|
||||
|
||||
<div id="container">
|
||||
<div id="content" class="checkers">
|
||||
<div id="container2">
|
||||
@@ -21,9 +26,7 @@
|
||||
pagemap(document.querySelector('#map'), {
|
||||
// viewport: document.querySelector('#container'),
|
||||
interval: 50,
|
||||
styles: {
|
||||
div: 'rgba(0,0,0,0.1)'
|
||||
},
|
||||
styles: { div: 'rgba(0,0,0,0.1)' },
|
||||
back: 'rgba(255,255,255,1)'
|
||||
});
|
||||
</script>
|
||||
|
@@ -4,16 +4,68 @@
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Ubuntu, sans;
|
||||
font-size: 16px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
body#boxes-demo {
|
||||
width: 2000px;
|
||||
height: 2000px;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
a, a:visited, a:active {
|
||||
color: #1d77c2;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
main {
|
||||
margin: 3em auto 6em auto;
|
||||
max-width: 800px;
|
||||
line-height: 1.6em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3em;
|
||||
font-weight: normal;
|
||||
margin: 0 0 1em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.8em;
|
||||
font-weight: normal;
|
||||
margin: 3em 0 1em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
#banner {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
font-size: 16px;
|
||||
margin: 4px;
|
||||
padding: 4px 12px;
|
||||
text-align: center;
|
||||
line-height: 24px;
|
||||
background: rgba(255,255,255,0.8);
|
||||
border: 1px solid rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
#map {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 120px;
|
||||
width: 160px;
|
||||
height: 100%;
|
||||
z-index: 100;
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#map {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 200px;
|
||||
height: 100%;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Bitter, Ubuntu, Arial, sans;
|
||||
font-size: 16px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
main {
|
||||
margin: 3em auto 6em auto;
|
||||
max-width: 800px;
|
||||
line-height: 1.6em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3em;
|
||||
font-weight: normal;
|
||||
margin: 0 0 1em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.8em;
|
||||
font-weight: normal;
|
||||
margin: 3em 0 1em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #1E88E5;
|
||||
}
|
@@ -2,16 +2,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>pagemap text demo</title>
|
||||
<link rel="stylesheet" href="text.css">
|
||||
<title>pagemap demo - text</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="map"></canvas>
|
||||
|
||||
<script src="pagemap.min.js"></script>
|
||||
<script>
|
||||
pagemap(document.querySelector('#map'));
|
||||
</script>
|
||||
<body id="text-demo">
|
||||
<div id="banner">
|
||||
<div>pagemap demo</div>
|
||||
<div><strong>text</strong> - <a href="boxes.html">boxes</a></div>
|
||||
</div>
|
||||
|
||||
<main>
|
||||
<header>
|
||||
@@ -43,5 +41,12 @@
|
||||
<p> Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, <a href="?">eaque veritatis</a> et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</p>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<canvas id="map"></canvas>
|
||||
|
||||
<script src="pagemap.min.js"></script>
|
||||
<script>
|
||||
pagemap(document.querySelector('#map'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
148
src/pagemap.js
148
src/pagemap.js
@@ -1,60 +1,61 @@
|
||||
const win = global.window;
|
||||
const doc = win.document;
|
||||
const doc_el = doc.documentElement;
|
||||
const body = doc.querySelector('body');
|
||||
|
||||
const black = pc => `rgba(0,0,0,${pc / 100})`;
|
||||
const 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
|
||||
};
|
||||
|
||||
const _listener = (el, method, types, fn) => types.split(/\s+/).forEach(type => el[method](type, fn));
|
||||
const on = (el, types, fn) => _listener(el, 'addEventListener', types, fn);
|
||||
const off = (el, types, fn) => _listener(el, 'removeEventListener', types, fn);
|
||||
|
||||
const Rect = (x, y, w, h) => { return {x, y, w, h}; };
|
||||
const rect_rel_to = (rect, pos = {x: 0, y: 0}) => Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h);
|
||||
|
||||
const rect_of_doc = () => {
|
||||
return Rect(0, 0, doc_el.scrollWidth, doc_el.scrollHeight);
|
||||
};
|
||||
|
||||
const rect_of_win = () => {
|
||||
return Rect(win.pageXOffset, win.pageYOffset, doc_el.clientWidth, doc_el.clientHeight);
|
||||
};
|
||||
|
||||
const el_get_offset = el => {
|
||||
const br = el.getBoundingClientRect();
|
||||
return {x: br.left + win.pageXOffset, y: br.top + win.pageYOffset};
|
||||
};
|
||||
|
||||
const rect_of_el = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x, y, el.offsetWidth, el.offsetHeight);
|
||||
};
|
||||
|
||||
const rect_of_viewport = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
|
||||
};
|
||||
|
||||
const rect_of_content = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight);
|
||||
};
|
||||
|
||||
module.exports = (canvas, options) => {
|
||||
const settings = Object.assign({}, defaults, options);
|
||||
const context = canvas.getContext('2d');
|
||||
const WIN = global.window;
|
||||
const DOC = WIN.document;
|
||||
const DOC_EL = DOC.documentElement;
|
||||
const BODY = DOC.querySelector('body');
|
||||
const CTX = canvas.getContext('2d');
|
||||
|
||||
const black = pc => `rgba(0,0,0,${pc / 100})`;
|
||||
const 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);
|
||||
|
||||
const _listener = (el, method, types, fn) => types.split(/\s+/).forEach(type => el[method](type, fn));
|
||||
const on = (el, types, fn) => _listener(el, 'addEventListener', types, fn);
|
||||
const off = (el, types, fn) => _listener(el, 'removeEventListener', types, fn);
|
||||
|
||||
const Rect = (x, y, w, h) => { return {x, y, w, h}; };
|
||||
|
||||
const rect_rel_to = (rect, pos = {x: 0, y: 0}) => {
|
||||
return Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h);
|
||||
};
|
||||
|
||||
const rect_of_doc = () => {
|
||||
return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight);
|
||||
};
|
||||
|
||||
const rect_of_win = () => {
|
||||
return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight);
|
||||
};
|
||||
|
||||
const el_get_offset = el => {
|
||||
const br = el.getBoundingClientRect();
|
||||
return {x: br.left + WIN.pageXOffset, y: br.top + WIN.pageYOffset};
|
||||
};
|
||||
|
||||
const rect_of_el = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x, y, el.offsetWidth, el.offsetHeight);
|
||||
};
|
||||
|
||||
const rect_of_viewport = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
|
||||
};
|
||||
|
||||
const rect_of_content = el => {
|
||||
const {x, y} = el_get_offset(el);
|
||||
return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight);
|
||||
};
|
||||
|
||||
const calc_scale = (() => {
|
||||
const width = canvas.clientWidth;
|
||||
@@ -70,7 +71,7 @@ module.exports = (canvas, options) => {
|
||||
};
|
||||
|
||||
const viewport = settings.viewport;
|
||||
const find = sel => Array.from((viewport || doc).querySelectorAll(sel));
|
||||
const find = sel => Array.from((viewport || DOC).querySelectorAll(sel));
|
||||
|
||||
let drag = false;
|
||||
|
||||
@@ -81,13 +82,12 @@ module.exports = (canvas, options) => {
|
||||
let drag_ry;
|
||||
|
||||
const 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();
|
||||
};
|
||||
|
||||
const apply_styles = styles => {
|
||||
@@ -106,9 +106,9 @@ module.exports = (canvas, options) => {
|
||||
|
||||
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);
|
||||
@@ -125,7 +125,7 @@ module.exports = (canvas, options) => {
|
||||
viewport.scrollLeft = x;
|
||||
viewport.scrollTop = y;
|
||||
} else {
|
||||
win.scrollTo(x, y);
|
||||
WIN.scrollTo(x, y);
|
||||
}
|
||||
draw();
|
||||
};
|
||||
@@ -133,9 +133,9 @@ module.exports = (canvas, options) => {
|
||||
const on_drag_end = ev => {
|
||||
drag = false;
|
||||
canvas.style.cursor = 'pointer';
|
||||
body.style.cursor = 'auto';
|
||||
off(win, 'mousemove', on_drag);
|
||||
off(win, 'mouseup', on_drag_end);
|
||||
BODY.style.cursor = 'auto';
|
||||
off(WIN, 'mousemove', on_drag);
|
||||
off(WIN, 'mouseup', on_drag_end);
|
||||
on_drag(ev);
|
||||
};
|
||||
|
||||
@@ -152,16 +152,16 @@ module.exports = (canvas, options) => {
|
||||
}
|
||||
|
||||
canvas.style.cursor = 'crosshair';
|
||||
body.style.cursor = 'crosshair';
|
||||
on(win, 'mousemove', on_drag);
|
||||
on(win, 'mouseup', on_drag_end);
|
||||
BODY.style.cursor = 'crosshair';
|
||||
on(WIN, 'mousemove', on_drag);
|
||||
on(WIN, 'mouseup', on_drag_end);
|
||||
on_drag(ev);
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
canvas.style.cursor = 'pointer';
|
||||
on(canvas, 'mousedown', on_drag_start);
|
||||
on(viewport || win, 'load resize scroll', draw);
|
||||
on(viewport || WIN, 'load resize scroll', draw);
|
||||
if (settings.interval > 0) {
|
||||
setInterval(() => draw(), settings.interval);
|
||||
}
|
||||
|
24
test/index.js
Normal file
24
test/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const {test, assert} = require('scar');
|
||||
const pagemap = require('../src/pagemap');
|
||||
|
||||
if (!global.window) {
|
||||
global.window = new (require('jsdom')).JSDOM().window;
|
||||
}
|
||||
|
||||
test('access', () => {
|
||||
assert.equal(typeof pagemap, 'function');
|
||||
});
|
||||
|
||||
test('no canvas throws', () => {
|
||||
assert.throws(() => pagemap(), /getContext/);
|
||||
assert.throws(() => pagemap(true), /getContext/);
|
||||
assert.throws(() => pagemap({}, {}), /getContext/);
|
||||
});
|
||||
|
||||
// test('basic canvas', () => {
|
||||
// const canvas = global.window.document.createElement('canvas');
|
||||
// const res = pagemap(canvas);
|
||||
// assert.equal(typeof res, 'object');
|
||||
// });
|
||||
|
||||
test.cli();
|
Reference in New Issue
Block a user