├── .gitignore ├── .editorconfig ├── test └── index.js ├── package.json ├── src ├── demo │ ├── boxes.html │ ├── styles.css │ └── text.html └── pagemap.js ├── ghu.js ├── README.md ├── dist ├── pagemap.min.js └── pagemap.js └── eslint.config.cjs /.gitignore: -------------------------------------------------------------------------------- 1 | /.nyc_output/ 2 | /build/ 3 | /coverage/ 4 | /local/ 5 | /node_modules/ 6 | /npm-debug.log 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | 6 | [*] 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 4 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | 15 | [{*.json,*.yml}] 16 | indent_size = 2 17 | 18 | 19 | [{*.md,*.pug}] 20 | trim_trailing_whitespace = false 21 | 22 | 23 | [*.svg] 24 | insert_final_newline = false 25 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const {test, assert} = require('scar'); 2 | const pagemap = require('../src/pagemap'); 3 | 4 | if (!global.window) { 5 | global.window = new (require('jsdom')).JSDOM().window; 6 | } 7 | 8 | test('access', () => { 9 | assert.equal(typeof pagemap, 'function'); 10 | }); 11 | 12 | test('no canvas throws', () => { 13 | assert.throws(() => pagemap(), /getContext/); 14 | assert.throws(() => pagemap(true), /getContext/); 15 | assert.throws(() => pagemap({}, {}), /getContext/); 16 | }); 17 | 18 | // test('basic canvas', () => { 19 | // const canvas = global.window.document.createElement('canvas'); 20 | // const res = pagemap(canvas); 21 | // assert.equal(typeof res, 'object'); 22 | // }); 23 | 24 | test.cli(); 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pagemap", 3 | "version": "1.4.1", 4 | "description": "Mini map for web pages.", 5 | "author": "Lars Jung (https://larsjung.de)", 6 | "license": "MIT", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/lrsjng/pagemap.git" 10 | }, 11 | "main": "dist/pagemap", 12 | "scripts": { 13 | "lint": "eslint .", 14 | "test": "node test", 15 | "check": "npm run -s lint && npm run -s test", 16 | "build": "node ghu release", 17 | "precommit": "npm run -s check && npm run -s build" 18 | }, 19 | "devDependencies": { 20 | "@babel/core": "7.26.0", 21 | "@babel/preset-env": "7.26.0", 22 | "eslint": "9.14.0", 23 | "ghu": "0.28.5", 24 | "jsdom": "25.0.1", 25 | "scar": "2.3.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/demo/boxes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pagemap demo - boxes 6 | 7 | 8 | 9 | 13 | 14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | 22 | 23 | 24 | 25 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ghu.js: -------------------------------------------------------------------------------- 1 | const {resolve, join} = require('path'); 2 | const {ghu, jszip, mapfn, read, remove, uglify, webpack, wrap, write} = require('ghu'); 3 | 4 | const NAME = 'pagemap'; 5 | 6 | const ROOT = resolve(__dirname); 7 | const SRC = join(ROOT, 'src'); 8 | const DEMO = join(SRC, 'demo'); 9 | const BUILD = join(ROOT, 'build'); 10 | const DIST = join(ROOT, 'dist'); 11 | 12 | ghu.defaults('release'); 13 | 14 | ghu.before(runtime => { 15 | runtime.pkg = Object.assign({}, require('./package.json')); 16 | runtime.comment = `${NAME} v${runtime.pkg.version} - ${runtime.pkg.homepage}`; 17 | runtime.commentJs = `/*! ${runtime.comment} */\n`; 18 | console.log(runtime.comment); 19 | }); 20 | 21 | ghu.task('clean', () => { 22 | return remove(`${BUILD}, ${DIST}`); 23 | }); 24 | 25 | ghu.task('build:script', runtime => { 26 | return read(`${SRC}/${NAME}.js`) 27 | .then(webpack(webpack.cfg_umd(NAME, [SRC]))) 28 | .then(wrap(runtime.commentJs)) 29 | .then(write(`${DIST}/${NAME}.js`, {overwrite: true})) 30 | .then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.js`, {overwrite: true})) 31 | .then(uglify()) 32 | .then(wrap(runtime.commentJs)) 33 | .then(write(`${DIST}/${NAME}.min.js`, {overwrite: true})) 34 | .then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.min.js`, {overwrite: true})); 35 | }); 36 | 37 | ghu.task('build:copy', () => { 38 | return read(`${ROOT}/*.md`) 39 | .then(write(mapfn.p(ROOT, BUILD), {overwrite: true})); 40 | }); 41 | 42 | ghu.task('build:demo', ['build:script'], () => { 43 | return Promise.all([ 44 | read(`${DEMO}: *`) 45 | .then(write(mapfn.p(SRC, BUILD), {overwrite: true})), 46 | 47 | read(`${BUILD}: ${NAME}-*.min.js`) 48 | .then(write(`${BUILD}/demo/${NAME}.min.js`, {overwrite: true})) 49 | ]); 50 | }); 51 | 52 | ghu.task('build', ['build:script', 'build:copy', 'build:demo']); 53 | 54 | ghu.task('zip', ['build'], runtime => { 55 | return read(`${BUILD}/**`) 56 | .then(jszip({dir: BUILD, level: 9})) 57 | .then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.zip`, {overwrite: true})); 58 | }); 59 | 60 | ghu.task('release', ['clean', 'zip']); 61 | -------------------------------------------------------------------------------- /src/demo/styles.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | 6 | body { 7 | font-family: Ubuntu, sans; 8 | font-size: 16px; 9 | color: #555; 10 | } 11 | 12 | body#boxes-demo { 13 | width: 2000px; 14 | height: 2000px; 15 | background-color: #eee; 16 | } 17 | 18 | a, a:visited, a:active { 19 | color: #1d77c2; 20 | text-decoration: none; 21 | } 22 | 23 | a:hover { 24 | color: #555; 25 | } 26 | 27 | main { 28 | margin: 3em auto 6em auto; 29 | max-width: 800px; 30 | line-height: 1.6em; 31 | } 32 | 33 | h1 { 34 | font-size: 3em; 35 | font-weight: normal; 36 | margin: 0 0 1em; 37 | } 38 | 39 | h2 { 40 | font-size: 1.8em; 41 | font-weight: normal; 42 | margin: 3em 0 1em; 43 | } 44 | 45 | h3 { 46 | font-size: 1.2em; 47 | font-weight: bold; 48 | margin: 2em 0 1em; 49 | } 50 | 51 | #banner { 52 | position: absolute; 53 | left: 0; 54 | top: 0; 55 | font-size: 16px; 56 | margin: 4px; 57 | padding: 4px 12px; 58 | text-align: center; 59 | line-height: 24px; 60 | background: rgba(255,255,255,0.8); 61 | border: 1px solid rgba(0,0,0,0.5); 62 | } 63 | 64 | #map { 65 | position: fixed; 66 | top: 0; 67 | right: 0; 68 | width: 160px; 69 | height: 100%; 70 | z-index: 100; 71 | } 72 | 73 | #container { 74 | position: relative; 75 | left: 100px; 76 | top: 100px; 77 | width: 600px; 78 | height: 600px; 79 | outline: 4px solid #222; 80 | overflow: auto; 81 | } 82 | 83 | #content { 84 | width: 800px; 85 | height: 1000px; 86 | background-color: #ccc; 87 | } 88 | 89 | #container2 { 90 | position: relative; 91 | left: 100px; 92 | top: 100px; 93 | width: 300px; 94 | height: 400px; 95 | outline: 4px solid #222; 96 | overflow: auto; 97 | } 98 | 99 | #content2 { 100 | width: 500px; 101 | height: 600px; 102 | background-color: #aaa; 103 | } 104 | 105 | .checkers { 106 | background-image: 107 | linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff), 108 | linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff); 109 | background-size: 100px 100px; 110 | background-position: 0 0, 50px 50px 111 | } 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pagemap 2 | 3 | [![license][license-img]][github] [![github][github-img]][github] [![npm][npm-img]][npm] 4 | 5 | Mini map for web pages. 6 | 7 | 8 | ## Example usage 9 | 10 | add a `canvas` tag to your HTML page: 11 | ```html 12 | 13 | ``` 14 | 15 | fix it's position on the screen: 16 | ```css 17 | #map { 18 | position: fixed; 19 | top: 0; 20 | right: 0; 21 | width: 200px; 22 | height: 100%; 23 | z-index: 100; 24 | } 25 | ``` 26 | 27 | init and style the mini map: 28 | ```js 29 | pagemap(document.querySelector('#map'), { 30 | viewport: null, 31 | styles: { 32 | 'header,footer,section,article': 'rgba(0,0,0,0.08)', 33 | 'h1,a': 'rgba(0,0,0,0.10)', 34 | 'h2,h3,h4': 'rgba(0,0,0,0.08)' 35 | }, 36 | back: 'rgba(0,0,0,0.02)', 37 | view: 'rgba(0,0,0,0.05)', 38 | drag: 'rgba(0,0,0,0.10)', 39 | interval: null 40 | }); 41 | ``` 42 | 43 | 44 | ## License 45 | The MIT License (MIT) 46 | 47 | Copyright (c) 2024 Lars Jung (https://larsjung.de) 48 | 49 | Permission is hereby granted, free of charge, to any person obtaining a copy 50 | of this software and associated documentation files (the "Software"), to deal 51 | in the Software without restriction, including without limitation the rights 52 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 53 | copies of the Software, and to permit persons to whom the Software is 54 | furnished to do so, subject to the following conditions: 55 | 56 | The above copyright notice and this permission notice shall be included in 57 | all copies or substantial portions of the Software. 58 | 59 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 62 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 63 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 64 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 65 | THE SOFTWARE. 66 | 67 | 68 | [github]: https://github.com/lrsjng/pagemap 69 | [npm]: https://www.npmjs.org/package/pagemap 70 | 71 | [license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square 72 | [github-img]: https://img.shields.io/badge/github-lrsjng/pagemap-a0a060.svg?style=flat-square 73 | [npm-img]: https://img.shields.io/badge/npm-pagemap-a0a060.svg?style=flat-square 74 | -------------------------------------------------------------------------------- /dist/pagemap.min.js: -------------------------------------------------------------------------------- 1 | /*! pagemap v1.4.1 - undefined */ 2 | ((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 { 2 | const WIN = global.window; 3 | const DOC = WIN.document; 4 | const DOC_EL = DOC.documentElement; 5 | const BODY = DOC.querySelector('body'); 6 | const CTX = canvas.getContext('2d'); 7 | 8 | const black = pc => `rgba(0,0,0,${pc / 100})`; 9 | const settings = Object.assign({ 10 | viewport: null, 11 | styles: { 12 | 'header,footer,section,article': black(8), 13 | 'h1,a': black(10), 14 | 'h2,h3,h4': black(8) 15 | }, 16 | back: black(2), 17 | view: black(5), 18 | drag: black(10), 19 | interval: null 20 | }, options); 21 | 22 | const _listener = (el, method, types, fn) => types.split(/\s+/).forEach(type => el[method](type, fn)); 23 | const on = (el, types, fn) => _listener(el, 'addEventListener', types, fn); 24 | const off = (el, types, fn) => _listener(el, 'removeEventListener', types, fn); 25 | 26 | const Rect = (x, y, w, h) => { return {x, y, w, h}; }; 27 | 28 | const rect_rel_to = (rect, pos = {x: 0, y: 0}) => { 29 | return Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h); 30 | }; 31 | 32 | const rect_of_doc = () => { 33 | return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight); 34 | }; 35 | 36 | const rect_of_win = () => { 37 | return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight); 38 | }; 39 | 40 | const el_get_offset = el => { 41 | const br = el.getBoundingClientRect(); 42 | return {x: br.left + WIN.pageXOffset, y: br.top + WIN.pageYOffset}; 43 | }; 44 | 45 | const rect_of_el = el => { 46 | const {x, y} = el_get_offset(el); 47 | return Rect(x, y, el.offsetWidth, el.offsetHeight); 48 | }; 49 | 50 | const rect_of_viewport = el => { 51 | const {x, y} = el_get_offset(el); 52 | return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight); 53 | }; 54 | 55 | const rect_of_content = el => { 56 | const {x, y} = el_get_offset(el); 57 | return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight); 58 | }; 59 | 60 | const calc_scale = (() => { 61 | const width = canvas.clientWidth; 62 | const height = canvas.clientHeight; 63 | return (w, h) => Math.min(width / w, height / h); 64 | })(); 65 | 66 | const resize_canvas = (w, h) => { 67 | canvas.width = w; 68 | canvas.height = h; 69 | canvas.style.width = `${w}px`; 70 | canvas.style.height = `${h}px`; 71 | }; 72 | 73 | const viewport = settings.viewport; 74 | const find = sel => Array.from((viewport || DOC).querySelectorAll(sel)); 75 | 76 | let drag = false; 77 | 78 | let root_rect; 79 | let view_rect; 80 | let scale; 81 | let drag_rx; 82 | let drag_ry; 83 | 84 | const draw_rect = (rect, col) => { 85 | if (col) { 86 | CTX.beginPath(); 87 | CTX.rect(rect.x, rect.y, rect.w, rect.h); 88 | CTX.fillStyle = col; 89 | CTX.fill(); 90 | } 91 | }; 92 | 93 | const apply_styles = styles => { 94 | Object.keys(styles).forEach(sel => { 95 | const col = styles[sel]; 96 | find(sel).forEach(el => { 97 | draw_rect(rect_rel_to(rect_of_el(el), root_rect), col); 98 | }); 99 | }); 100 | }; 101 | 102 | const draw = () => { 103 | root_rect = viewport ? rect_of_content(viewport) : rect_of_doc(); 104 | view_rect = viewport ? rect_of_viewport(viewport) : rect_of_win(); 105 | scale = calc_scale(root_rect.w, root_rect.h); 106 | 107 | resize_canvas(root_rect.w * scale, root_rect.h * scale); 108 | 109 | CTX.setTransform(1, 0, 0, 1, 0, 0); 110 | CTX.clearRect(0, 0, canvas.width, canvas.height); 111 | CTX.scale(scale, scale); 112 | 113 | draw_rect(rect_rel_to(root_rect, root_rect), settings.back); 114 | apply_styles(settings.styles); 115 | draw_rect(rect_rel_to(view_rect, root_rect), drag ? settings.drag : settings.view); 116 | }; 117 | 118 | const on_drag = ev => { 119 | ev.preventDefault(); 120 | const cr = rect_of_viewport(canvas); 121 | const x = (ev.pageX - cr.x) / scale - view_rect.w * drag_rx; 122 | const y = (ev.pageY - cr.y) / scale - view_rect.h * drag_ry; 123 | 124 | if (viewport) { 125 | viewport.scrollLeft = x; 126 | viewport.scrollTop = y; 127 | } else { 128 | WIN.scrollTo(x, y); 129 | } 130 | draw(); 131 | }; 132 | 133 | const on_drag_end = ev => { 134 | drag = false; 135 | canvas.style.cursor = 'pointer'; 136 | BODY.style.cursor = 'auto'; 137 | off(WIN, 'mousemove', on_drag); 138 | off(WIN, 'mouseup', on_drag_end); 139 | on_drag(ev); 140 | }; 141 | 142 | const on_drag_start = ev => { 143 | drag = true; 144 | 145 | const cr = rect_of_viewport(canvas); 146 | const vr = rect_rel_to(view_rect, root_rect); 147 | drag_rx = ((ev.pageX - cr.x) / scale - vr.x) / vr.w; 148 | drag_ry = ((ev.pageY - cr.y) / scale - vr.y) / vr.h; 149 | if (drag_rx < 0 || drag_rx > 1 || drag_ry < 0 || drag_ry > 1) { 150 | drag_rx = 0.5; 151 | drag_ry = 0.5; 152 | } 153 | 154 | canvas.style.cursor = 'crosshair'; 155 | BODY.style.cursor = 'crosshair'; 156 | on(WIN, 'mousemove', on_drag); 157 | on(WIN, 'mouseup', on_drag_end); 158 | on_drag(ev); 159 | }; 160 | 161 | const init = () => { 162 | canvas.style.cursor = 'pointer'; 163 | on(canvas, 'mousedown', on_drag_start); 164 | on(viewport || WIN, 'load resize scroll', draw); 165 | if (settings.interval > 0) { 166 | setInterval(() => draw(), settings.interval); 167 | } 168 | draw(); 169 | }; 170 | 171 | init(); 172 | 173 | return { 174 | redraw: draw 175 | }; 176 | }; 177 | -------------------------------------------------------------------------------- /eslint.config.cjs: -------------------------------------------------------------------------------- 1 | const globals = require("globals"); 2 | 3 | module.exports = [{ 4 | ignores: ["eslint.config.*", "build/", "coverage/", "dist/", "es5/", "local/", "node_modules/"], 5 | }, { 6 | languageOptions: { 7 | globals: { 8 | ...globals.node, 9 | }, 10 | 11 | ecmaVersion: 2019, 12 | sourceType: "commonjs", 13 | }, 14 | 15 | rules: { 16 | "array-bracket-spacing": [2, "never"], 17 | "arrow-parens": [2, "as-needed"], 18 | "arrow-spacing": 2, 19 | "block-scoped-var": 2, 20 | 21 | "brace-style": [2, "1tbs", { 22 | allowSingleLine: true, 23 | }], 24 | 25 | camelcase: 0, 26 | "comma-dangle": [2, "never"], 27 | 28 | "comma-spacing": [2, { 29 | before: false, 30 | after: true, 31 | }], 32 | 33 | "comma-style": [2, "last"], 34 | complexity: [1, 16], 35 | "computed-property-spacing": [2, "never"], 36 | "consistent-return": 2, 37 | "consistent-this": [2, "self"], 38 | "constructor-super": 2, 39 | curly: [2, "multi-line"], 40 | "default-case": 2, 41 | "dot-location": [2, "property"], 42 | 43 | "dot-notation": [2, { 44 | allowKeywords: true, 45 | }], 46 | 47 | "eol-last": 2, 48 | eqeqeq: 2, 49 | "func-names": 2, 50 | 51 | "func-style": [2, "declaration", { 52 | allowArrowFunctions: true, 53 | }], 54 | 55 | "generator-star-spacing": [2, "after"], 56 | "guard-for-in": 2, 57 | "handle-callback-err": 2, 58 | indent: [2, 4], 59 | 60 | "key-spacing": [2, { 61 | beforeColon: false, 62 | afterColon: true, 63 | }], 64 | 65 | "keyword-spacing": [2, { 66 | before: true, 67 | after: true, 68 | }], 69 | 70 | "linebreak-style": [2, "unix"], 71 | "max-depth": [1, 4], 72 | "max-len": [0, 80, 4], 73 | "max-nested-callbacks": [1, 3], 74 | "max-params": [1, 5], 75 | "max-statements": [1, 48], 76 | "new-cap": 0, 77 | "new-parens": 2, 78 | "newline-after-var": 0, 79 | "no-alert": 2, 80 | "no-array-constructor": 2, 81 | "no-bitwise": 2, 82 | "no-caller": 2, 83 | "no-catch-shadow": 2, 84 | "no-class-assign": 2, 85 | "no-cond-assign": 2, 86 | "no-console": 0, 87 | "no-const-assign": 2, 88 | "no-constant-condition": 1, 89 | "no-continue": 0, 90 | "no-control-regex": 2, 91 | "no-debugger": 2, 92 | "no-delete-var": 2, 93 | "no-div-regex": 2, 94 | "no-dupe-args": 2, 95 | "no-dupe-class-members": 2, 96 | "no-dupe-keys": 2, 97 | "no-duplicate-case": 2, 98 | "no-else-return": 1, 99 | "no-empty": 2, 100 | "no-empty-character-class": 2, 101 | "no-empty-pattern": 2, 102 | "no-eq-null": 2, 103 | "no-eval": 2, 104 | "no-ex-assign": 2, 105 | "no-extend-native": 1, 106 | "no-extra-bind": 2, 107 | "no-extra-boolean-cast": 2, 108 | "no-extra-parens": 1, 109 | "no-extra-semi": 2, 110 | "no-fallthrough": 2, 111 | "no-floating-decimal": 2, 112 | "no-func-assign": 2, 113 | 114 | "no-implicit-coercion": [2, { 115 | boolean: false, 116 | number: true, 117 | string: true, 118 | }], 119 | 120 | "no-implied-eval": 2, 121 | "no-inline-comments": 0, 122 | "no-inner-declarations": [2, "functions"], 123 | "no-invalid-regexp": 2, 124 | "no-invalid-this": 2, 125 | "no-irregular-whitespace": 2, 126 | "no-iterator": 2, 127 | "no-label-var": 2, 128 | "no-labels": 2, 129 | "no-lone-blocks": 2, 130 | "no-lonely-if": 2, 131 | "no-loop-func": 1, 132 | "no-magic-numbers": 0, 133 | "no-mixed-requires": [2, false], 134 | "no-mixed-spaces-and-tabs": [2, false], 135 | "no-multi-spaces": 2, 136 | "no-multi-str": 2, 137 | 138 | "no-multiple-empty-lines": [2, { 139 | max: 4, 140 | }], 141 | 142 | "no-native-reassign": 1, 143 | "no-negated-in-lhs": 2, 144 | "no-nested-ternary": 0, 145 | "no-new": 2, 146 | "no-new-func": 2, 147 | "no-new-object": 2, 148 | "no-new-require": 2, 149 | "no-new-wrappers": 2, 150 | "no-obj-calls": 2, 151 | "no-octal": 2, 152 | "no-octal-escape": 2, 153 | "no-param-reassign": 0, 154 | "no-path-concat": 2, 155 | "no-plusplus": 2, 156 | "no-process-env": 2, 157 | "no-process-exit": 2, 158 | "no-proto": 2, 159 | "no-redeclare": 2, 160 | "no-regex-spaces": 2, 161 | "no-restricted-modules": 2, 162 | "no-return-assign": 2, 163 | "no-script-url": 2, 164 | "no-self-compare": 2, 165 | "no-sequences": 2, 166 | "no-shadow": 2, 167 | "no-shadow-restricted-names": 2, 168 | "no-spaced-func": 2, 169 | "no-sparse-arrays": 2, 170 | "no-sync": 0, 171 | "no-ternary": 0, 172 | "no-this-before-super": 2, 173 | "no-throw-literal": 1, 174 | "no-trailing-spaces": 2, 175 | "no-undef": 2, 176 | "no-undef-init": 2, 177 | "no-undefined": 0, 178 | "no-underscore-dangle": 0, 179 | "no-unexpected-multiline": 2, 180 | "no-unneeded-ternary": 2, 181 | "no-unreachable": 2, 182 | "no-useless-call": 2, 183 | "no-useless-concat": 2, 184 | "no-unused-expressions": 2, 185 | 186 | "no-unused-vars": [1, { 187 | vars: "all", 188 | args: "after-used", 189 | }], 190 | 191 | "no-use-before-define": 2, 192 | "no-var": 2, 193 | "no-void": 2, 194 | 195 | "no-warning-comments": [1, { 196 | terms: ["todo", "fixme", "xxx"], 197 | location: "start", 198 | }], 199 | 200 | "no-with": 2, 201 | "object-curly-spacing": [2, "never"], 202 | "object-shorthand": [2, "always"], 203 | "one-var": [2, "never"], 204 | "operator-assignment": [2, "always"], 205 | "operator-linebreak": [2, "after"], 206 | "padded-blocks": [2, "never"], 207 | "prefer-arrow-callback": 2, 208 | "prefer-const": 1, 209 | "prefer-reflect": 1, 210 | "prefer-spread": 2, 211 | "prefer-template": 0, 212 | "quote-props": [2, "as-needed"], 213 | quotes: [2, "single", "avoid-escape"], 214 | radix: 2, 215 | "require-yield": 2, 216 | semi: 2, 217 | 218 | "semi-spacing": [2, { 219 | before: false, 220 | after: true, 221 | }], 222 | 223 | "sort-vars": 0, 224 | "space-before-blocks": [2, "always"], 225 | 226 | "space-before-function-paren": [2, { 227 | anonymous: "always", 228 | named: "never", 229 | }], 230 | 231 | "space-in-parens": [2, "never"], 232 | "space-infix-ops": 2, 233 | 234 | "space-unary-ops": [2, { 235 | words: true, 236 | nonwords: false, 237 | }], 238 | 239 | "spaced-comment": [2, "always"], 240 | strict: [2, "never"], 241 | "use-isnan": 2, 242 | // "valid-jsdoc": 2, 243 | "valid-typeof": 2, 244 | "vars-on-top": 0, 245 | "wrap-iife": [2, "outside"], 246 | "wrap-regex": 2, 247 | 248 | yoda: [2, "never", { 249 | exceptRange: true, 250 | }], 251 | }, 252 | }]; 253 | -------------------------------------------------------------------------------- /dist/pagemap.js: -------------------------------------------------------------------------------- 1 | /*! pagemap v1.4.1 - undefined */ 2 | (function webpackUniversalModuleDefinition(root, factory) { 3 | if(typeof exports === 'object' && typeof module === 'object') 4 | module.exports = factory(); 5 | else if(typeof define === 'function' && define.amd) 6 | define("pagemap", [], factory); 7 | else if(typeof exports === 'object') 8 | exports["pagemap"] = factory(); 9 | else 10 | root["pagemap"] = factory(); 11 | })((typeof self !== 'undefined' ? self : this), () => { 12 | return /******/ (() => { // webpackBootstrap 13 | /******/ var __webpack_modules__ = ([ 14 | /* 0 */ 15 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 16 | 17 | module.exports = function (canvas, options) { 18 | var WIN = __webpack_require__.g.window; 19 | var DOC = WIN.document; 20 | var DOC_EL = DOC.documentElement; 21 | var BODY = DOC.querySelector('body'); 22 | var CTX = canvas.getContext('2d'); 23 | var black = function black(pc) { 24 | return "rgba(0,0,0,".concat(pc / 100, ")"); 25 | }; 26 | var settings = Object.assign({ 27 | viewport: null, 28 | styles: { 29 | 'header,footer,section,article': black(8), 30 | 'h1,a': black(10), 31 | 'h2,h3,h4': black(8) 32 | }, 33 | back: black(2), 34 | view: black(5), 35 | drag: black(10), 36 | interval: null 37 | }, options); 38 | var _listener = function _listener(el, method, types, fn) { 39 | return types.split(/\s+/).forEach(function (type) { 40 | return el[method](type, fn); 41 | }); 42 | }; 43 | var on = function on(el, types, fn) { 44 | return _listener(el, 'addEventListener', types, fn); 45 | }; 46 | var off = function off(el, types, fn) { 47 | return _listener(el, 'removeEventListener', types, fn); 48 | }; 49 | var Rect = function Rect(x, y, w, h) { 50 | return { 51 | x: x, 52 | y: y, 53 | w: w, 54 | h: h 55 | }; 56 | }; 57 | var rect_rel_to = function rect_rel_to(rect) { 58 | var pos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 59 | x: 0, 60 | y: 0 61 | }; 62 | return Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h); 63 | }; 64 | var rect_of_doc = function rect_of_doc() { 65 | return Rect(0, 0, DOC_EL.scrollWidth, DOC_EL.scrollHeight); 66 | }; 67 | var rect_of_win = function rect_of_win() { 68 | return Rect(WIN.pageXOffset, WIN.pageYOffset, DOC_EL.clientWidth, DOC_EL.clientHeight); 69 | }; 70 | var el_get_offset = function el_get_offset(el) { 71 | var br = el.getBoundingClientRect(); 72 | return { 73 | x: br.left + WIN.pageXOffset, 74 | y: br.top + WIN.pageYOffset 75 | }; 76 | }; 77 | var rect_of_el = function rect_of_el(el) { 78 | var _el_get_offset = el_get_offset(el), 79 | x = _el_get_offset.x, 80 | y = _el_get_offset.y; 81 | return Rect(x, y, el.offsetWidth, el.offsetHeight); 82 | }; 83 | var rect_of_viewport = function rect_of_viewport(el) { 84 | var _el_get_offset2 = el_get_offset(el), 85 | x = _el_get_offset2.x, 86 | y = _el_get_offset2.y; 87 | return Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight); 88 | }; 89 | var rect_of_content = function rect_of_content(el) { 90 | var _el_get_offset3 = el_get_offset(el), 91 | x = _el_get_offset3.x, 92 | y = _el_get_offset3.y; 93 | return Rect(x + el.clientLeft - el.scrollLeft, y + el.clientTop - el.scrollTop, el.scrollWidth, el.scrollHeight); 94 | }; 95 | var calc_scale = function () { 96 | var width = canvas.clientWidth; 97 | var height = canvas.clientHeight; 98 | return function (w, h) { 99 | return Math.min(width / w, height / h); 100 | }; 101 | }(); 102 | var resize_canvas = function resize_canvas(w, h) { 103 | canvas.width = w; 104 | canvas.height = h; 105 | canvas.style.width = "".concat(w, "px"); 106 | canvas.style.height = "".concat(h, "px"); 107 | }; 108 | var viewport = settings.viewport; 109 | var find = function find(sel) { 110 | return Array.from((viewport || DOC).querySelectorAll(sel)); 111 | }; 112 | var drag = false; 113 | var root_rect; 114 | var view_rect; 115 | var scale; 116 | var drag_rx; 117 | var drag_ry; 118 | var draw_rect = function draw_rect(rect, col) { 119 | if (col) { 120 | CTX.beginPath(); 121 | CTX.rect(rect.x, rect.y, rect.w, rect.h); 122 | CTX.fillStyle = col; 123 | CTX.fill(); 124 | } 125 | }; 126 | var apply_styles = function apply_styles(styles) { 127 | Object.keys(styles).forEach(function (sel) { 128 | var col = styles[sel]; 129 | find(sel).forEach(function (el) { 130 | draw_rect(rect_rel_to(rect_of_el(el), root_rect), col); 131 | }); 132 | }); 133 | }; 134 | var draw = function draw() { 135 | root_rect = viewport ? rect_of_content(viewport) : rect_of_doc(); 136 | view_rect = viewport ? rect_of_viewport(viewport) : rect_of_win(); 137 | scale = calc_scale(root_rect.w, root_rect.h); 138 | resize_canvas(root_rect.w * scale, root_rect.h * scale); 139 | CTX.setTransform(1, 0, 0, 1, 0, 0); 140 | CTX.clearRect(0, 0, canvas.width, canvas.height); 141 | CTX.scale(scale, scale); 142 | draw_rect(rect_rel_to(root_rect, root_rect), settings.back); 143 | apply_styles(settings.styles); 144 | draw_rect(rect_rel_to(view_rect, root_rect), drag ? settings.drag : settings.view); 145 | }; 146 | var on_drag = function on_drag(ev) { 147 | ev.preventDefault(); 148 | var cr = rect_of_viewport(canvas); 149 | var x = (ev.pageX - cr.x) / scale - view_rect.w * drag_rx; 150 | var y = (ev.pageY - cr.y) / scale - view_rect.h * drag_ry; 151 | if (viewport) { 152 | viewport.scrollLeft = x; 153 | viewport.scrollTop = y; 154 | } else { 155 | WIN.scrollTo(x, y); 156 | } 157 | draw(); 158 | }; 159 | var _on_drag_end = function on_drag_end(ev) { 160 | drag = false; 161 | canvas.style.cursor = 'pointer'; 162 | BODY.style.cursor = 'auto'; 163 | off(WIN, 'mousemove', on_drag); 164 | off(WIN, 'mouseup', _on_drag_end); 165 | on_drag(ev); 166 | }; 167 | var on_drag_start = function on_drag_start(ev) { 168 | drag = true; 169 | var cr = rect_of_viewport(canvas); 170 | var vr = rect_rel_to(view_rect, root_rect); 171 | drag_rx = ((ev.pageX - cr.x) / scale - vr.x) / vr.w; 172 | drag_ry = ((ev.pageY - cr.y) / scale - vr.y) / vr.h; 173 | if (drag_rx < 0 || drag_rx > 1 || drag_ry < 0 || drag_ry > 1) { 174 | drag_rx = 0.5; 175 | drag_ry = 0.5; 176 | } 177 | canvas.style.cursor = 'crosshair'; 178 | BODY.style.cursor = 'crosshair'; 179 | on(WIN, 'mousemove', on_drag); 180 | on(WIN, 'mouseup', _on_drag_end); 181 | on_drag(ev); 182 | }; 183 | var init = function init() { 184 | canvas.style.cursor = 'pointer'; 185 | on(canvas, 'mousedown', on_drag_start); 186 | on(viewport || WIN, 'load resize scroll', draw); 187 | if (settings.interval > 0) { 188 | setInterval(function () { 189 | return draw(); 190 | }, settings.interval); 191 | } 192 | draw(); 193 | }; 194 | init(); 195 | return { 196 | redraw: draw 197 | }; 198 | }; 199 | 200 | /***/ }) 201 | /******/ ]); 202 | /************************************************************************/ 203 | /******/ // The module cache 204 | /******/ var __webpack_module_cache__ = {}; 205 | /******/ 206 | /******/ // The require function 207 | /******/ function __webpack_require__(moduleId) { 208 | /******/ // Check if module is in cache 209 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 210 | /******/ if (cachedModule !== undefined) { 211 | /******/ return cachedModule.exports; 212 | /******/ } 213 | /******/ // Create a new module (and put it into the cache) 214 | /******/ var module = __webpack_module_cache__[moduleId] = { 215 | /******/ // no module.id needed 216 | /******/ // no module.loaded needed 217 | /******/ exports: {} 218 | /******/ }; 219 | /******/ 220 | /******/ // Execute the module function 221 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 222 | /******/ 223 | /******/ // Return the exports of the module 224 | /******/ return module.exports; 225 | /******/ } 226 | /******/ 227 | /************************************************************************/ 228 | /******/ /* webpack/runtime/global */ 229 | /******/ (() => { 230 | /******/ __webpack_require__.g = (function() { 231 | /******/ if (typeof globalThis === 'object') return globalThis; 232 | /******/ try { 233 | /******/ return this || new Function('return this')(); 234 | /******/ } catch (e) { 235 | /******/ if (typeof window === 'object') return window; 236 | /******/ } 237 | /******/ })(); 238 | /******/ })(); 239 | /******/ 240 | /************************************************************************/ 241 | /******/ 242 | /******/ // startup 243 | /******/ // Load entry module and return exports 244 | /******/ // This entry module is referenced by other modules so it can't be inlined 245 | /******/ var __webpack_exports__ = __webpack_require__(0); 246 | /******/ 247 | /******/ return __webpack_exports__; 248 | /******/ })() 249 | ; 250 | }); -------------------------------------------------------------------------------- /src/demo/text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | pagemap demo - text 6 | 7 | 8 | 9 | 13 | 14 |
15 |
16 |

At Eos Accusamu

17 |
18 |
19 |

Et harum quidem rerum

20 | 21 |

Nemo enim ipsam voluptatem

22 |

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis 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. 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, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

23 | 24 |

Nemo enim ipsam voluptatem

25 |

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, eaque ipsa quae ab illo inventore veritatis 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. 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, eaque ipsa quae ab illo inventore veritatis 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.

26 | 27 |

Nemo enim ipsam voluptatem

28 |

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.

29 |
30 | 31 |
32 |

Et harum quidem rerum

33 | 34 |

Nemo enim ipsam voluptatem

35 |

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis 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. 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.

36 | 37 |

Nemo enim ipsam voluptatem

38 |

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, eaque ipsa quae ab illo inventore veritatis 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. 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.

39 | 40 |

Nemo enim ipsam voluptatem

41 |

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, eaque veritatis 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.

42 |
43 |
44 | 45 | 46 | 47 | 48 | 51 | 52 | 53 | --------------------------------------------------------------------------------